From 015552b53390c9ebf4fc2565c6015b44adb1d61d Mon Sep 17 00:00:00 2001 From: dongyeon1031 Date: Mon, 7 Oct 2024 18:48:31 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EB=B0=8F=20=EB=8C=93=EA=B8=80=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EB=B0=8F=20EntityType=20Enum=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/CampusNoticeRegisterRequest.java | 4 +- .../comment/controller/CommentController.java | 20 ++-- .../comment/dto/CommentRegisterRequest.java | 8 ++ .../domain/comment/entity/Comment.java | 13 ++- .../domain/comment/enums/EntityType.java | 20 ---- .../comment/repository/CommentRepository.java | 4 + .../comment/service/CommentService.java | 1 - .../comment/service/CommentServiceImpl.java | 98 ++++++++++++------- .../event/service/EventServiceImpl.java | 10 +- .../domain/faq/service/FAQServiceImpl.java | 8 +- .../like/controller/LikeController.java | 10 +- .../domain/like/dto/LikeRegisterRequest.java | 9 +- .../Key/{NoticeLikeId.java => LikeId.java} | 11 ++- .../bigbrotherbe/domain/like/entity/Like.java | 36 +++++++ .../domain/like/entity/NoticeLike.java | 63 ------------ .../like/repository/LikeRepository.java | 7 +- .../domain/like/service/LikeServiceImpl.java | 50 +++++----- .../meetings/service/MeetingsServiceImpl.java | 10 +- .../notice/service/NoticeServiceImpl.java | 10 +- .../domain/rule/service/RuleServiceImpl.java | 10 +- .../service/TransactionsServiceImpl.java | 6 +- .../global/common/constant/Constant.java | 11 +++ .../global/common/enums/EntityType.java | 46 +++++++++ .../common/exception/enums/ErrorCode.java | 10 +- .../global/file/enums/FileType.java | 21 ---- 25 files changed, 279 insertions(+), 217 deletions(-) delete mode 100644 src/main/java/com/example/bigbrotherbe/domain/comment/enums/EntityType.java rename src/main/java/com/example/bigbrotherbe/domain/like/entity/Key/{NoticeLikeId.java => LikeId.java} (51%) create mode 100644 src/main/java/com/example/bigbrotherbe/domain/like/entity/Like.java delete mode 100644 src/main/java/com/example/bigbrotherbe/domain/like/entity/NoticeLike.java create mode 100644 src/main/java/com/example/bigbrotherbe/global/common/enums/EntityType.java delete mode 100644 src/main/java/com/example/bigbrotherbe/global/file/enums/FileType.java diff --git a/src/main/java/com/example/bigbrotherbe/domain/campusNotice/dto/CampusNoticeRegisterRequest.java b/src/main/java/com/example/bigbrotherbe/domain/campusNotice/dto/CampusNoticeRegisterRequest.java index 4e78bda..6cc87f6 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/campusNotice/dto/CampusNoticeRegisterRequest.java +++ b/src/main/java/com/example/bigbrotherbe/domain/campusNotice/dto/CampusNoticeRegisterRequest.java @@ -5,7 +5,7 @@ import com.example.bigbrotherbe.domain.campusNotice.util.CampusNoticeMultipartFile; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.entity.File; -import com.example.bigbrotherbe.global.file.enums.FileType; +import com.example.bigbrotherbe.global.common.enums.EntityType; import com.example.bigbrotherbe.global.file.service.FileService; import lombok.*; import org.springframework.http.MediaType; @@ -37,7 +37,7 @@ public CampusNotice toCampusNoticeEntity(FileService fileService, CampusNoticeTy List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileSaveDTO fileSaveDTO = FileSaveDTO.builder() - .fileType(FileType.CAMPUS_NOTICE.getType()) + .fileType(EntityType.CAMPUS_NOTICE_TYPE.getType()) .multipartFileList(multipartFiles) .build(); diff --git a/src/main/java/com/example/bigbrotherbe/domain/comment/controller/CommentController.java b/src/main/java/com/example/bigbrotherbe/domain/comment/controller/CommentController.java index 51d22a5..c65bc62 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/comment/controller/CommentController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/comment/controller/CommentController.java @@ -4,12 +4,12 @@ import com.example.bigbrotherbe.domain.comment.dto.CommentReplyRequest; import com.example.bigbrotherbe.domain.comment.dto.CommentUpdateRequest; import com.example.bigbrotherbe.domain.comment.service.CommentService; -import com.example.bigbrotherbe.global.exception.response.ApiResponse; +import com.example.bigbrotherbe.global.common.exception.response.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import static com.example.bigbrotherbe.global.exception.enums.SuccessCode.SUCCESS; +import static com.example.bigbrotherbe.global.common.exception.enums.SuccessCode.SUCCESS; @RestController @RequiredArgsConstructor @@ -17,21 +17,21 @@ public class CommentController { private final CommentService commentService; - @PostMapping("/comment") - public ResponseEntity> registerComment(@RequestPart(value = "commentRegisterRequest") CommentRegisterRequest commentRegisterRequest){ + @PostMapping() + public ResponseEntity> registerComment(@RequestBody CommentRegisterRequest commentRegisterRequest){ this.commentService.registerComment(commentRegisterRequest); return ResponseEntity.ok(ApiResponse.success(SUCCESS)); } - @PostMapping("/reply") - public ResponseEntity> registerReply(@RequestPart(value = "commentReplyRequest") CommentReplyRequest commentReplyRequest){ - this.commentService.registerReply(commentReplyRequest); - return ResponseEntity.ok(ApiResponse.success(SUCCESS)); - } +// @PostMapping("/reply") +// public ResponseEntity> registerReply(@RequestBody CommentReplyRequest commentReplyRequest){ +// this.commentService.registerReply(commentReplyRequest); +// return ResponseEntity.ok(ApiResponse.success(SUCCESS)); +// } @PutMapping("/{commentId}") public ResponseEntity> updateComment(@PathVariable("commentId") Long id, - @RequestPart(value = "commentUpdateRequest")CommentUpdateRequest commentUpdateRequest){ + @RequestBody CommentUpdateRequest commentUpdateRequest){ this.commentService.updateComment(id, commentUpdateRequest); return ResponseEntity.ok(ApiResponse.success(SUCCESS)); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/comment/dto/CommentRegisterRequest.java b/src/main/java/com/example/bigbrotherbe/domain/comment/dto/CommentRegisterRequest.java index 15ffc58..6095a96 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/comment/dto/CommentRegisterRequest.java +++ b/src/main/java/com/example/bigbrotherbe/domain/comment/dto/CommentRegisterRequest.java @@ -6,6 +6,7 @@ @Getter public class CommentRegisterRequest { + private Long parentId; private String content; private String entityType; private Long entityId; @@ -16,4 +17,11 @@ public Comment toCommentEntity(Member member){ .members(member) .build(); } + public Comment toCommentEntity(Member member, Comment parent){ + return Comment.builder() + .content(this.content) + .members(member) + .parent(parent) + .build(); + } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/comment/entity/Comment.java b/src/main/java/com/example/bigbrotherbe/domain/comment/entity/Comment.java index e072304..175d27d 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/comment/entity/Comment.java +++ b/src/main/java/com/example/bigbrotherbe/domain/comment/entity/Comment.java @@ -1,18 +1,21 @@ package com.example.bigbrotherbe.domain.comment.entity; -import com.example.bigbrotherbe.domain.BaseTimeEntity; import com.example.bigbrotherbe.domain.event.entity.Event; import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.notice.entity.Notice; +import com.example.bigbrotherbe.global.common.enums.EntityType; +import com.example.bigbrotherbe.global.entity.BaseTimeEntity; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.SQLDelete; @Entity @Getter @Builder @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) +@SQLDelete(sql = "UPDATE comment SET deleted = true WHERE comment_id = ?") public class Comment extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -22,6 +25,12 @@ public class Comment extends BaseTimeEntity { @Column(name = "content") private String content; + @Enumerated // enum type 명시 + private EntityType entityType; + + @Column(nullable = false) + private boolean deleted = Boolean.FALSE; + @JsonIgnore @ManyToOne @JoinColumn(name = "parent_id") @@ -66,6 +75,8 @@ public void update(String content) { this.content = content; } + public void setEntityType(EntityType entityType){this.entityType = entityType;} + public void linkNotice(Notice notice) { this.notice = notice; } diff --git a/src/main/java/com/example/bigbrotherbe/domain/comment/enums/EntityType.java b/src/main/java/com/example/bigbrotherbe/domain/comment/enums/EntityType.java deleted file mode 100644 index 524ae9f..0000000 --- a/src/main/java/com/example/bigbrotherbe/domain/comment/enums/EntityType.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.example.bigbrotherbe.domain.comment.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum EntityType { - NOTICE(1, "notice"), - FAQ(2, "faq"), - MEETINGS(3, "meetings"), - EVENT(4, "event"), - RULE(5, "rule"), - AFFILIATION(6, "affiliation"), - CAMPUS_NOTICE(7, "campusNotice"), - TRANSACTIONS(8, "transactions"); - - private final int val; - private final String type; -} diff --git a/src/main/java/com/example/bigbrotherbe/domain/comment/repository/CommentRepository.java b/src/main/java/com/example/bigbrotherbe/domain/comment/repository/CommentRepository.java index 77a42ce..2db2461 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/comment/repository/CommentRepository.java +++ b/src/main/java/com/example/bigbrotherbe/domain/comment/repository/CommentRepository.java @@ -1,7 +1,11 @@ package com.example.bigbrotherbe.domain.comment.repository; import com.example.bigbrotherbe.domain.comment.entity.Comment; +import io.lettuce.core.dynamic.annotation.Param; +import jakarta.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; public interface CommentRepository extends JpaRepository { } diff --git a/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentService.java b/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentService.java index d9675c6..20ce19c 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentService.java @@ -6,7 +6,6 @@ public interface CommentService { public void registerComment(CommentRegisterRequest commentRegisterRequest); - public void registerReply(CommentReplyRequest commentReplyRequest); public void updateComment(Long id, CommentUpdateRequest commentUpdateRequest); public void deleteComment(Long id); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentServiceImpl.java index cb8e974..55e511f 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentServiceImpl.java @@ -1,21 +1,20 @@ package com.example.bigbrotherbe.domain.comment.service; import com.example.bigbrotherbe.domain.comment.dto.CommentRegisterRequest; -import com.example.bigbrotherbe.domain.comment.dto.CommentReplyRequest; import com.example.bigbrotherbe.domain.comment.dto.CommentUpdateRequest; import com.example.bigbrotherbe.domain.comment.entity.Comment; -import com.example.bigbrotherbe.domain.comment.enums.EntityType; import com.example.bigbrotherbe.domain.comment.repository.CommentRepository; import com.example.bigbrotherbe.domain.event.repository.EventRepository; import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.notice.repository.NoticeRepository; -import com.example.bigbrotherbe.global.exception.BusinessException; -import com.example.bigbrotherbe.global.jwt.component.AuthUtil; +import com.example.bigbrotherbe.global.auth.util.AuthUtil; +import com.example.bigbrotherbe.global.common.constant.Constant; +import com.example.bigbrotherbe.global.common.enums.EntityType; +import com.example.bigbrotherbe.global.common.exception.BusinessException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.NOT_FOUNT_ENTITY; -import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.NO_EXIST_COMMENT; +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.*; @Service @RequiredArgsConstructor @@ -29,21 +28,19 @@ public class CommentServiceImpl implements CommentService{ @Override public void registerComment(CommentRegisterRequest commentRegisterRequest) { Member member = authUtil.getLoginMember(); - - Comment comment = commentRegisterRequest.toCommentEntity(member); - this.setCommentEntity(comment, commentRegisterRequest.getEntityType(), commentRegisterRequest.getEntityId()); - - commentRepository.save(comment); - } - - @Override - public void registerReply(CommentReplyRequest commentReplyRequest) { - Member member = authUtil.getLoginMember(); - Comment parentComment = commentRepository.findById(commentReplyRequest.getParentId()) - .orElseThrow(() -> new BusinessException(NO_EXIST_COMMENT)); - - Comment comment = commentReplyRequest.toCommentEntity(member, parentComment); - this.setCommentEntity(comment, parentComment); + Comment comment; + if (commentRegisterRequest.getParentId() != null){ + Comment parentComment = commentRepository.findById(commentRegisterRequest.getParentId()) + .orElseThrow(() -> new BusinessException(NO_EXIST_COMMENT)); + if (parentComment.isDeleted()){ + throw new BusinessException(NO_EXIST_COMMENT); + } + comment = commentRegisterRequest.toCommentEntity(member, parentComment); + this.setCommentEntity(comment, parentComment); + }else{ + comment = commentRegisterRequest.toCommentEntity(member); + this.setCommentEntity(comment, commentRegisterRequest.getEntityType(), commentRegisterRequest.getEntityId()); + } commentRepository.save(comment); } @@ -52,6 +49,13 @@ public void registerReply(CommentReplyRequest commentReplyRequest) { public void updateComment(Long id, CommentUpdateRequest commentUpdateRequest) { Comment comment = commentRepository.findById(id) .orElseThrow(() -> new BusinessException(NO_EXIST_COMMENT)); + + if (!comment.getMembers().equals(authUtil.getLoginMember())){ + throw new BusinessException(NOT_REGISTER_MEMBER); + } + if (comment.isDeleted()){ + throw new BusinessException(NO_EXIST_COMMENT); + } comment.update(commentUpdateRequest.getContent()); commentRepository.save(comment); } @@ -61,6 +65,12 @@ public void deleteComment(Long id) { Comment comment = commentRepository.findById(id) .orElseThrow(() -> new BusinessException(NO_EXIST_COMMENT)); + if (!comment.getMembers().equals(authUtil.getLoginMember())){ + throw new BusinessException(NOT_REGISTER_MEMBER); + } + if (comment.isDeleted()){ + throw new BusinessException(NO_EXIST_COMMENT); + } commentRepository.delete(comment); } @@ -68,27 +78,43 @@ private void setCommentEntity(Comment comment, String entityType, Long entityId) /* comment와 관계를 맺은 entity 연결 */ - if (entityType.equals(EntityType.NOTICE.getType())){ - comment.linkNotice(noticeRepository.findById(entityId) - .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY))); - }else if(entityType.equals(EntityType.EVENT.getType())){ - comment.linkEvent(this.eventRepository.findById(entityId) - .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY))); - }else { - throw new BusinessException(NOT_FOUNT_ENTITY); + EntityType type; + switch (entityType){ + case Constant.Entity.NOTICE: + comment.linkNotice(noticeRepository.findById(entityId) + .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY))); + type = EntityType.NOTICE_TYPE; + break; + case Constant.Entity.EVENT: + comment.linkEvent(this.eventRepository.findById(entityId) + .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY))); + type = EntityType.EVENT_TYPE; + break; + default: + throw new BusinessException(NOT_FOUNT_ENTITY); } + this.setCommentEntityType(comment, type); } private void setCommentEntity(Comment comment, Comment parent){ /* - 부모 comment외 관계를 맺은 entity 연결 + 부모 comment와 관계를 맺은 entity 연결 */ - if(parent.getNotice() != null){ - comment.linkNotice(parent.getNotice()); - }else if(parent.getEvent() != null){ - comment.linkEvent(parent.getEvent()); - }else{ - throw new BusinessException(NOT_FOUNT_ENTITY); + EntityType type = EntityType.getEntityType(parent.getEntityType().getType()); + switch (parent.getEntityType().getType()){ + case Constant.Entity.NOTICE: + comment.linkNotice(parent.getNotice()); + break; + case Constant.Entity.EVENT: + comment.linkEvent(parent.getEvent()); + break; + default: + throw new BusinessException(NOT_FOUNT_ENTITY); } + this.setCommentEntityType(comment, type); + } + + private void setCommentEntityType(Comment comment, EntityType entityType){ + comment.setEntityType(entityType); } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java index 716f590..707531f 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java @@ -13,7 +13,7 @@ import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO; import com.example.bigbrotherbe.global.file.entity.File; -import com.example.bigbrotherbe.global.file.enums.FileType; +import com.example.bigbrotherbe.global.common.enums.EntityType; import com.example.bigbrotherbe.global.file.service.FileService; import com.example.bigbrotherbe.global.file.util.FileUtil; import com.example.bigbrotherbe.global.auth.util.AuthUtil; @@ -26,6 +26,8 @@ import java.util.List; +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.*; + @Service @RequiredArgsConstructor public class EventServiceImpl implements EventService { @@ -54,7 +56,7 @@ public void registerEvent(EventRegisterRequest eventRegisterRequest, List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileSaveDTO fileSaveDTO = FileSaveDTO.builder() - .fileType(FileType.EVENT.getType()) + .fileType(EntityType.EVENT_TYPE.getType()) .multipartFileList(multipartFiles) .build(); @@ -86,7 +88,7 @@ public void updateEvent(Long eventId, EventUpdateRequest eventUpdateRequest, Lis List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileUpdateDTO fileUpdateDTO = FileUpdateDTO.builder() - .fileType(FileType.EVENT.getType()) + .fileType(EntityType.EVENT_TYPE.getType()) .multipartFileList(multipartFiles) .files(event.getFiles()) .build(); @@ -113,7 +115,7 @@ public void deleteEvent(Long eventId) { } FileDeleteDTO fileDeleteDTO = FileDeleteDTO.builder() - .fileType(FileType.EVENT.getType()) + .fileType(EntityType.EVENT_TYPE.getType()) .files(event.getFiles()) .build(); diff --git a/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java index fc4dce7..154d844 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java @@ -12,7 +12,7 @@ import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO; import com.example.bigbrotherbe.global.file.entity.File; -import com.example.bigbrotherbe.global.file.enums.FileType; +import com.example.bigbrotherbe.global.common.enums.EntityType; import com.example.bigbrotherbe.global.file.service.FileService; import com.example.bigbrotherbe.global.auth.util.AuthUtil; import lombok.RequiredArgsConstructor; @@ -24,6 +24,8 @@ import java.util.List; +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.*; + @Service @RequiredArgsConstructor public class FAQServiceImpl implements FAQService { @@ -48,7 +50,7 @@ public void register(FAQRegisterRequest faqRegisterRequest, List List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileSaveDTO fileSaveDTO = FileSaveDTO.builder() - .fileType(FileType.FAQ.getType()) + .fileType(EntityType.FAQ_TYPE.getType()) .multipartFileList(multipartFiles) .build(); @@ -78,7 +80,7 @@ public void modify(Long faqId, FAQModifyRequest faqModifyRequest, List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileUpdateDTO fileUpdateDTO = FileUpdateDTO.builder() - .fileType(FileType.FAQ.getType()) + .fileType(EntityType.FAQ_TYPE.getType()) .multipartFileList(multipartFiles) .files(faq.getFiles()) .build(); diff --git a/src/main/java/com/example/bigbrotherbe/domain/like/controller/LikeController.java b/src/main/java/com/example/bigbrotherbe/domain/like/controller/LikeController.java index b6c8bf6..c4f0512 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/like/controller/LikeController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/like/controller/LikeController.java @@ -1,15 +1,15 @@ package com.example.bigbrotherbe.domain.like.controller; -import com.example.bigbrotherbe.domain.comment.dto.CommentRegisterRequest; import com.example.bigbrotherbe.domain.like.dto.LikeDeleteRequest; import com.example.bigbrotherbe.domain.like.dto.LikeRegisterRequest; import com.example.bigbrotherbe.domain.like.service.LikeService; -import com.example.bigbrotherbe.global.exception.response.ApiResponse; +import com.example.bigbrotherbe.global.common.exception.response.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import static com.example.bigbrotherbe.global.exception.enums.SuccessCode.SUCCESS; +import static com.example.bigbrotherbe.global.common.exception.enums.SuccessCode.SUCCESS; + @RestController @RequiredArgsConstructor @@ -18,13 +18,13 @@ public class LikeController { private final LikeService likeService; @PostMapping() - public ResponseEntity> registerComment(@RequestPart(value = "likeRegisterRequest") LikeRegisterRequest likeRegisterRequest){ + public ResponseEntity> registerComment(@RequestBody LikeRegisterRequest likeRegisterRequest){ this.likeService.registerLike(likeRegisterRequest); return ResponseEntity.ok(ApiResponse.success(SUCCESS)); } @DeleteMapping() - public ResponseEntity> deleteComment(@RequestPart(value = "likeDeleteRequest") LikeDeleteRequest likeDeleteRequest) { + public ResponseEntity> deleteComment(@RequestBody LikeDeleteRequest likeDeleteRequest) { this.likeService.deleteLike(likeDeleteRequest); return ResponseEntity.ok(ApiResponse.success(SUCCESS)); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/like/dto/LikeRegisterRequest.java b/src/main/java/com/example/bigbrotherbe/domain/like/dto/LikeRegisterRequest.java index d39e739..6361abc 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/like/dto/LikeRegisterRequest.java +++ b/src/main/java/com/example/bigbrotherbe/domain/like/dto/LikeRegisterRequest.java @@ -1,7 +1,8 @@ package com.example.bigbrotherbe.domain.like.dto; -import com.example.bigbrotherbe.domain.like.entity.NoticeLike; +import com.example.bigbrotherbe.domain.like.entity.Like; import com.example.bigbrotherbe.domain.member.entity.Member; +import com.example.bigbrotherbe.global.common.enums.EntityType; import lombok.Getter; @Getter @@ -9,9 +10,11 @@ public class LikeRegisterRequest { private String entityType; private Long entityId; - public NoticeLike toLikeEntity(Member member){ - return NoticeLike.builder() + public Like toLikeEntity(Member member){ + return Like.builder() .member(member) + .entityType(EntityType.getEntityType(this.entityType)) + .entityId(this.entityId) .build(); } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/like/entity/Key/NoticeLikeId.java b/src/main/java/com/example/bigbrotherbe/domain/like/entity/Key/LikeId.java similarity index 51% rename from src/main/java/com/example/bigbrotherbe/domain/like/entity/Key/NoticeLikeId.java rename to src/main/java/com/example/bigbrotherbe/domain/like/entity/Key/LikeId.java index 854cd1b..9918966 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/like/entity/Key/NoticeLikeId.java +++ b/src/main/java/com/example/bigbrotherbe/domain/like/entity/Key/LikeId.java @@ -2,7 +2,11 @@ import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.notice.entity.Notice; -import lombok.*; +import com.example.bigbrotherbe.global.common.enums.EntityType; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; import java.io.Serializable; @@ -10,7 +14,8 @@ @NoArgsConstructor @Getter @EqualsAndHashCode -public class NoticeLikeId implements Serializable { +public class LikeId implements Serializable { private Member member; - private Notice notice; + private Long entityId; + private EntityType entityType; } diff --git a/src/main/java/com/example/bigbrotherbe/domain/like/entity/Like.java b/src/main/java/com/example/bigbrotherbe/domain/like/entity/Like.java new file mode 100644 index 0000000..6eddf53 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/domain/like/entity/Like.java @@ -0,0 +1,36 @@ +package com.example.bigbrotherbe.domain.like.entity; + + +import com.example.bigbrotherbe.domain.campusNotice.entity.CampusNotice; +import com.example.bigbrotherbe.domain.event.entity.Event; +import com.example.bigbrotherbe.domain.faq.entity.FAQ; +import com.example.bigbrotherbe.domain.like.entity.Key.LikeId; +import com.example.bigbrotherbe.domain.meetings.entity.Meetings; +import com.example.bigbrotherbe.domain.member.entity.Member; +import com.example.bigbrotherbe.domain.notice.entity.Notice; +import com.example.bigbrotherbe.domain.rule.entity.Rule; +import com.example.bigbrotherbe.global.common.enums.EntityType; +import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@IdClass(LikeId.class) +@Table(name = "likes") +public class Like { + @Id + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @Id + private Long entityId; + + @Id + @Enumerated + private EntityType entityType; +} diff --git a/src/main/java/com/example/bigbrotherbe/domain/like/entity/NoticeLike.java b/src/main/java/com/example/bigbrotherbe/domain/like/entity/NoticeLike.java deleted file mode 100644 index eee6150..0000000 --- a/src/main/java/com/example/bigbrotherbe/domain/like/entity/NoticeLike.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.example.bigbrotherbe.domain.like.entity; - -import com.example.bigbrotherbe.domain.like.entity.Key.NoticeLikeId; -import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.notice.entity.Notice; -import com.fasterxml.jackson.annotation.JsonIgnore; -import jakarta.persistence.*; -import lombok.*; - -@Entity -@Getter -@Builder -@AllArgsConstructor -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@IdClass(NoticeLikeId.class) -@Table(name = "likes") -public class NoticeLike { - @Id - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id") - private Member member; - - @Id - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "notice_id") - @JsonIgnore - private Notice notice; - -// @Id -// @ManyToOne(fetch = FetchType.EAGER) -// @JoinColumn(name = "meetings_id", nullable = true) -// @JsonIgnore -// private Meetings meetings; -// -// @Id -// @ManyToOne(fetch = FetchType.EAGER) -// @JoinColumn(name = "faq_id", nullable = true) -// @JsonIgnore -// private FAQ faq; -// -// @Id -// @ManyToOne(fetch = FetchType.EAGER) -// @JoinColumn(name = "event_id", nullable = true) -// @JsonIgnore -// private Event event; -// -// @Id -// @ManyToOne(fetch = FetchType.EAGER) -// @JoinColumn(name = "rule_id", nullable = true) -// @JsonIgnore -// private Rule rule; -// -// @Id -// @ManyToOne(fetch = FetchType.EAGER) -// @JoinColumn(name = "campus_notice_id", nullable = true) -// @JsonIgnore -// private CampusNotice campusNotice; - - public void linkNotice(Notice notice) { - this.notice = notice; - } - -} diff --git a/src/main/java/com/example/bigbrotherbe/domain/like/repository/LikeRepository.java b/src/main/java/com/example/bigbrotherbe/domain/like/repository/LikeRepository.java index 2323384..fa2bb82 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/like/repository/LikeRepository.java +++ b/src/main/java/com/example/bigbrotherbe/domain/like/repository/LikeRepository.java @@ -1,9 +1,8 @@ package com.example.bigbrotherbe.domain.like.repository; -import com.example.bigbrotherbe.domain.like.entity.Key.NoticeLikeId; -import com.example.bigbrotherbe.domain.like.entity.NoticeLike; +import com.example.bigbrotherbe.domain.like.entity.Key.LikeId; +import com.example.bigbrotherbe.domain.like.entity.Like; import org.springframework.data.jpa.repository.JpaRepository; -public interface LikeRepository extends JpaRepository { - +public interface LikeRepository extends JpaRepository { } diff --git a/src/main/java/com/example/bigbrotherbe/domain/like/service/LikeServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/like/service/LikeServiceImpl.java index 03f6104..40005d7 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/like/service/LikeServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/like/service/LikeServiceImpl.java @@ -1,28 +1,32 @@ package com.example.bigbrotherbe.domain.like.service; -import com.example.bigbrotherbe.domain.comment.enums.EntityType; +import com.example.bigbrotherbe.domain.campusNotice.repository.CampusNoticeRepository; +import com.example.bigbrotherbe.domain.event.repository.EventRepository; +import com.example.bigbrotherbe.domain.faq.repository.FAQRepository; import com.example.bigbrotherbe.domain.like.dto.LikeDeleteRequest; import com.example.bigbrotherbe.domain.like.dto.LikeRegisterRequest; -import com.example.bigbrotherbe.domain.like.entity.Key.NoticeLikeId; -import com.example.bigbrotherbe.domain.like.entity.NoticeLike; +import com.example.bigbrotherbe.domain.like.entity.Key.LikeId; +import com.example.bigbrotherbe.domain.like.entity.Like; import com.example.bigbrotherbe.domain.like.repository.LikeRepository; +import com.example.bigbrotherbe.domain.meetings.repository.MeetingsRepository; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.notice.entity.Notice; import com.example.bigbrotherbe.domain.notice.repository.NoticeRepository; -import com.example.bigbrotherbe.global.exception.BusinessException; -import com.example.bigbrotherbe.global.jwt.component.AuthUtil; +import com.example.bigbrotherbe.domain.rule.repository.RuleRepository; +import com.example.bigbrotherbe.global.auth.util.AuthUtil; +import com.example.bigbrotherbe.global.common.enums.EntityType; +import com.example.bigbrotherbe.global.common.exception.BusinessException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.NOT_FOUNT_ENTITY; +import java.util.Optional; + +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.*; @Service @RequiredArgsConstructor public class LikeServiceImpl implements LikeService{ private final LikeRepository likeRepository; - private final NoticeRepository noticeRepository; - private final AuthUtil authUtil; @Override public void registerLike(LikeRegisterRequest likeRegisterRequest) { @@ -30,31 +34,25 @@ public void registerLike(LikeRegisterRequest likeRegisterRequest) { String entityType = likeRegisterRequest.getEntityType(); Long entityId = likeRegisterRequest.getEntityId(); - - if (entityType.equals(EntityType.NOTICE.getType())){ - NoticeLike noticeLike = likeRegisterRequest.toLikeEntity(member); - - noticeLike.linkNotice(noticeRepository.findById(entityId) - .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY))); - this.likeRepository.save(noticeLike); - - }else if(entityType.equals(EntityType.EVENT.getType())){ -// like.linkEvent(this.eventRepository.findById(entityId) -// .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY))); - }else { - throw new BusinessException(NOT_FOUNT_ENTITY); + if (this.likeRepository.existsById(new LikeId(member, entityId, EntityType.getEntityType(entityType)))){ + throw new BusinessException(ALREADY_EXIST_LIKE); } + + Like like = likeRegisterRequest.toLikeEntity(member); + this.likeRepository.save(like); } @Override public void deleteLike(LikeDeleteRequest likeDeleteRequest) { Member member = authUtil.getLoginMember(); - Notice notice = this.noticeRepository.findById(likeDeleteRequest.getEntityId()) - .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY)); - NoticeLike noticeLike = this.likeRepository.getReferenceById(new NoticeLikeId(member, notice)); + EntityType entityType = EntityType.getEntityType(likeDeleteRequest.getEntityType()); + Optional like = this.likeRepository.findById(new LikeId(member, likeDeleteRequest.getEntityId(), entityType)); + if (like.isEmpty()) { + throw new BusinessException(NO_EXIST_LIKE); + } - this.likeRepository.delete(noticeLike); + this.likeRepository.delete(like.get()); } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java index b890db2..bd1f031 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java @@ -13,7 +13,7 @@ import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO; import com.example.bigbrotherbe.global.file.entity.File; -import com.example.bigbrotherbe.global.file.enums.FileType; +import com.example.bigbrotherbe.global.common.enums.EntityType; import com.example.bigbrotherbe.global.file.service.FileService; import com.example.bigbrotherbe.global.file.util.FileUtil; import com.example.bigbrotherbe.global.auth.util.AuthUtil; @@ -26,6 +26,8 @@ import java.util.List; +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.*; + @Service @RequiredArgsConstructor public class MeetingsServiceImpl implements MeetingsService { @@ -53,7 +55,7 @@ public void registerMeetings(MeetingsRegisterRequest meetingsRegisterRequest, Li List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileSaveDTO fileSaveDTO = FileSaveDTO.builder() - .fileType(FileType.MEETINGS.getType()) + .fileType(EntityType.MEETINGS_TYPE.getType()) .multipartFileList(multipartFiles) .build(); @@ -85,7 +87,7 @@ public void updateMeetings(Long meetingsId, MeetingsUpdateRequest meetingsUpdate List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileUpdateDTO fileUpdateDTO = FileUpdateDTO.builder() - .fileType(FileType.MEETINGS.getType()) + .fileType(EntityType.MEETINGS_TYPE.getType()) .multipartFileList(multipartFiles) .files(meetings.getFiles()) .build(); @@ -103,7 +105,7 @@ public void deleteMeetings(Long meetingsId) { .orElseThrow(() -> new BusinessException(NO_EXIST_MEETINGS)); FileDeleteDTO fileDeleteDTO = FileDeleteDTO.builder() - .fileType(FileType.MEETINGS.getType()) + .fileType(EntityType.MEETINGS_TYPE.getType()) .files(meetings.getFiles()) .build(); diff --git a/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java index 0ce0c73..6ca8ee5 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java @@ -13,7 +13,7 @@ import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO; import com.example.bigbrotherbe.global.file.entity.File; -import com.example.bigbrotherbe.global.file.enums.FileType; +import com.example.bigbrotherbe.global.common.enums.EntityType; import com.example.bigbrotherbe.global.file.service.FileService; import com.example.bigbrotherbe.global.auth.util.AuthUtil; import lombok.RequiredArgsConstructor; @@ -25,6 +25,8 @@ import java.util.List; +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.*; + @Service @RequiredArgsConstructor public class NoticeServiceImpl implements NoticeService { @@ -50,7 +52,7 @@ public void register(NoticeRegisterRequest noticeRegisterRequest, List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileSaveDTO fileSaveDTO = FileSaveDTO.builder() - .fileType(FileType.NOTICE.getType()) + .fileType(EntityType.NOTICE_TYPE.getType()) .multipartFileList(multipartFiles) .build(); @@ -80,7 +82,7 @@ public void modify(Long noticeId, NoticeModifyRequest noticeModifyRequest, List< List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileUpdateDTO fileUpdateDTO = FileUpdateDTO.builder() - .fileType(FileType.NOTICE.getType()) + .fileType(EntityType.NOTICE_TYPE.getType()) .multipartFileList(multipartFiles) .files(notice.getFiles()) .build(); @@ -102,7 +104,7 @@ public void delete(Long noticeId) { } FileDeleteDTO fileDeleteDTO = FileDeleteDTO.builder() - .fileType(FileType.NOTICE.getType()) + .fileType(EntityType.NOTICE_TYPE.getType()) .files(notice.getFiles()) .build(); diff --git a/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java index 9ee38eb..10ff85c 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java @@ -13,7 +13,7 @@ import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO; import com.example.bigbrotherbe.global.file.entity.File; -import com.example.bigbrotherbe.global.file.enums.FileType; +import com.example.bigbrotherbe.global.common.enums.EntityType; import com.example.bigbrotherbe.global.file.service.FileService; import com.example.bigbrotherbe.global.file.util.FileUtil; import com.example.bigbrotherbe.global.auth.util.AuthUtil; @@ -26,6 +26,8 @@ import java.util.List; +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.*; + @Service @RequiredArgsConstructor public class RuleServiceImpl implements RuleService { @@ -54,7 +56,7 @@ public void registerRule(RuleRegisterRequest ruleRegisterRequest, List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileSaveDTO fileSaveDTO = FileSaveDTO.builder() - .fileType(FileType.RULE.getType()) + .fileType(EntityType.RULE_TYPE.getType()) .multipartFileList(multipartFiles) .build(); @@ -82,7 +84,7 @@ public void updateRule(Long ruleId, RuleUpdateRequest ruleUpdateRequest, List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { FileUpdateDTO fileUpdateDTO = FileUpdateDTO.builder() - .fileType(FileType.RULE.getType()) + .fileType(EntityType.RULE_TYPE.getType()) .multipartFileList(multipartFiles) .files(rule.getFiles()) .build(); @@ -100,7 +102,7 @@ public void deleteRule(Long ruleId) { .orElseThrow(() -> new BusinessException(NO_EXIST_RULE)); FileDeleteDTO fileDeleteDTO = FileDeleteDTO.builder() - .fileType(FileType.RULE.getType()) + .fileType(EntityType.RULE_TYPE.getType()) .files(rule.getFiles()) .build(); diff --git a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java index e5bf352..c75be27 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java @@ -9,7 +9,7 @@ import com.example.bigbrotherbe.global.common.exception.BusinessException; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.entity.File; -import com.example.bigbrotherbe.global.file.enums.FileType; +import com.example.bigbrotherbe.global.common.enums.EntityType; import com.example.bigbrotherbe.global.file.service.FileService; import com.example.bigbrotherbe.global.auth.util.AuthUtil; import com.example.bigbrotherbe.global.ocr.dto.OcrDto; @@ -26,6 +26,8 @@ import java.util.List; import java.util.stream.Collectors; +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.*; + @Service @RequiredArgsConstructor @@ -75,7 +77,7 @@ public void register(MultipartFile multipartFile, Long affiliationId) { // pdf 저장 FileSaveDTO fileSaveDTO = FileSaveDTO.builder() - .fileType(FileType.TRANSACTIONS.getType()) + .fileType(EntityType.TRANSACTIONS_TYPE.getType()) .multipartFile(multipartFile) .build(); diff --git a/src/main/java/com/example/bigbrotherbe/global/common/constant/Constant.java b/src/main/java/com/example/bigbrotherbe/global/common/constant/Constant.java index b374b24..fc079f3 100644 --- a/src/main/java/com/example/bigbrotherbe/global/common/constant/Constant.java +++ b/src/main/java/com/example/bigbrotherbe/global/common/constant/Constant.java @@ -18,4 +18,15 @@ public static class Cron{ public static class Url{ public static final String DOMAIN_URL = "https://api.mju-bigbrother.xyz"; } + + public static class Entity{ + public static final String NOTICE = "notice"; + public static final String FAQ = "faq"; + public static final String MEETINGS = "meetings"; + public static final String EVENT = "event"; + public static final String RULE = "rule"; + public static final String AFFILIATION = "affiliation"; + public static final String CAMPUS_NOTICE = "campusNotice"; + public static final String TRANSACTIONS = "transactions"; + } } diff --git a/src/main/java/com/example/bigbrotherbe/global/common/enums/EntityType.java b/src/main/java/com/example/bigbrotherbe/global/common/enums/EntityType.java new file mode 100644 index 0000000..8260414 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/global/common/enums/EntityType.java @@ -0,0 +1,46 @@ +package com.example.bigbrotherbe.global.common.enums; + +import com.example.bigbrotherbe.global.common.constant.Constant; +import com.example.bigbrotherbe.global.common.exception.BusinessException; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import static com.example.bigbrotherbe.global.common.exception.enums.ErrorCode.NO_ENTITY_TYPE; + +@Getter +@AllArgsConstructor +public enum EntityType { + NOTICE_TYPE(1, Constant.Entity.NOTICE), + FAQ_TYPE(2, Constant.Entity.FAQ), + MEETINGS_TYPE(3, Constant.Entity.MEETINGS), + EVENT_TYPE(4, Constant.Entity.EVENT), + RULE_TYPE(5, Constant.Entity.RULE), + AFFILIATION_TYPE(6, Constant.Entity.AFFILIATION), + CAMPUS_NOTICE_TYPE(7, Constant.Entity.CAMPUS_NOTICE), + TRANSACTIONS_TYPE(8, Constant.Entity.TRANSACTIONS); + + private final int val; + private final String type; + public static EntityType getEntityType(String entity){ + switch (entity){ + case Constant.Entity.NOTICE: + return NOTICE_TYPE; + case Constant.Entity.FAQ: + return FAQ_TYPE; + case Constant.Entity.MEETINGS: + return MEETINGS_TYPE; + case Constant.Entity.EVENT: + return EVENT_TYPE; + case Constant.Entity.RULE: + return RULE_TYPE; + case Constant.Entity.AFFILIATION: + return AFFILIATION_TYPE; + case Constant.Entity.CAMPUS_NOTICE: + return CAMPUS_NOTICE_TYPE; + case Constant.Entity.TRANSACTIONS: + return TRANSACTIONS_TYPE; + default: + throw new BusinessException(NO_ENTITY_TYPE); + } + } +} diff --git a/src/main/java/com/example/bigbrotherbe/global/common/exception/enums/ErrorCode.java b/src/main/java/com/example/bigbrotherbe/global/common/exception/enums/ErrorCode.java index 9274d2d..9ab8776 100644 --- a/src/main/java/com/example/bigbrotherbe/global/common/exception/enums/ErrorCode.java +++ b/src/main/java/com/example/bigbrotherbe/global/common/exception/enums/ErrorCode.java @@ -41,7 +41,15 @@ public enum ErrorCode { // Comment NO_EXIST_COMMENT(HttpStatus.NOT_FOUND, "COMMENT-001", "존재하지 않는 댓글 입니다."), - NOT_FOUNT_ENTITY(HttpStatus.NOT_FOUND, "COMMENT-002", "존재하지 않는 계시글 입니다."), + NOT_REGISTER_MEMBER(HttpStatus.BAD_REQUEST, "COMMENT-002", "댓글을 작성한 유저가 아닙니다."), + + // like + NO_EXIST_LIKE(HttpStatus.NOT_FOUND, "LIKE-001", "존재하지 않는 좋아요 입니다."), + ALREADY_EXIST_LIKE(HttpStatus.CONFLICT, "LIKE-002", "이미 존재하는 좋아요 입니다."), + + // Entity + NOT_FOUNT_ENTITY(HttpStatus.NOT_FOUND, "ENTITY-001", "존재하지 않는 게시글 입니다."), + NO_ENTITY_TYPE(HttpStatus.NOT_FOUND, "ENTITY-002", "존재하지 않는 게시글 타입 입니다."), // AFFILIATION NO_EXIST_AFFILIATION(HttpStatus.NOT_FOUND, "AFFILIATION-001", "존재하지 않는 소속 입니다."), diff --git a/src/main/java/com/example/bigbrotherbe/global/file/enums/FileType.java b/src/main/java/com/example/bigbrotherbe/global/file/enums/FileType.java deleted file mode 100644 index 14df40b..0000000 --- a/src/main/java/com/example/bigbrotherbe/global/file/enums/FileType.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.bigbrotherbe.global.file.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum FileType { - NOTICE(1, "notice"), - FAQ(2, "faq"), - MEETINGS(3, "meetings"), - EVENT(4, "event"), - RULE(5, "rule"), - AFFILIATION(6, "affiliation"), - CAMPUS_NOTICE(7, "campusNotice"), - TRANSACTIONS(8, "transactions"); - - private final int val; - private final String type; - -}