From 78fc41966f49e8c13bc2404eef192426443348bb Mon Sep 17 00:00:00 2001 From: bo-ram-bo-ram Date: Fri, 12 Jul 2024 15:42:33 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix=20:=20=EB=B6=88=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=B0=8F=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/api/notice/controller/.gitkeep | 0 .../server/api/notice/domain/Notice.java | 28 +++++++++---------- .../pickple/server/api/notice/dto/.gitkeep | 0 .../server/api/notice/repository/.gitkeep | 0 .../server/api/notice/service/.gitkeep | 0 .../global/response/enums/SuccessCode.java | 1 + 6 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 src/main/java/com/pickple/server/api/notice/controller/.gitkeep delete mode 100644 src/main/java/com/pickple/server/api/notice/dto/.gitkeep delete mode 100644 src/main/java/com/pickple/server/api/notice/repository/.gitkeep delete mode 100644 src/main/java/com/pickple/server/api/notice/service/.gitkeep diff --git a/src/main/java/com/pickple/server/api/notice/controller/.gitkeep b/src/main/java/com/pickple/server/api/notice/controller/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/java/com/pickple/server/api/notice/domain/Notice.java b/src/main/java/com/pickple/server/api/notice/domain/Notice.java index 527a1c11..e4fdf441 100644 --- a/src/main/java/com/pickple/server/api/notice/domain/Notice.java +++ b/src/main/java/com/pickple/server/api/notice/domain/Notice.java @@ -1,8 +1,19 @@ package com.pickple.server.api.notice.domain; import com.pickple.server.api.moim.domain.Moim; -import jakarta.persistence.*; -import lombok.*; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity @Getter @@ -25,17 +36,4 @@ public class Notice { private String content; private String imageUrl; - - - @Builder - public Notice(final Moim moim, - final String title, - final String content, - final String imageUrl - ){ - this.moim = moim; - this.title = title; - this.content = content; - this.imageUrl = imageUrl; - } } diff --git a/src/main/java/com/pickple/server/api/notice/dto/.gitkeep b/src/main/java/com/pickple/server/api/notice/dto/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/java/com/pickple/server/api/notice/repository/.gitkeep b/src/main/java/com/pickple/server/api/notice/repository/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/java/com/pickple/server/api/notice/service/.gitkeep b/src/main/java/com/pickple/server/api/notice/service/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java b/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java index 5251b585..c53fb4c0 100644 --- a/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java +++ b/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java @@ -20,6 +20,7 @@ public enum SuccessCode { MOIM_SUBMISSION_POST_SUCCESS(20007, HttpStatus.OK, "모임 참여 신청 성공"), PRESIGNED_URL_GET_SUCCESS(20008, HttpStatus.OK, "presigned url 발급 성공"), SUBMITTED_MOIM_DETAIL_GET_SUCCESS(20008, HttpStatus.OK, "신청한 모임 상세 정보 조회 성공"), + HOST_POST_SUCCESS(20009, HttpStatus.OK, "공지사항 작성 성공"), //201 Created MOIM_CREATE_SUCCESS(20100, HttpStatus.CREATED, "모임 개설 성공"); From e810246edd88775d3defabf16739c1f6b5a5b017 Mon Sep 17 00:00:00 2001 From: bo-ram-bo-ram Date: Fri, 12 Jul 2024 15:43:35 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat=20:=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=9E=91=EC=84=B1=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/controller/NoticeController.java | 27 ++++++++++++++++ .../notice/dto/request/NoticePostRequest.java | 18 +++++++++++ .../notice/repository/NoticeRepository.java | 7 ++++ .../notice/service/NoticeCommandService.java | 32 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/main/java/com/pickple/server/api/notice/controller/NoticeController.java create mode 100644 src/main/java/com/pickple/server/api/notice/dto/request/NoticePostRequest.java create mode 100644 src/main/java/com/pickple/server/api/notice/repository/NoticeRepository.java create mode 100644 src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java diff --git a/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java b/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java new file mode 100644 index 00000000..00483515 --- /dev/null +++ b/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java @@ -0,0 +1,27 @@ +package com.pickple.server.api.notice.controller; + +import com.pickple.server.api.notice.dto.request.NoticePostRequest; +import com.pickple.server.api.notice.service.NoticeCommandService; +import com.pickple.server.global.response.ApiResponseDto; +import com.pickple.server.global.response.enums.SuccessCode; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class NoticeController { + + private final NoticeCommandService noticeCommandService; + + @PostMapping("/v1/moim/{moimId}/notice") + public ApiResponseDto getHost(@PathVariable Long moimId, + @RequestBody NoticePostRequest noticePostRequest) { + noticeCommandService.postNotice(moimId, noticePostRequest); + return ApiResponseDto.success(SuccessCode.HOST_POST_SUCCESS); + } +} diff --git a/src/main/java/com/pickple/server/api/notice/dto/request/NoticePostRequest.java b/src/main/java/com/pickple/server/api/notice/dto/request/NoticePostRequest.java new file mode 100644 index 00000000..c9c95005 --- /dev/null +++ b/src/main/java/com/pickple/server/api/notice/dto/request/NoticePostRequest.java @@ -0,0 +1,18 @@ +package com.pickple.server.api.notice.dto.request; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +public record NoticePostRequest( + @Size(max = 25, message = "제목은 최대 25자 이내로 작성해주세요.") + @NotBlank(message = "제목 비어 있습니다.") + String noticeTitle,//공지사항 제목 + + @Size(max = 500, message = "내용은 최대 500자 이내로 작성해주세요.") + @NotBlank(message = "내용이 비어 있습니다.") + String noticeContent, //공지사항 내용 + + String imageUrl //공지사항 이미지 +) { + +} diff --git a/src/main/java/com/pickple/server/api/notice/repository/NoticeRepository.java b/src/main/java/com/pickple/server/api/notice/repository/NoticeRepository.java new file mode 100644 index 00000000..474b5251 --- /dev/null +++ b/src/main/java/com/pickple/server/api/notice/repository/NoticeRepository.java @@ -0,0 +1,7 @@ +package com.pickple.server.api.notice.repository; + +import com.pickple.server.api.notice.domain.Notice; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NoticeRepository extends JpaRepository { +} diff --git a/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java b/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java new file mode 100644 index 00000000..7d85a3d5 --- /dev/null +++ b/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java @@ -0,0 +1,32 @@ +package com.pickple.server.api.notice.service; + +import com.pickple.server.api.moim.domain.Moim; +import com.pickple.server.api.moim.repository.MoimRepository; +import com.pickple.server.api.notice.domain.Notice; +import com.pickple.server.api.notice.dto.request.NoticePostRequest; +import com.pickple.server.api.notice.repository.NoticeRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class NoticeCommandService { + + private final MoimRepository moimRepository; + private final NoticeRepository noticeRepository; + + public void postNotice(Long moimId, NoticePostRequest request) { + Moim moim = moimRepository.findMoimByIdOrThrow(moimId); + + Notice notice = Notice.builder() + .title(request.noticeTitle()) + .content(request.noticeContent()) + .imageUrl(request.imageUrl()) + .moim(moim) + .build(); + + noticeRepository.save(notice); + } +} From 62ef30b20268a7ffe0d9efc36cc95e051345442e Mon Sep 17 00:00:00 2001 From: bo-ram-bo-ram Date: Fri, 12 Jul 2024 15:58:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix=20:=20=EC=BD=94=EB=93=9C=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/api/notice/controller/NoticeController.java | 8 ++++---- .../{NoticePostRequest.java => NoticeCreateRequest.java} | 2 +- .../server/api/notice/service/NoticeCommandService.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename src/main/java/com/pickple/server/api/notice/dto/request/{NoticePostRequest.java => NoticeCreateRequest.java} (94%) diff --git a/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java b/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java index 00483515..89b83302 100644 --- a/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java +++ b/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java @@ -1,6 +1,6 @@ package com.pickple.server.api.notice.controller; -import com.pickple.server.api.notice.dto.request.NoticePostRequest; +import com.pickple.server.api.notice.dto.request.NoticeCreateRequest; import com.pickple.server.api.notice.service.NoticeCommandService; import com.pickple.server.global.response.ApiResponseDto; import com.pickple.server.global.response.enums.SuccessCode; @@ -19,9 +19,9 @@ public class NoticeController { private final NoticeCommandService noticeCommandService; @PostMapping("/v1/moim/{moimId}/notice") - public ApiResponseDto getHost(@PathVariable Long moimId, - @RequestBody NoticePostRequest noticePostRequest) { - noticeCommandService.postNotice(moimId, noticePostRequest); + public ApiResponseDto createNotice(@PathVariable Long moimId, + @RequestBody NoticeCreateRequest noticeCreateRequest) { + noticeCommandService.createNotice(moimId, noticeCreateRequest); return ApiResponseDto.success(SuccessCode.HOST_POST_SUCCESS); } } diff --git a/src/main/java/com/pickple/server/api/notice/dto/request/NoticePostRequest.java b/src/main/java/com/pickple/server/api/notice/dto/request/NoticeCreateRequest.java similarity index 94% rename from src/main/java/com/pickple/server/api/notice/dto/request/NoticePostRequest.java rename to src/main/java/com/pickple/server/api/notice/dto/request/NoticeCreateRequest.java index c9c95005..53dab306 100644 --- a/src/main/java/com/pickple/server/api/notice/dto/request/NoticePostRequest.java +++ b/src/main/java/com/pickple/server/api/notice/dto/request/NoticeCreateRequest.java @@ -3,7 +3,7 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; -public record NoticePostRequest( +public record NoticeCreateRequest( @Size(max = 25, message = "제목은 최대 25자 이내로 작성해주세요.") @NotBlank(message = "제목 비어 있습니다.") String noticeTitle,//공지사항 제목 diff --git a/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java b/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java index 7d85a3d5..60708015 100644 --- a/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java +++ b/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java @@ -3,7 +3,7 @@ import com.pickple.server.api.moim.domain.Moim; import com.pickple.server.api.moim.repository.MoimRepository; import com.pickple.server.api.notice.domain.Notice; -import com.pickple.server.api.notice.dto.request.NoticePostRequest; +import com.pickple.server.api.notice.dto.request.NoticeCreateRequest; import com.pickple.server.api.notice.repository.NoticeRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -17,7 +17,7 @@ public class NoticeCommandService { private final MoimRepository moimRepository; private final NoticeRepository noticeRepository; - public void postNotice(Long moimId, NoticePostRequest request) { + public void createNotice(Long moimId, NoticeCreateRequest request) { Moim moim = moimRepository.findMoimByIdOrThrow(moimId); Notice notice = Notice.builder()