diff --git a/src/main/java/com/example/helloworldmvc/converter/CommentConverter.java b/src/main/java/com/example/helloworldmvc/converter/CommentConverter.java index 323cc43..9b66f5a 100644 --- a/src/main/java/com/example/helloworldmvc/converter/CommentConverter.java +++ b/src/main/java/com/example/helloworldmvc/converter/CommentConverter.java @@ -4,6 +4,7 @@ import com.example.helloworldmvc.domain.Community; import com.example.helloworldmvc.domain.User; import com.example.helloworldmvc.web.dto.CommentRequestDTO; +import com.example.helloworldmvc.web.dto.CommentResponseDTO; public class CommentConverter { @@ -15,4 +16,11 @@ public static Comment toComment(CommentRequestDTO.commentCreateReq request, Comm .content(request.getContent()) .build(); } + + public static CommentResponseDTO.commentCreateRes toCommentCreateRes(Long commentId, Long communityId) { + return CommentResponseDTO.commentCreateRes.builder() + .commentId(commentId) + .communityId(communityId) + .build(); + } } diff --git a/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java b/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java index 1e93b03..028ac79 100644 --- a/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java +++ b/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java @@ -127,6 +127,7 @@ public static CommunityResponseDTO.ModifyPostDTO toModifyPostDTO(Community commu return CommunityResponseDTO.ModifyPostDTO.builder() .title(community.getTitle()) .content(community.getContent()) + .communityCategory(community.getCommunityCategory()) .communityWriterEmail(community.getUser().getEmail()) .created_at(community.getCreatedAt()) .isOwner(isOwner) diff --git a/src/main/java/com/example/helloworldmvc/domain/Community.java b/src/main/java/com/example/helloworldmvc/domain/Community.java index b77f75c..12f74f9 100644 --- a/src/main/java/com/example/helloworldmvc/domain/Community.java +++ b/src/main/java/com/example/helloworldmvc/domain/Community.java @@ -55,5 +55,7 @@ public void setTitle(String title) { public void setContent(String content) { this.content = content; } - + public void setCommunityCategory(CommunityCategory communityCategory) { + this.communityCategory = communityCategory; + } } diff --git a/src/main/java/com/example/helloworldmvc/service/CommentServiceImpl.java b/src/main/java/com/example/helloworldmvc/service/CommentServiceImpl.java index 158762a..c0cc3fc 100644 --- a/src/main/java/com/example/helloworldmvc/service/CommentServiceImpl.java +++ b/src/main/java/com/example/helloworldmvc/service/CommentServiceImpl.java @@ -44,7 +44,7 @@ public CommentResponseDTO.commentCreateRes createComment(String userId, Long com Comment comment = CommentConverter.toComment(requestBody, community, user, anonymousNumber); Comment savedComment = commentRepository.save(comment); - return new CommentResponseDTO.commentCreateRes(savedComment.getId()); + return CommentConverter.toCommentCreateRes(savedComment.getId(), communityId); } @Override diff --git a/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java b/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java index c409738..c72bfea 100644 --- a/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java +++ b/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java @@ -100,6 +100,20 @@ public CommunityResponseDTO.ModifyPostDTO modifyCommunityPost(String userId, Lon if(community.getUser().getEmail().equals(user.getEmail())) { isOwner = true; } + switch (modifyPostDTO.getCommunityCategoryId()){ + case 1 : + community.setCommunityCategory(CommunityCategory.WORRY); + break; + case 2 : + community.setCommunityCategory(CommunityCategory.MEDICAL); + break; + case 3 : + community.setCommunityCategory(CommunityCategory.QUALIFICATION); + break; + default : + community.setCommunityCategory(CommunityCategory.ETC); + break; + } communityRepository.save(community); return CommunityConverter.toModifyPostDTO(community, isOwner); } diff --git a/src/main/java/com/example/helloworldmvc/web/dto/CommentResponseDTO.java b/src/main/java/com/example/helloworldmvc/web/dto/CommentResponseDTO.java index 2b2483b..ef8c76a 100644 --- a/src/main/java/com/example/helloworldmvc/web/dto/CommentResponseDTO.java +++ b/src/main/java/com/example/helloworldmvc/web/dto/CommentResponseDTO.java @@ -13,6 +13,7 @@ public class CommentResponseDTO { @AllArgsConstructor public static class commentCreateRes{ Long commentId; + Long communityId; } @Builder diff --git a/src/main/java/com/example/helloworldmvc/web/dto/CommunityRequestDTO.java b/src/main/java/com/example/helloworldmvc/web/dto/CommunityRequestDTO.java index 9759727..98bbc41 100644 --- a/src/main/java/com/example/helloworldmvc/web/dto/CommunityRequestDTO.java +++ b/src/main/java/com/example/helloworldmvc/web/dto/CommunityRequestDTO.java @@ -29,5 +29,7 @@ public static class ModifyPostDTO { @NotBlank String content; + + Integer communityCategoryId; } } diff --git a/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java b/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java index f4072a3..6363f76 100644 --- a/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java +++ b/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java @@ -1,5 +1,6 @@ package com.example.helloworldmvc.web.dto; +import com.example.helloworldmvc.domain.enums.CommunityCategory; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -80,6 +81,7 @@ public static class DeletedPostDTO{ public static class ModifyPostDTO{ String title; String content; + CommunityCategory communityCategory; String communityWriterEmail; LocalDateTime created_at; Boolean isOwner;