diff --git a/src/main/java/com/gamzabat/algohub/feature/notice/domain/Notice.java b/src/main/java/com/gamzabat/algohub/feature/notice/domain/Notice.java index 7a357791..4456cc0a 100644 --- a/src/main/java/com/gamzabat/algohub/feature/notice/domain/Notice.java +++ b/src/main/java/com/gamzabat/algohub/feature/notice/domain/Notice.java @@ -31,6 +31,7 @@ public class Notice { private String title; @Column(columnDefinition = "TEXT") private String content; + private String category; private LocalDateTime createdAt; private LocalDateTime updatedAt; @@ -43,17 +44,20 @@ public class Notice { private StudyGroup studyGroup; @Builder - public Notice(User author, StudyGroup studyGroup, String title, String content, LocalDateTime createdAt) { + public Notice(User author, StudyGroup studyGroup, String title, String content, String category, + LocalDateTime createdAt) { this.author = author; this.title = title; this.studyGroup = studyGroup; this.content = content; + this.category = category; this.createdAt = createdAt; } - public void updateNotice(String title, String content) { + public void updateNotice(String title, String content, String category) { this.title = title; this.content = content; + this.category = category; this.updatedAt = LocalDateTime.now(); } diff --git a/src/main/java/com/gamzabat/algohub/feature/notice/dto/CreateNoticeRequest.java b/src/main/java/com/gamzabat/algohub/feature/notice/dto/CreateNoticeRequest.java index 14a8484d..1d3c5028 100644 --- a/src/main/java/com/gamzabat/algohub/feature/notice/dto/CreateNoticeRequest.java +++ b/src/main/java/com/gamzabat/algohub/feature/notice/dto/CreateNoticeRequest.java @@ -3,9 +3,10 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -public record CreateNoticeRequest(@NotNull(message = "그룹id 는 필수입니다") Long studyGroupId, +public record CreateNoticeRequest(@NotNull(message = "그룹 id 는 필수입니다") Long studyGroupId, @NotBlank(message = "제목은 필수 입력입니다") String title, - @NotBlank(message = "본문은 필수 입력입니다") String content + @NotBlank(message = "본문은 필수 입력입니다") String content, + @NotBlank(message = "카테고리는 필수 입력입니다") String category ) { } diff --git a/src/main/java/com/gamzabat/algohub/feature/notice/dto/GetNoticeResponse.java b/src/main/java/com/gamzabat/algohub/feature/notice/dto/GetNoticeResponse.java index 85b0606e..6eff899b 100644 --- a/src/main/java/com/gamzabat/algohub/feature/notice/dto/GetNoticeResponse.java +++ b/src/main/java/com/gamzabat/algohub/feature/notice/dto/GetNoticeResponse.java @@ -8,16 +8,18 @@ @Builder public record GetNoticeResponse(String author, Long noticeId, - String noticeContent, - String noticeTitle, + String content, + String title, + String category, String createAt) { public static GetNoticeResponse toDTO(Notice notice) { return GetNoticeResponse.builder() .author(notice.getAuthor().getNickname()) .noticeId(notice.getId()) - .noticeTitle(notice.getTitle()) - .noticeContent(notice.getContent()) + .title(notice.getTitle()) + .content(notice.getContent()) + .category(notice.getCategory()) .createAt(DateFormatUtil.formatDate(notice.getCreatedAt().toLocalDate())) .build(); diff --git a/src/main/java/com/gamzabat/algohub/feature/notice/dto/UpdateNoticeRequest.java b/src/main/java/com/gamzabat/algohub/feature/notice/dto/UpdateNoticeRequest.java index 0ad3a3d0..9c499e3d 100644 --- a/src/main/java/com/gamzabat/algohub/feature/notice/dto/UpdateNoticeRequest.java +++ b/src/main/java/com/gamzabat/algohub/feature/notice/dto/UpdateNoticeRequest.java @@ -5,5 +5,7 @@ public record UpdateNoticeRequest(@NotNull(message = "게시글 id는 필수 입니다.") Long noticeId, @NotBlank(message = "제목은 필수 입력입니다") String title, - @NotBlank(message = "본문은 필수 입력입니다") String content) { + @NotBlank(message = "본문은 필수 입력입니다") String content, + @NotBlank(message = "카테고리는 필수 입력입니다") String category +) { } diff --git a/src/main/java/com/gamzabat/algohub/feature/notice/service/NoticeService.java b/src/main/java/com/gamzabat/algohub/feature/notice/service/NoticeService.java index cf136ba9..784e15d3 100644 --- a/src/main/java/com/gamzabat/algohub/feature/notice/service/NoticeService.java +++ b/src/main/java/com/gamzabat/algohub/feature/notice/service/NoticeService.java @@ -55,6 +55,7 @@ public void createNotice(@AuthedUser User user, CreateNoticeRequest request) { .studyGroup(studyGroup) .title(request.title()) .content(request.content()) + .category(request.category()) .createdAt(LocalDateTime.now()) .build()); log.info("success to create notice"); @@ -71,8 +72,9 @@ public GetNoticeResponse getNotice(@AuthedUser User user, Long noticeId) { return GetNoticeResponse.builder() .author(notice.getAuthor().getNickname()) .noticeId(notice.getId()) - .noticeTitle(notice.getTitle()) - .noticeContent(notice.getContent()) + .title(notice.getTitle()) + .content(notice.getContent()) + .category(notice.getCategory()) .createAt(DateFormatUtil.formatDate(notice.getCreatedAt().toLocalDate())) .build(); } @@ -98,7 +100,7 @@ public void updateNotice(User user, UpdateNoticeRequest request) { if (!user.getId().equals(notice.getAuthor().getId())) throw new UserValidationException("공지를 수정할 수 있는 권한이 없습니다"); - notice.updateNotice(request.title(), request.content()); + notice.updateNotice(request.title(), request.content(), request.category()); } @Transactional diff --git a/src/test/java/com/gamzabat/algohub/service/NoticeServiceTest.java b/src/test/java/com/gamzabat/algohub/service/NoticeServiceTest.java index fdb2162d..a79eb091 100644 --- a/src/test/java/com/gamzabat/algohub/service/NoticeServiceTest.java +++ b/src/test/java/com/gamzabat/algohub/service/NoticeServiceTest.java @@ -78,6 +78,7 @@ void setUp() throws NoSuchFieldException, IllegalAccessException { .createdAt(LocalDateTime.now()) .title("title") .content("content") + .category("category") .author(user) .build(); @@ -107,7 +108,7 @@ void setUp() throws NoSuchFieldException, IllegalAccessException { @DisplayName("공지 작성 성공") void createNoticeSuccess_1() { //given - CreateNoticeRequest request = new CreateNoticeRequest(30L, "title", "content"); + CreateNoticeRequest request = new CreateNoticeRequest(30L, "title", "content", "category"); when(studyGroupRepository.findById(request.studyGroupId())).thenReturn(Optional.ofNullable(studyGroup)); when(groupMemberRepository.findByUserAndStudyGroup(user2, studyGroup)).thenReturn( Optional.ofNullable(groupMember2)); @@ -119,6 +120,7 @@ void createNoticeSuccess_1() { assertThat(result.getAuthor()).isEqualTo(user2); assertThat(result.getContent()).isEqualTo("content"); assertThat(result.getTitle()).isEqualTo("title"); + assertThat(result.getCategory()).isEqualTo("category"); assertThat(result.getStudyGroup()).isEqualTo(studyGroup); } @@ -127,7 +129,7 @@ void createNoticeSuccess_1() { @DisplayName("공지 작성 실패 그룹장or부방장이 아님") void createNoticeFail_1() { //given - CreateNoticeRequest request = new CreateNoticeRequest(30L, "title", "content"); + CreateNoticeRequest request = new CreateNoticeRequest(30L, "title", "content", "category"); when(studyGroupRepository.findById(request.studyGroupId())).thenReturn(Optional.ofNullable(studyGroup)); when(groupMemberRepository.findByUserAndStudyGroup(user3, studyGroup)).thenReturn( Optional.ofNullable(groupMember3)); @@ -142,7 +144,7 @@ void createNoticeFail_1() { @DisplayName("공지 작성 실패 존재하지 않는 그룹") void createNoticeFail_2() { //given - CreateNoticeRequest request = new CreateNoticeRequest(31L, "title", "content"); + CreateNoticeRequest request = new CreateNoticeRequest(31L, "title", "content", "category"); when(studyGroupRepository.findById(request.studyGroupId())).thenReturn(Optional.empty()); //when,then assertThatThrownBy(() -> noticeService.createNotice(user, request)) @@ -155,7 +157,7 @@ void createNoticeFail_2() { @DisplayName("공지 작성 실패 존재하지 않는 멤버") void createNoticeFail_3() { //given - CreateNoticeRequest request = new CreateNoticeRequest(30L, "title", "content"); + CreateNoticeRequest request = new CreateNoticeRequest(30L, "title", "content", "category"); when(studyGroupRepository.findById(request.studyGroupId())).thenReturn(Optional.ofNullable(studyGroup)); when(groupMemberRepository.findByUserAndStudyGroup(user4, studyGroup)).thenReturn(Optional.empty()); //when,then @@ -176,8 +178,9 @@ void getNoticeSuccess_1() { GetNoticeResponse response = noticeService.getNotice(user2, 1000L); //then assertThat(response.author()).isEqualTo("nickname1"); - assertThat(response.noticeContent()).isEqualTo("content"); - assertThat(response.noticeTitle()).isEqualTo("title"); + assertThat(response.content()).isEqualTo("content"); + assertThat(response.title()).isEqualTo("title"); + assertThat(response.category()).isEqualTo("category"); assertThat(response.createAt()).isEqualTo(DateFormatUtil.formatDate(LocalDateTime.now().toLocalDate())); assertThat(response.noticeId()).isEqualTo(1000L); } @@ -215,19 +218,21 @@ void getNoticeListSuccess_1() { List noticeList = new ArrayList<>(10); for (int i = 0; i < 10; i++) noticeList.add( - notice.builder() + Notice.builder() .author(user) .content("content" + i) .title("title" + i) + .category("category" + i) .createdAt(LocalDateTime.now()) .studyGroup(studyGroup) .build()); for (int i = 10; i < 20; i++) noticeList.add( - notice.builder() + Notice.builder() .author(user2) .content("content" + i) .title("title" + i) + .category("category" + i) .createdAt(LocalDateTime.now()) .studyGroup(studyGroup) .build()); @@ -239,8 +244,9 @@ void getNoticeListSuccess_1() { //then assertThat(result.size()).isEqualTo(20); for (int i = 0; i < 20; i++) { - assertThat(result.get(i).noticeContent()).isEqualTo("content" + i); - assertThat(result.get(i).noticeTitle()).isEqualTo("title" + i); + assertThat(result.get(i).content()).isEqualTo("content" + i); + assertThat(result.get(i).title()).isEqualTo("title" + i); + assertThat(result.get(i).category()).isEqualTo("category" + i); } } @@ -273,7 +279,8 @@ void getNoticeListFailed_2() { @DisplayName("공지 수정 성공") void updateNoticeSuccess() { //given - UpdateNoticeRequest updateNoticeRequest = new UpdateNoticeRequest(1000L, "updateTitle", "updateContent"); + UpdateNoticeRequest updateNoticeRequest = new UpdateNoticeRequest(1000L, "updateTitle", "updateContent", + "updateCategory"); when(noticeRepository.findById(1000L)).thenReturn(Optional.ofNullable(notice)); when(studyGroupRepository.findById(30L)).thenReturn(Optional.ofNullable(studyGroup)); //when @@ -281,13 +288,15 @@ void updateNoticeSuccess() { //then assertThat(notice.getContent()).isEqualTo("updateContent"); assertThat(notice.getTitle()).isEqualTo("updateTitle"); + assertThat(notice.getCategory()).isEqualTo("updateCategory"); } @Test @DisplayName("공지 수정 실패(존재하지 않는 게시글)") void updateNoticeFailed_1() { //given - UpdateNoticeRequest updateNoticeRequest = new UpdateNoticeRequest(1001L, "updateTitle", "updateContent"); + UpdateNoticeRequest updateNoticeRequest = new UpdateNoticeRequest(1001L, "updateTitle", "updateContent", + "updateCategory"); when(noticeRepository.findById(1001L)).thenReturn(Optional.empty()); //when,then assertThatThrownBy(() -> noticeService.updateNotice(user, updateNoticeRequest)) @@ -299,7 +308,8 @@ void updateNoticeFailed_1() { @DisplayName("공시 수정 실패(존재하지 않는 스터디 그룹)") void updateNoticeFailed_2() { //given - UpdateNoticeRequest updateNoticeRequest = new UpdateNoticeRequest(1000L, "updateTitle", "updateContent"); + UpdateNoticeRequest updateNoticeRequest = new UpdateNoticeRequest(1000L, "updateTitle", "updateContent", + "updateCategory"); when(noticeRepository.findById(1000L)).thenReturn(Optional.ofNullable(notice)); when(studyGroupRepository.findById(30L)).thenReturn(Optional.empty()); //when,then @@ -314,7 +324,8 @@ void updateNoticeFailed_2() { @DisplayName("공지 수정 실패(게시글 작성자가 아님)") void updateNoticeFailed_3() { //given - UpdateNoticeRequest updateNoticeRequest = new UpdateNoticeRequest(1000L, "updateTitle", "updateContent"); + UpdateNoticeRequest updateNoticeRequest = new UpdateNoticeRequest(1000L, "updateTitle", "updateContent", + "updateCategory"); when(noticeRepository.findById(1000L)).thenReturn(Optional.ofNullable(notice)); when(studyGroupRepository.findById(30L)).thenReturn(Optional.ofNullable(studyGroup)); //when, then