diff --git a/back/src/main/java/com/back/domain/post/post/controller/PostController.java b/back/src/main/java/com/back/domain/post/post/controller/PostController.java index 0ccb2e57..b1d27ddf 100644 --- a/back/src/main/java/com/back/domain/post/post/controller/PostController.java +++ b/back/src/main/java/com/back/domain/post/post/controller/PostController.java @@ -40,7 +40,7 @@ public RsData getPostWithPage( return new RsData<>("200", "게시글이 조회 되었습니다.", resDto); } - @Operation(summary = "게시글 생성") + @Operation(summary = "게시글 생성 ") @PostMapping public RsData createPost( @Valid @RequestBody PostCreateRequest postCreateRequest @@ -93,28 +93,13 @@ public RsData updatePost(@PathVariable Long post_id @Operation(summary = "게시글 좋아요") @PostMapping("/{post_id}/liked") - public RsData likePost(@PathVariable Long post_id) { + public RsData likePost(@PathVariable Long post_id) { postLikeService.likePost(post_id); - return new RsData<>("200", "게시글 좋아요 성공", null); - } - - @Operation(summary = "게시글 좋아요 (Show)") - @GetMapping("/{post_id}/liked") - public RsData getLike(@PathVariable Long post_id) { int likeCount = postLikeService.getLikeCount(post_id); PostLikedResponse postLikedResponse = new PostLikedResponse(likeCount); - return new RsData<>("200", "게시글 좋아요 조회 성공", postLikedResponse); - } - - @Operation(summary = "게시글 싫어요 (Show)") - @GetMapping("/{post_id}/disliked") - public RsData getDisLike(@PathVariable Long post_id) { - int likeCount = postLikeService.getDisLikeCount(post_id); - PostLikedResponse postLikedResponse = new PostLikedResponse(likeCount); - - return new RsData<>("200", "게시글 싫어요 조회 성공", postLikedResponse); + return new RsData<>("200", "게시글 좋아요 성공", postLikedResponse); } @Operation(summary = "게시글 싫어요") @@ -122,12 +107,15 @@ public RsData getDisLike(@PathVariable Long post_id) { public RsData disLikePost(@PathVariable Long post_id) { postLikeService.disLikePost(post_id); - return new RsData<>("200", "게시글 싫어요 성공", null); + int likeCount = postLikeService.getDisLikeCount(post_id); + PostLikedResponse postLikedResponse = new PostLikedResponse(likeCount); + + return new RsData<>("200", "게시글 싫어요 성공", postLikedResponse); } @Operation(summary = "게시글 상세페이지") - @GetMapping("/Detail/{post_id}") + @GetMapping("/detail/{post_id}") public RsData getPostDetail(@PathVariable Long post_id) { PostDetailResponse response = postDetailFacade.getDetailWithViewIncrement(post_id); diff --git a/back/src/main/java/com/back/domain/post/post/dto/PostCreateRequest.java b/back/src/main/java/com/back/domain/post/post/dto/PostCreateRequest.java index add523db..5224d2a8 100644 --- a/back/src/main/java/com/back/domain/post/post/dto/PostCreateRequest.java +++ b/back/src/main/java/com/back/domain/post/post/dto/PostCreateRequest.java @@ -8,8 +8,9 @@ public record PostCreateRequest( String postType, @NotBlank(message = "제목은 null 혹은 공백일 수 없습니다.") String title, - @NotBlank(message = "제목은 null 혹은 공백일 수 없습니다.") - String content + @NotBlank(message = "내용은 null 혹은 공백일 수 없습니다.") + String content, + String job ) { diff --git a/back/src/main/java/com/back/domain/post/post/dto/PostDto.java b/back/src/main/java/com/back/domain/post/post/dto/PostDto.java index 1a7cc565..c9d516fa 100644 --- a/back/src/main/java/com/back/domain/post/post/dto/PostDto.java +++ b/back/src/main/java/com/back/domain/post/post/dto/PostDto.java @@ -8,7 +8,8 @@ public record PostDto( Long postId, String title, - String content + String content, + int viewCount ) { @@ -16,7 +17,8 @@ public static PostDto from(Post post) { return new PostDto( post.getId(), post.getTitle(), - post.getContent() + post.getContent(), + post.getViewCount() ); } } diff --git a/back/src/main/java/com/back/domain/post/post/entity/Post.java b/back/src/main/java/com/back/domain/post/post/entity/Post.java index 81d1b3bd..0056ea51 100644 --- a/back/src/main/java/com/back/domain/post/post/entity/Post.java +++ b/back/src/main/java/com/back/domain/post/post/entity/Post.java @@ -42,7 +42,7 @@ public enum PostType { private int viewCount; private Boolean isMento; - private String career; + private String job; private Boolean isResolve; @@ -107,4 +107,11 @@ public void increaseViewCount() { public void updateResolveStatus(Boolean isResolve) { this.isResolve = isResolve; } + + public void updateJob(String job) { + if (job == null || job.isBlank()) { + throw new ServiceException("400", "직업은 null이거나 공백일 수 없습니다."); + } + this.job = job; + } } diff --git a/back/src/main/java/com/back/domain/post/post/service/PostService.java b/back/src/main/java/com/back/domain/post/post/service/PostService.java index f3baeaaf..b385cfd2 100644 --- a/back/src/main/java/com/back/domain/post/post/service/PostService.java +++ b/back/src/main/java/com/back/domain/post/post/service/PostService.java @@ -1,10 +1,7 @@ package com.back.domain.post.post.service; import com.back.domain.member.member.entity.Member; -import com.back.domain.post.post.dto.PostAllResponse; -import com.back.domain.post.post.dto.PostCreateRequest; -import com.back.domain.post.post.dto.PostDto; -import com.back.domain.post.post.dto.PostSingleResponse; +import com.back.domain.post.post.dto.*; import com.back.domain.post.post.entity.Post; import com.back.domain.post.post.repository.PostRepository; import com.back.global.exception.ServiceException; @@ -43,12 +40,6 @@ public Post createPost(PostCreateRequest postCreateRequest, Member member) { throw new ServiceException("400", "실무 경험 공유 게시글은 멘토만 작성할 수 있습니다."); } -// if( postType == Post.PostType.PRACTICEPOST ) { -// if(member.getCareer() == null || member.getCareer().isEmpty()) { -// throw new ServiceException("400", "멘토는 경력을 입력해야 실무 경험 공유 게시글을 작성할 수 있습니다."); -// } -// } - Post post = Post.builder() .title(postCreateRequest.title()) .content(postCreateRequest.content()) @@ -57,6 +48,10 @@ public Post createPost(PostCreateRequest postCreateRequest, Member member) { .build(); + if(postType == Post.PostType.PRACTICEPOST) { + post.updateJob(postCreateRequest.job()); + } + // PostType이 QUESTIONPOST인 경우 isResolve를 false로 초기화 if(postType == Post.PostType.QUESTIONPOST) { post.updateResolveStatus(false); @@ -67,6 +62,7 @@ public Post createPost(PostCreateRequest postCreateRequest, Member member) { return post; } + @Transactional public void removePost(Long postId, Member member) { Post post = findById(postId); diff --git a/back/src/test/java/com/back/domain/post/post/controller/PostControllerTest.java b/back/src/test/java/com/back/domain/post/post/controller/PostControllerTest.java index f96b3d8c..a4a87c26 100644 --- a/back/src/test/java/com/back/domain/post/post/controller/PostControllerTest.java +++ b/back/src/test/java/com/back/domain/post/post/controller/PostControllerTest.java @@ -438,22 +438,22 @@ void t12() throws Exception { .andExpect(jsonPath("$.msg").value("게시글 좋아요 성공")); } - @Test - @DisplayName("게시글 좋아요 조회") - void t13() throws Exception { - ResultActions resultActions = mvc - .perform( - get("/post/{post_id}/liked", 1L) - ) - .andDo(print()); - - resultActions - .andExpect(handler().handlerType(PostController.class)) - .andExpect(handler().methodName("getLike")) - .andExpect(jsonPath("$.resultCode").value("200")) - .andExpect(jsonPath("$.msg").value("게시글 좋아요 조회 성공")) - .andExpect(jsonPath("$.data.likeCount").exists()); - } +// @Test +// @DisplayName("게시글 좋아요 조회") +// void t13() throws Exception { +// ResultActions resultActions = mvc +// .perform( +// get("/post/{post_id}/liked", 1L) +// ) +// .andDo(print()); +// +// resultActions +// .andExpect(handler().handlerType(PostController.class)) +// .andExpect(handler().methodName("getLike")) +// .andExpect(jsonPath("$.resultCode").value("200")) +// .andExpect(jsonPath("$.msg").value("게시글 좋아요 조회 성공")) +// .andExpect(jsonPath("$.data.likeCount").exists()); +// } @Test @DisplayName("게시글 싫어요 성공") @@ -471,22 +471,22 @@ void t14() throws Exception { .andExpect(jsonPath("$.msg").value("게시글 싫어요 성공")); } - @Test - @DisplayName("게시글 싫어요 조회") - void t15() throws Exception { - ResultActions resultActions = mvc - .perform( - get("/post/{post_id}/disliked", 1L) - ) - .andDo(print()); - - resultActions - .andExpect(handler().handlerType(PostController.class)) - .andExpect(handler().methodName("getDisLike")) - .andExpect(jsonPath("$.resultCode").value("200")) - .andExpect(jsonPath("$.msg").value("게시글 싫어요 조회 성공")) - .andExpect(jsonPath("$.data.likeCount").exists()); - } +// @Test +// @DisplayName("게시글 싫어요 조회") +// void t15() throws Exception { +// ResultActions resultActions = mvc +// .perform( +// get("/post/{post_id}/disliked", 1L) +// ) +// .andDo(print()); +// +// resultActions +// .andExpect(handler().handlerType(PostController.class)) +// .andExpect(handler().methodName("getDisLike")) +// .andExpect(jsonPath("$.resultCode").value("200")) +// .andExpect(jsonPath("$.msg").value("게시글 싫어요 조회 성공")) +// .andExpect(jsonPath("$.data.likeCount").exists()); +// } @Test @DisplayName("좋아요 -> 싫어요 토글 테스트") @@ -539,7 +539,7 @@ void t18() throws Exception { ResultActions resultActions = mvc .perform( - get("/post/Detail/{post_id}", 1L) + get("/post/detail/{post_id}", 1L) ) .andDo(print()); @@ -566,7 +566,7 @@ void t18() throws Exception { void t19() throws Exception { ResultActions resultActions = mvc .perform( - get("/post/Detail/{post_id}", 999L) + get("/post/detail/{post_id}", 999L) ) .andDo(print()); diff --git a/back/src/test/java/com/back/domain/post/post/service/PostServiceTest.java b/back/src/test/java/com/back/domain/post/post/service/PostServiceTest.java index fbce14bd..1d3e19a2 100644 --- a/back/src/test/java/com/back/domain/post/post/service/PostServiceTest.java +++ b/back/src/test/java/com/back/domain/post/post/service/PostServiceTest.java @@ -45,7 +45,7 @@ class CreatePostTest { void createPost_informationPost_success() { // given Member member = MemberFixture.create(1L, "test@test.com", "Test User", "password", Member.Role.MENTEE); - PostCreateRequest request = new PostCreateRequest("INFORMATIONPOST","제목","내용"); + PostCreateRequest request = new PostCreateRequest("INFORMATIONPOST","제목","내용",""); Post expectedPost = createPost("제목", "내용", member, Post.PostType.INFORMATIONPOST); @@ -68,7 +68,7 @@ void createPost_informationPost_success() { void createPost_practicePost_mentor_success() { // given Member mentor = MemberFixture.create(1L, "mentor@test.com", "Mentor", "password", Member.Role.MENTOR); - PostCreateRequest request = new PostCreateRequest("PRACTICEPOST","실무경험","실무내용"); + PostCreateRequest request = new PostCreateRequest("PRACTICEPOST","실무경험","실무내용","123"); Post expectedPost = createPost("실무 경험", "실무 내용", mentor, Post.PostType.PRACTICEPOST); when(postRepository.save(any(Post.class))).thenReturn(expectedPost); @@ -86,7 +86,7 @@ void createPost_practicePost_mentor_success() { void createPost_practicePost_mentee_failure() { // given Member mentee = MemberFixture.create(1L, "mentee@test.com", "Mentee", "password", Member.Role.MENTEE); - PostCreateRequest request = new PostCreateRequest("PRACTICEPOST","실무경험","실무내용"); + PostCreateRequest request = new PostCreateRequest("PRACTICEPOST","실무경험","실무내용",""); // when & then assertThatThrownBy(() -> postService.createPost(request, mentee)) @@ -101,7 +101,7 @@ void createPost_practicePost_mentee_failure() { void createPost_questionPost_initializeIsResolve() { // given Member member = MemberFixture.create(1L, "test@test.com", "Test User", "password", Member.Role.MENTEE); - PostCreateRequest request = new PostCreateRequest("QUESTIONPOST","질문경험","질문내용"); + PostCreateRequest request = new PostCreateRequest("QUESTIONPOST","질문경험","질문내용",""); Post expectedPost = createPost("질문", "질문 내용", member, Post.PostType.QUESTIONPOST); expectedPost.updateResolveStatus(false); @@ -122,7 +122,7 @@ void createPost_questionPost_initializeIsResolve() { void createPost_invalidPostType_failure() { // given Member member = MemberFixture.createDefault(); - PostCreateRequest request = new PostCreateRequest("INVALIDPOST","질문경험","질문내용"); + PostCreateRequest request = new PostCreateRequest("INVALIDPOST","질문경험","질문내용",""); // when & then assertThatThrownBy(() -> postService.createPost(request, member)) @@ -202,7 +202,7 @@ void updatePost_author_success() { Member author = MemberFixture.create(1L, "author@test.com", "Author", "password", Member.Role.MENTEE); Post post = createPost("기존 제목", "기존 내용", author, Post.PostType.INFORMATIONPOST); Long postId = 1L; - PostCreateRequest updateRequest = new PostCreateRequest("INFORMATIONPOST","새 제목","새 내용"); + PostCreateRequest updateRequest = new PostCreateRequest("INFORMATIONPOST","새 제목","새 내용",""); when(postRepository.findById(postId)).thenReturn(Optional.of(post)); when(postRepository.save(any(Post.class))).thenReturn(post); @@ -224,7 +224,7 @@ void updatePost_notAuthor_failure() { Member otherUser = MemberFixture.create(2L, "other@test.com", "Other", "password", Member.Role.MENTEE); Post post = createPost("제목", "내용", author, Post.PostType.INFORMATIONPOST); Long postId = 1L; - PostCreateRequest updateRequest = new PostCreateRequest("INFORMATIONPOST","새 내용","새 제목"); + PostCreateRequest updateRequest = new PostCreateRequest("INFORMATIONPOST","새 내용","새 제목",""); when(postRepository.findById(postId)).thenReturn(Optional.of(post)); @@ -244,7 +244,7 @@ void updatePost_nullOrBlankTitle_failure() { Member author = MemberFixture.create(1L, "author@test.com", "Author", "password", Member.Role.MENTEE); Post post = createPost("제목", "내용", author, Post.PostType.INFORMATIONPOST); Long postId = 1L; - PostCreateRequest updateRequest = new PostCreateRequest("INFORMATIONPOST","","새 내용"); + PostCreateRequest updateRequest = new PostCreateRequest("INFORMATIONPOST","","새 내용",""); when(postRepository.findById(postId)).thenReturn(Optional.of(post)); @@ -263,7 +263,7 @@ void updatePost_nullOrBlankContent_failure() { Member author = MemberFixture.create(1L, "author@test.com", "Author", "password", Member.Role.MENTEE); Post post = createPost("제목", "내용", author, Post.PostType.INFORMATIONPOST); Long postId = 1L; - PostCreateRequest updateRequest = new PostCreateRequest("INFORMATIONPOST","새 제목",""); + PostCreateRequest updateRequest = new PostCreateRequest("INFORMATIONPOST","새 제목","",""); when(postRepository.findById(postId)).thenReturn(Optional.of(post));