Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public RsData<PostPagingResponse> getPostWithPage(
return new RsData<>("200", "게시글이 조회 되었습니다.", resDto);
}

@Operation(summary = "게시글 생성")
@Operation(summary = "게시글 생성 ")
@PostMapping
public RsData<PostCreateResponse> createPost(
@Valid @RequestBody PostCreateRequest postCreateRequest
Expand Down Expand Up @@ -93,41 +93,29 @@ public RsData<Void> updatePost(@PathVariable Long post_id

@Operation(summary = "게시글 좋아요")
@PostMapping("/{post_id}/liked")
public RsData<Void> likePost(@PathVariable Long post_id) {
public RsData<PostLikedResponse> likePost(@PathVariable Long post_id) {
postLikeService.likePost(post_id);

return new RsData<>("200", "게시글 좋아요 성공", null);
}

@Operation(summary = "게시글 좋아요 (Show)")
@GetMapping("/{post_id}/liked")
public RsData<PostLikedResponse> 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<PostLikedResponse> 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 = "게시글 싫어요")
@PostMapping("/{post_id}/disliked")
public RsData<PostLikedResponse> 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<PostDetailResponse> getPostDetail(@PathVariable Long post_id) {

PostDetailResponse response = postDetailFacade.getDetailWithViewIncrement(post_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {


Expand Down
6 changes: 4 additions & 2 deletions back/src/main/java/com/back/domain/post/post/dto/PostDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
public record PostDto(
Long postId,
String title,
String content
String content,
int viewCount
) {


public static PostDto from(Post post) {
return new PostDto(
post.getId(),
post.getTitle(),
post.getContent()
post.getContent(),
post.getViewCount()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public enum PostType {
private int viewCount;

private Boolean isMento;
private String career;
private String job;

private Boolean isResolve;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("게시글 싫어요 성공")
Expand All @@ -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("좋아요 -> 싫어요 토글 테스트")
Expand Down Expand Up @@ -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());

Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CreatePostTest {
void createPost_informationPost_success() {
// given
Member member = MemberFixture.create(1L, "[email protected]", "Test User", "password", Member.Role.MENTEE);
PostCreateRequest request = new PostCreateRequest("INFORMATIONPOST","제목","내용");
PostCreateRequest request = new PostCreateRequest("INFORMATIONPOST","제목","내용","");


Post expectedPost = createPost("제목", "내용", member, Post.PostType.INFORMATIONPOST);
Expand All @@ -68,7 +68,7 @@ void createPost_informationPost_success() {
void createPost_practicePost_mentor_success() {
// given
Member mentor = MemberFixture.create(1L, "[email protected]", "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);
Expand All @@ -86,7 +86,7 @@ void createPost_practicePost_mentor_success() {
void createPost_practicePost_mentee_failure() {
// given
Member mentee = MemberFixture.create(1L, "[email protected]", "Mentee", "password", Member.Role.MENTEE);
PostCreateRequest request = new PostCreateRequest("PRACTICEPOST","실무경험","실무내용");
PostCreateRequest request = new PostCreateRequest("PRACTICEPOST","실무경험","실무내용","");

// when & then
assertThatThrownBy(() -> postService.createPost(request, mentee))
Expand All @@ -101,7 +101,7 @@ void createPost_practicePost_mentee_failure() {
void createPost_questionPost_initializeIsResolve() {
// given
Member member = MemberFixture.create(1L, "[email protected]", "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);
Expand All @@ -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))
Expand Down Expand Up @@ -202,7 +202,7 @@ void updatePost_author_success() {
Member author = MemberFixture.create(1L, "[email protected]", "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);
Expand All @@ -224,7 +224,7 @@ void updatePost_notAuthor_failure() {
Member otherUser = MemberFixture.create(2L, "[email protected]", "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));
Expand All @@ -244,7 +244,7 @@ void updatePost_nullOrBlankTitle_failure() {
Member author = MemberFixture.create(1L, "[email protected]", "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));

Expand All @@ -263,7 +263,7 @@ void updatePost_nullOrBlankContent_failure() {
Member author = MemberFixture.create(1L, "[email protected]", "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));

Expand Down