diff --git a/src/main/java/com/keeper/homepage/domain/comment/application/CommentService.java b/src/main/java/com/keeper/homepage/domain/comment/application/CommentService.java index 902b3822d..744f89b40 100644 --- a/src/main/java/com/keeper/homepage/domain/comment/application/CommentService.java +++ b/src/main/java/com/keeper/homepage/domain/comment/application/CommentService.java @@ -1,5 +1,7 @@ package com.keeper.homepage.domain.comment.application; +import static com.keeper.homepage.domain.post.application.PostService.ANONYMOUS_NAME; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.익명게시판; import static com.keeper.homepage.global.error.ErrorCode.COMMENT_NOT_ALLOWED; import static com.keeper.homepage.global.error.ErrorCode.COMMENT_NOT_PARENT; import static com.keeper.homepage.global.error.ErrorCode.COMMENT_NOT_WRITER; @@ -63,7 +65,12 @@ public CommentListResponse getComments(Long postId) { List comments = post.getComments(); List commentResponses = comments.stream() - .map(CommentResponse::from) + .map(comment -> { + if (post.isCategory(익명게시판)) { + return CommentResponse.of(comment, ANONYMOUS_NAME, null); + } + return CommentResponse.from(comment); + }) .toList(); return CommentListResponse.from(commentResponses); } diff --git a/src/main/java/com/keeper/homepage/domain/comment/dto/response/CommentResponse.java b/src/main/java/com/keeper/homepage/domain/comment/dto/response/CommentResponse.java index bc621b72a..6bb761163 100644 --- a/src/main/java/com/keeper/homepage/domain/comment/dto/response/CommentResponse.java +++ b/src/main/java/com/keeper/homepage/domain/comment/dto/response/CommentResponse.java @@ -33,4 +33,17 @@ public static CommentResponse from(Comment comment) { .dislikeCount(comment.getCommentDislikes().size()) .build(); } + + public static CommentResponse of(Comment comment, String writerName, String writerThumbnailPath) { + return CommentResponse.builder() + .commentId(comment.getId()) + .writerName(writerName) + .writerThumbnailPath(writerThumbnailPath) + .content(comment.getContent()) + .registerTime(comment.getRegisterTime()) + .parentId(comment.getParent() != null ? comment.getParent().getId() : null) + .likeCount(comment.getCommentLikes().size()) + .dislikeCount(comment.getCommentDislikes().size()) + .build(); + } } diff --git a/src/main/java/com/keeper/homepage/domain/post/application/PostService.java b/src/main/java/com/keeper/homepage/domain/post/application/PostService.java index cf0b9f9a8..e86597cca 100644 --- a/src/main/java/com/keeper/homepage/domain/post/application/PostService.java +++ b/src/main/java/com/keeper/homepage/domain/post/application/PostService.java @@ -1,7 +1,7 @@ package com.keeper.homepage.domain.post.application; -import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.ANONYMOUS_CATEGORY; -import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.EXAM_CATEGORY; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.익명게시판; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.시험게시판; import static com.keeper.homepage.global.error.ErrorCode.FILE_NOT_FOUND; import static com.keeper.homepage.global.error.ErrorCode.POST_ACCESS_CONDITION_NEED; import static com.keeper.homepage.global.error.ErrorCode.POST_CONTENT_NEED; @@ -120,7 +120,7 @@ public PostDetailResponse find(Member member, long postId, String password) { } private void checkExamPost(Member member, Post post) { - if (post.isCategory(EXAM_CATEGORY.getId())) { + if (post.isCategory(시험게시판)) { checkAccessibleExamPost(member, post); } } @@ -165,14 +165,14 @@ private void checkAccessibleSecretPost(Member member, Post post, String password } private String getWriterName(Post post) { - if (post.isCategory(ANONYMOUS_CATEGORY.getId())) { + if (post.isCategory(익명게시판)) { return ANONYMOUS_NAME; } return post.getWriterNickname(); } private String getWriterThumbnailPath(Post post) { - if (post.isCategory(ANONYMOUS_CATEGORY.getId())) { + if (post.isCategory(익명게시판)) { return null; } return post.getMember().getThumbnailPath(); @@ -215,6 +215,7 @@ public void deletePostThumbnail(Member member, long postId) { thumbnailUtil.deleteFileAndEntityIfExist(post.getThumbnail()); } + @Transactional public void delete(Member member, long postId) { Post post = validPostFindService.findById(postId); @@ -282,30 +283,37 @@ public Page getPosts(long categoryId, String searchType, String se Category category = categoryFindService.findById(categoryId); if (searchType == null) { return postRepository.findAllRecentByCategory(category, pageable) - .map(PostResponse::from); + .map(this::getPostResponse); } if (searchType.equals("title")) { return postRepository.findAllRecentByCategoryAndTitle(category, search, pageable) - .map(PostResponse::from); + .map(this::getPostResponse); } if (searchType.equals("content")) { return postRepository.findAllRecentByCategoryAndContent(category, search, pageable) - .map(PostResponse::from); + .map(this::getPostResponse); } if (searchType.equals("writer")) { return postRepository.findAllRecentByCategoryAndWriter(category, search, pageable) - .map(PostResponse::from); + .map(this::getPostResponse); } if (searchType.equals("title+content")) { return postRepository.findAllRecentByCategoryAndTitleOrContent(category, search, pageable) - .map(PostResponse::from); + .map(this::getPostResponse); } throw new BusinessException(searchType, "searchType", POST_SEARCH_TYPE_NOT_FOUND); } + private PostResponse getPostResponse(Post post) { + if (post.isCategory(익명게시판)) { + return PostResponse.of(post, ANONYMOUS_NAME, null); + } + return PostResponse.from(post); + } + public List getRecentPosts() { return postRepository.findAllRecent().stream() - .map(PostResponse::from) + .map(this::getPostResponse) .limit(10) .toList(); } @@ -320,7 +328,7 @@ public List getTrendPosts() { return Integer.compare(postScore2, postScore1); }); return posts.stream() - .map(PostResponse::from) + .map(this::getPostResponse) .limit(10) .toList(); } diff --git a/src/main/java/com/keeper/homepage/domain/post/converter/CategoryTypeConverter.java b/src/main/java/com/keeper/homepage/domain/post/converter/CategoryTypeConverter.java new file mode 100644 index 000000000..4c1c05266 --- /dev/null +++ b/src/main/java/com/keeper/homepage/domain/post/converter/CategoryTypeConverter.java @@ -0,0 +1,29 @@ +package com.keeper.homepage.domain.post.converter; + +import com.keeper.homepage.domain.post.entity.category.Category.CategoryType; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; +import lombok.extern.slf4j.Slf4j; + +@Converter +@Slf4j +public class CategoryTypeConverter implements AttributeConverter { + + @Override + public String convertToDatabaseColumn(CategoryType type) { + return type != null ? type.getName() : null; + } + + @Override + public CategoryType convertToEntityAttribute(String dbData) { + if (dbData == null) { + return null; + } + try { + return CategoryType.fromCode(dbData); + } catch (IllegalArgumentException e) { + log.error("failure to convert cause unexpected code [{}]", dbData, e); + throw e; + } + } +} diff --git a/src/main/java/com/keeper/homepage/domain/post/dao/PostRepository.java b/src/main/java/com/keeper/homepage/domain/post/dao/PostRepository.java index 96acc2574..29007e500 100644 --- a/src/main/java/com/keeper/homepage/domain/post/dao/PostRepository.java +++ b/src/main/java/com/keeper/homepage/domain/post/dao/PostRepository.java @@ -15,18 +15,32 @@ public interface PostRepository extends JpaRepository { Optional findByIdAndIdNot(Long postId, Long virtualId); + /** + * 카테고리 + 공지글 + 등록시간 최신순 정렬 + * + * @param category 게시글 카테고리 + */ @Query("SELECT p FROM Post p " + "WHERE p.category = :category " + "AND p.isNotice = true " + "ORDER BY p.registerTime DESC") List findAllNoticeByCategory(@Param("category") Category category); + /** + * 임시 저장글 제외 + 등록 시간 최신순 정렬 + */ @Query("SELECT p FROM Post p " + "WHERE p.isTemp = false " + "AND p.id <> 1 " // virtual post + "ORDER BY p.registerTime DESC") List findAllRecent(); + /** + * 카테고리 + 공지글 제외 + 임시글 제외 + 등록시간 최신순 정렬 + * + * @param category 게시글 카테고리 + * @param pageable Pageable + */ @Query("SELECT p FROM Post p " + "WHERE p.category = :category " + "AND p.isNotice = false " @@ -35,6 +49,13 @@ public interface PostRepository extends JpaRepository { + "ORDER BY p.registerTime DESC") Page findAllRecentByCategory(@Param("category") Category category, Pageable pageable); + /** + * 카테고리 + 공지글 제외 + 임시글 제외 + 제목 검색 + 등록시간 최신순 정렬 + * + * @param category 게시글 카테고리 + * @param search 검색어 + * @param pageable Pageable + */ @Query("SELECT p FROM Post p " + "WHERE p.category = :category " + "AND p.isNotice = false " @@ -44,6 +65,13 @@ public interface PostRepository extends JpaRepository { Page findAllRecentByCategoryAndTitle(@Param("category") Category category, @Param("search") String search, Pageable pageable); + /** + * 카테고리 + 공지글 제외 + 임시글 제외 + 내용 검색 + 등록시간 최신순 정렬 + * + * @param category 게시글 카테고리 + * @param search 검색어 + * @param pageable Pageable + */ @Query("SELECT p FROM Post p " + "WHERE p.category = :category " + "AND p.isNotice = false " @@ -53,6 +81,13 @@ Page findAllRecentByCategoryAndTitle(@Param("category") Category category, Page findAllRecentByCategoryAndContent(@Param("category") Category category, @Param("search") String search, Pageable pageable); + /** + * 카테고리 + 공지글 제외 + 임시글 제외 + 제목&내용 검색 + 등록시간 최신순 정렬 + * + * @param category 게시글 카테고리 + * @param search 검색어 + * @param pageable Pageable + */ @Query("SELECT p FROM Post p " + "WHERE p.category = :category " + "AND p.isNotice = false " @@ -63,6 +98,13 @@ Page findAllRecentByCategoryAndContent(@Param("category") Category categor Page findAllRecentByCategoryAndTitleOrContent(@Param("category") Category category, @Param("search") String search, Pageable pageable); + /** + * 카테고리 + 공지글 제외 + 임시글 제외 + 작성자 닉네임 검색 + 등록시간 최신순 정렬 + * + * @param category 게시글 카테고리 + * @param search 검색어 + * @param pageable Pageable + */ @Query("SELECT p FROM Post p " + "WHERE p.category = :category " + "AND p.isNotice = false " @@ -72,6 +114,12 @@ Page findAllRecentByCategoryAndTitleOrContent(@Param("category") Category Page findAllRecentByCategoryAndWriter(@Param("category") Category category, @Param("search") String search, Pageable pageable); + /** + * 임시 저장글 제외 + 등록 시간 최신순 정렬 + 날짜 사이의 게시글 + * + * @param startDate 가져올 시작 시간 + * @param endDate 가져올 끝 시간 + */ @Query("SELECT p FROM Post p " + "WHERE p.isTemp = false " + "AND p.registerTime BETWEEN :startDate AND :endDate") diff --git a/src/main/java/com/keeper/homepage/domain/post/dto/response/PostDetailResponse.java b/src/main/java/com/keeper/homepage/domain/post/dto/response/PostDetailResponse.java index 61cc98002..f936dd26a 100644 --- a/src/main/java/com/keeper/homepage/domain/post/dto/response/PostDetailResponse.java +++ b/src/main/java/com/keeper/homepage/domain/post/dto/response/PostDetailResponse.java @@ -45,7 +45,7 @@ public static PostDetailResponse of(Post post, String writerName, String writerT Post nextPost) { return PostDetailResponse.builder() .categoryId(post.getCategory().getId()) - .categoryName(post.getCategory().getName()) + .categoryName(post.getCategory().getType().toString()) .title(post.getTitle()) .writerName(writerName) .writerThumbnailPath(writerThumbnailPath) diff --git a/src/main/java/com/keeper/homepage/domain/post/dto/response/PostResponse.java b/src/main/java/com/keeper/homepage/domain/post/dto/response/PostResponse.java index c37c5d613..574c8ef86 100644 --- a/src/main/java/com/keeper/homepage/domain/post/dto/response/PostResponse.java +++ b/src/main/java/com/keeper/homepage/domain/post/dto/response/PostResponse.java @@ -17,6 +17,7 @@ public class PostResponse { private Long id; private String title; private String writerName; + private String writerThumbnailPath; private Integer visitCount; private Integer commentCount; private Boolean isSecret; @@ -30,6 +31,21 @@ public static PostResponse from(Post post) { .id(post.getId()) .title(post.getTitle()) .writerName(post.getWriterNickname()) + .writerThumbnailPath(post.getMember().getThumbnailPath()) + .visitCount(post.getVisitCount()) + .commentCount(post.getComments().size()) + .isSecret(post.isSecret()) + .thumbnailPath(post.getThumbnailPath()) + .registerTime(post.getRegisterTime()) + .build(); + } + + public static PostResponse of(Post post, String writerName, String writerThumbnailPath) { + return PostResponse.builder() + .id(post.getId()) + .title(post.getTitle()) + .writerName(writerName) + .writerThumbnailPath(writerThumbnailPath) .visitCount(post.getVisitCount()) .commentCount(post.getComments().size()) .isSecret(post.isSecret()) diff --git a/src/main/java/com/keeper/homepage/domain/post/entity/Post.java b/src/main/java/com/keeper/homepage/domain/post/entity/Post.java index f7db31457..82befd94a 100644 --- a/src/main/java/com/keeper/homepage/domain/post/entity/Post.java +++ b/src/main/java/com/keeper/homepage/domain/post/entity/Post.java @@ -1,5 +1,6 @@ package com.keeper.homepage.domain.post.entity; +import static com.keeper.homepage.domain.post.entity.category.Category.getCategoryBy; import static jakarta.persistence.CascadeType.ALL; import static jakarta.persistence.CascadeType.REMOVE; import static jakarta.persistence.FetchType.LAZY; @@ -12,6 +13,7 @@ import com.keeper.homepage.domain.member.entity.post.MemberHasPostDislike; import com.keeper.homepage.domain.member.entity.post.MemberHasPostLike; import com.keeper.homepage.domain.post.entity.category.Category; +import com.keeper.homepage.domain.post.entity.category.Category.CategoryType; import com.keeper.homepage.domain.thumbnail.entity.Thumbnail; import com.keeper.homepage.global.entity.BaseEntity; import jakarta.persistence.Column; @@ -141,8 +143,8 @@ public void addVisitCount() { this.visitCount++; } - public boolean isCategory(long categoryId) { - return this.category.getId().equals(categoryId); + public boolean isCategory(CategoryType category) { + return this.category.equals(getCategoryBy(category)); } public boolean isMine(Member member) { diff --git a/src/main/java/com/keeper/homepage/domain/post/entity/category/Category.java b/src/main/java/com/keeper/homepage/domain/post/entity/category/Category.java index 5cd74f6c5..59170c52f 100644 --- a/src/main/java/com/keeper/homepage/domain/post/entity/category/Category.java +++ b/src/main/java/com/keeper/homepage/domain/post/entity/category/Category.java @@ -3,24 +3,25 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import com.keeper.homepage.domain.post.converter.CategoryTypeConverter; import jakarta.persistence.Column; +import jakarta.persistence.Convert; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.Table; +import java.util.Arrays; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; -import org.hibernate.annotations.DynamicInsert; -import org.hibernate.annotations.DynamicUpdate; +import lombok.ToString; -@DynamicInsert -@DynamicUpdate @Getter @NoArgsConstructor(access = PROTECTED) @Entity +@ToString(of = {"type"}) @EqualsAndHashCode(of = {"id"}) @Table(name = "category") public class Category { @@ -33,27 +34,47 @@ public class Category { @Column(name = "id", nullable = false, updatable = false) private Long id; + @Convert(converter = CategoryTypeConverter.class) @Column(name = "name", nullable = false, length = MAX_NAME_LENGTH) - private String name; + private CategoryType type; + + public static Category getCategoryBy(CategoryType type) { + return Category.builder() + .id(type.id) + .type(type) + .build(); + } @Builder - private Category(String name) { - this.name = name; + private Category(Long id, CategoryType type) { + this.id = id; + this.type = type; } @Getter @RequiredArgsConstructor public enum CategoryType { - VIRTUAL_CATEGORY(1), - NOTICE_CATEGORY(101), - SUGGESTION_CATEGORY(102), - INFORMATION_CATEGORY(103), - FREE_CATEGORY(104), - ANONYMOUS_CATEGORY(105), - GRADUATE_CATEGORY(106), - EXAM_CATEGORY(107), + VIRTUAL_CATEGORY(1, "virtual_category"), + 공지사항(101, "공지사항"), + 건의사항(102, "건의사항"), + 정보게시판(103, "정보게시판"), + 자유게시판(104, "자유게시판"), + 익명게시판(105, "익명게시판"), + 졸업생게시판(106, "졸업생게시판"), + 시험게시판(107, "시험게시판"), + 발표자료(202, "발표자료"), + 기술문서(203, "기술문서"), + 회계부(204, "회계부"), ; private final long id; + private final String name; + + public static CategoryType fromCode(String type) { + return Arrays.stream(CategoryType.values()) + .filter(categoryType -> categoryType.getName().equals(type)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 카테고리 타입입니다.")); + } } } diff --git a/src/test/java/com/keeper/homepage/IntegrationTest.java b/src/test/java/com/keeper/homepage/IntegrationTest.java index 066525198..c34c6abde 100644 --- a/src/test/java/com/keeper/homepage/IntegrationTest.java +++ b/src/test/java/com/keeper/homepage/IntegrationTest.java @@ -64,7 +64,6 @@ import com.keeper.homepage.domain.member.dao.role.MemberJobRepository; import com.keeper.homepage.domain.member.dao.type.MemberTypeRepository; import com.keeper.homepage.domain.point.dao.PointLogRepository; -import com.keeper.homepage.domain.post.CategoryTestHelper; import com.keeper.homepage.domain.post.PostTestHelper; import com.keeper.homepage.domain.post.application.PostService; import com.keeper.homepage.domain.post.dao.PostHasFileRepository; @@ -339,9 +338,6 @@ public class IntegrationTest { @Autowired protected SeminarTestHelper seminarTestHelper; - @Autowired - protected CategoryTestHelper categoryTestHelper; - @Autowired protected PostTestHelper postTestHelper; diff --git a/src/test/java/com/keeper/homepage/domain/post/CategoryTestHelper.java b/src/test/java/com/keeper/homepage/domain/post/CategoryTestHelper.java deleted file mode 100644 index b879c292f..000000000 --- a/src/test/java/com/keeper/homepage/domain/post/CategoryTestHelper.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.keeper.homepage.domain.post; - -import com.keeper.homepage.domain.post.dao.category.CategoryRepository; -import com.keeper.homepage.domain.post.entity.category.Category; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class CategoryTestHelper { - - @Autowired - CategoryRepository categoryRepository; - - public Category generate() { - return this.builder().build(); - } - - public CategoryBuilder builder() { - return new CategoryBuilder(); - } - - public final class CategoryBuilder { - - private String name; - - private CategoryBuilder() { - - } - - public CategoryBuilder name(String name) { - this.name = name; - return this; - } - - public Category build() { - return categoryRepository.save(Category.builder() - .name(name != null ? name : "카테고리 이름") - .build()); - } - } -} diff --git a/src/test/java/com/keeper/homepage/domain/post/PostTestHelper.java b/src/test/java/com/keeper/homepage/domain/post/PostTestHelper.java index b10168662..dbe714692 100644 --- a/src/test/java/com/keeper/homepage/domain/post/PostTestHelper.java +++ b/src/test/java/com/keeper/homepage/domain/post/PostTestHelper.java @@ -1,5 +1,8 @@ package com.keeper.homepage.domain.post; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.자유게시판; +import static com.keeper.homepage.domain.post.entity.category.Category.getCategoryBy; + import com.keeper.homepage.domain.member.MemberTestHelper; import com.keeper.homepage.domain.member.entity.Member; import com.keeper.homepage.domain.post.dao.PostRepository; @@ -23,9 +26,6 @@ public class PostTestHelper { @Autowired ThumbnailTestHelper thumbnailTestHelper; - @Autowired - CategoryTestHelper categoryTestHelper; - public Post generate() { return this.builder().build(); } @@ -125,7 +125,7 @@ public Post build() { .isSecret(isSecret != null ? isSecret : false) .isTemp(isTemp != null ? isTemp : false) .password(password) - .category(category != null ? category : categoryTestHelper.generate()) + .category(category != null ? category : getCategoryBy(자유게시판)) .thumbnail(thumbnail != null ? thumbnail : thumbnailTestHelper.generateThumbnail()) .build()); } diff --git a/src/test/java/com/keeper/homepage/domain/post/api/AdminPostControllerTest.java b/src/test/java/com/keeper/homepage/domain/post/api/AdminPostControllerTest.java index 242fed505..21a5f19a7 100644 --- a/src/test/java/com/keeper/homepage/domain/post/api/AdminPostControllerTest.java +++ b/src/test/java/com/keeper/homepage/domain/post/api/AdminPostControllerTest.java @@ -2,6 +2,8 @@ import static com.keeper.homepage.domain.member.entity.job.MemberJob.MemberJobType.ROLE_회원; import static com.keeper.homepage.domain.member.entity.job.MemberJob.MemberJobType.ROLE_회장; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.자유게시판; +import static com.keeper.homepage.domain.post.entity.category.Category.getCategoryBy; import static com.keeper.homepage.global.config.security.data.JwtType.ACCESS_TOKEN; import static com.keeper.homepage.global.restdocs.RestDocsHelper.getSecuredValue; import static org.springframework.restdocs.cookies.CookieDocumentation.cookieWithName; @@ -34,7 +36,7 @@ void setUp() { adminToken = jwtTokenProvider.createAccessToken(ACCESS_TOKEN, adminId, ROLE_회원, ROLE_회장); memberToken = jwtTokenProvider.createAccessToken(ACCESS_TOKEN, memberId, ROLE_회원); post = postTestHelper.generate(); - category = categoryTestHelper.generate(); + category = getCategoryBy(자유게시판); } @Nested diff --git a/src/test/java/com/keeper/homepage/domain/post/api/PostApiTestHelper.java b/src/test/java/com/keeper/homepage/domain/post/api/PostApiTestHelper.java index ad4c4f6de..aab8c6536 100644 --- a/src/test/java/com/keeper/homepage/domain/post/api/PostApiTestHelper.java +++ b/src/test/java/com/keeper/homepage/domain/post/api/PostApiTestHelper.java @@ -146,6 +146,7 @@ FieldDescriptor[] getPostsResponse() { fieldWithPath("id").description("게시글 ID"), fieldWithPath("title").description("게시글 제목"), fieldWithPath("writerName").description("게시글 작성자 닉네임"), + fieldWithPath("writerThumbnailPath").description("게시글 작성자 썸네일 주소"), fieldWithPath("visitCount").description("게시글 조회수"), fieldWithPath("commentCount").description("게시글 댓글수"), fieldWithPath("isSecret").description("비밀글 여부"), diff --git a/src/test/java/com/keeper/homepage/domain/post/api/PostControllerTest.java b/src/test/java/com/keeper/homepage/domain/post/api/PostControllerTest.java index 9d34fca93..166a4f4f4 100644 --- a/src/test/java/com/keeper/homepage/domain/post/api/PostControllerTest.java +++ b/src/test/java/com/keeper/homepage/domain/post/api/PostControllerTest.java @@ -4,6 +4,8 @@ import static com.keeper.homepage.domain.post.application.PostService.EXAM_ACCESSIBLE_POINT; import static com.keeper.homepage.domain.post.dto.request.PostCreateRequest.POST_PASSWORD_LENGTH; import static com.keeper.homepage.domain.post.dto.request.PostCreateRequest.POST_TITLE_LENGTH; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.자유게시판; +import static com.keeper.homepage.domain.post.entity.category.Category.getCategoryBy; import static com.keeper.homepage.global.config.security.data.JwtType.ACCESS_TOKEN; import static com.keeper.homepage.global.restdocs.RestDocsHelper.getSecuredValue; import static com.keeper.homepage.global.restdocs.RestDocsHelper.listHelper; @@ -67,7 +69,7 @@ void setUp() throws IOException { other = memberTestHelper.generate(); memberToken = jwtTokenProvider.createAccessToken(ACCESS_TOKEN, member.getId(), ROLE_회원); otherToken = jwtTokenProvider.createAccessToken(ACCESS_TOKEN, other.getId(), ROLE_회원); - category = categoryTestHelper.generate(); + category = getCategoryBy(자유게시판); thumbnail = thumbnailTestHelper.getSmallThumbnailFile(); file = new MockMultipartFile("files", "testImage_1x1.png", "image/png", new FileInputStream("src/test/resources/images/testImage_1x1.png")); @@ -673,6 +675,7 @@ void setUp() { fieldWithPath("posts[].id").description("게시글 ID"), fieldWithPath("posts[].title").description("게시글 제목"), fieldWithPath("posts[].writerName").description("게시글 작성자 닉네임"), + fieldWithPath("posts[].writerThumbnailPath").description("게시글 작성자 썸네일 주소"), fieldWithPath("posts[].visitCount").description("게시글 조회수"), fieldWithPath("posts[].commentCount").description("게시글 댓글 개수"), fieldWithPath("posts[].isSecret").description("개시글 비밀글 여부"), diff --git a/src/test/java/com/keeper/homepage/domain/post/application/PostServiceTest.java b/src/test/java/com/keeper/homepage/domain/post/application/PostServiceTest.java index 834a2ea09..5c86dc4d4 100644 --- a/src/test/java/com/keeper/homepage/domain/post/application/PostServiceTest.java +++ b/src/test/java/com/keeper/homepage/domain/post/application/PostServiceTest.java @@ -1,9 +1,10 @@ package com.keeper.homepage.domain.post.application; import static com.keeper.homepage.domain.post.application.PostService.EXAM_ACCESSIBLE_POINT; -import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.ANONYMOUS_CATEGORY; -import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.EXAM_CATEGORY; -import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.VIRTUAL_CATEGORY; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.시험게시판; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.익명게시판; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.자유게시판; +import static com.keeper.homepage.domain.post.entity.category.Category.getCategoryBy; import static com.keeper.homepage.global.util.file.server.FileServerConstants.ROOT_PATH; import static java.io.File.separator; import static org.assertj.core.api.Assertions.assertThat; @@ -47,7 +48,7 @@ public class PostServiceTest extends IntegrationTest { @BeforeEach void setUp() { member = memberTestHelper.generate(); - category = categoryTestHelper.generate(); + category = getCategoryBy(자유게시판); thumbnail = thumbnailTestHelper.getThumbnailFile(); post = postTestHelper.builder().member(member).category(category).build(); postId = post.getId(); @@ -93,14 +94,14 @@ void should_throwBusinessException_when_requestNotFoundCategory() { class FindPost { private Member bestMember; - private Category virtualCategory, examCategory; + private Category category, examCategory; private final long virtualPostId = 1; @BeforeEach void setUp() { bestMember = memberTestHelper.builder().point(EXAM_ACCESSIBLE_POINT).build(); - virtualCategory = categoryRepository.findById(VIRTUAL_CATEGORY.getId()).orElseThrow(); - examCategory = categoryRepository.findById(EXAM_CATEGORY.getId()).orElseThrow(); + category = getCategoryBy(자유게시판); + examCategory = getCategoryBy(시험게시판); } @Test @@ -109,7 +110,7 @@ void should_success_when_getPost() { post = postTestHelper.builder() .member(bestMember) .password("비밀비밀") - .category(virtualCategory) + .category(category) .build(); em.flush(); @@ -147,7 +148,7 @@ public void should_successWithOutPassword_when_writerIsMe() throws Exception { @Test @DisplayName("익명 글은 작성자가 익명으로 조회되어야 한다.") public void should_getAnonymousName_when_getAnonymousPost() throws Exception { - Category anonymousCategory = categoryRepository.findById(ANONYMOUS_CATEGORY.getId()) + Category anonymousCategory = categoryRepository.findById(익명게시판.getId()) .orElseThrow(); post = postTestHelper.builder() .member(bestMember) @@ -507,7 +508,7 @@ class FindPosts { @BeforeEach void setUp() { - category = categoryTestHelper.generate(); + category = getCategoryBy(자유게시판); } @Test diff --git a/src/test/java/com/keeper/homepage/domain/post/dao/PostRepositoryTest.java b/src/test/java/com/keeper/homepage/domain/post/dao/PostRepositoryTest.java index a32ef2ab9..1760b4410 100644 --- a/src/test/java/com/keeper/homepage/domain/post/dao/PostRepositoryTest.java +++ b/src/test/java/com/keeper/homepage/domain/post/dao/PostRepositoryTest.java @@ -1,5 +1,7 @@ package com.keeper.homepage.domain.post.dao; +import static com.keeper.homepage.domain.post.entity.category.Category.CategoryType.자유게시판; +import static com.keeper.homepage.domain.post.entity.category.Category.getCategoryBy; import static org.assertj.core.api.Assertions.assertThat; import com.keeper.homepage.IntegrationTest; @@ -117,7 +119,7 @@ void should_processDefault_when_EmptyValue() { Post post = postRepository.save(Post.builder() .title("게시글 제목") .content("게시글 내용") - .category(categoryTestHelper.generate()) + .category(getCategoryBy(자유게시판)) .ipAddress(WebUtil.getUserIP()) .member(member) .build()