diff --git a/build.gradle b/build.gradle index 6fec3ab..eaf0668 100644 --- a/build.gradle +++ b/build.gradle @@ -81,7 +81,7 @@ dependencies { // implementation 'software.amazon.awssdk:http-client-netty:2.20.0' implementation 'software.amazon.awssdk:sagemakerruntime:2.20.92' implementation 'software.amazon.awssdk:sdk-core:2.20.92' - implementation 'software.amazon.awssdk:http-client-netty:2.20.92' +// implementation 'software.amazon.awssdk:http-client-netty:2.20.92' // OCR implementation 'org.apache.pdfbox:pdfbox:2.0.27' 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 c65bc62..1688a01 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 @@ -18,7 +18,7 @@ public class CommentController { private final CommentService commentService; @PostMapping() - public ResponseEntity> registerComment(@RequestBody CommentRegisterRequest commentRegisterRequest){ + public ResponseEntity> registerComment(@RequestBody CommentRegisterRequest commentRegisterRequest) { this.commentService.registerComment(commentRegisterRequest); return ResponseEntity.ok(ApiResponse.success(SUCCESS)); } @@ -31,7 +31,7 @@ public ResponseEntity> registerComment(@RequestBody CommentReg @PutMapping("/{commentId}") public ResponseEntity> updateComment(@PathVariable("commentId") Long id, - @RequestBody 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/entity/Comment.java b/src/main/java/com/example/bigbrotherbe/domain/comment/entity/Comment.java index 175d27d..91b4261 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 @@ -17,6 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @SQLDelete(sql = "UPDATE comment SET deleted = true WHERE comment_id = ?") public class Comment extends BaseTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "comment_id") @@ -75,7 +76,9 @@ public void update(String content) { this.content = content; } - public void setEntityType(EntityType entityType){this.entityType = entityType;} + 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/service/CommentServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/comment/service/CommentServiceImpl.java index 55e511f..0f54b96 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 @@ -3,6 +3,7 @@ import com.example.bigbrotherbe.domain.comment.dto.CommentRegisterRequest; import com.example.bigbrotherbe.domain.comment.dto.CommentUpdateRequest; import com.example.bigbrotherbe.domain.comment.entity.Comment; + import com.example.bigbrotherbe.domain.comment.repository.CommentRepository; import com.example.bigbrotherbe.domain.event.repository.EventRepository; import com.example.bigbrotherbe.domain.member.entity.Member; @@ -18,26 +19,27 @@ @Service @RequiredArgsConstructor -public class CommentServiceImpl implements CommentService{ +public class CommentServiceImpl implements CommentService { private final CommentRepository commentRepository; private final EventRepository eventRepository; private final NoticeRepository noticeRepository; private final AuthUtil authUtil; + @Override public void registerComment(CommentRegisterRequest commentRegisterRequest) { Member member = authUtil.getLoginMember(); Comment comment; - if (commentRegisterRequest.getParentId() != null){ + if (commentRegisterRequest.getParentId() != null) { Comment parentComment = commentRepository.findById(commentRegisterRequest.getParentId()) .orElseThrow(() -> new BusinessException(NO_EXIST_COMMENT)); - if (parentComment.isDeleted()){ + if (parentComment.isDeleted()) { throw new BusinessException(NO_EXIST_COMMENT); } comment = commentRegisterRequest.toCommentEntity(member, parentComment); this.setCommentEntity(comment, parentComment); - }else{ + } else { comment = commentRegisterRequest.toCommentEntity(member); this.setCommentEntity(comment, commentRegisterRequest.getEntityType(), commentRegisterRequest.getEntityId()); } @@ -50,10 +52,10 @@ public void updateComment(Long id, CommentUpdateRequest commentUpdateRequest) { Comment comment = commentRepository.findById(id) .orElseThrow(() -> new BusinessException(NO_EXIST_COMMENT)); - if (!comment.getMembers().equals(authUtil.getLoginMember())){ + if (!comment.getMembers().equals(authUtil.getLoginMember())) { throw new BusinessException(NOT_REGISTER_MEMBER); } - if (comment.isDeleted()){ + if (comment.isDeleted()) { throw new BusinessException(NO_EXIST_COMMENT); } comment.update(commentUpdateRequest.getContent()); @@ -65,21 +67,21 @@ public void deleteComment(Long id) { Comment comment = commentRepository.findById(id) .orElseThrow(() -> new BusinessException(NO_EXIST_COMMENT)); - if (!comment.getMembers().equals(authUtil.getLoginMember())){ + if (!comment.getMembers().equals(authUtil.getLoginMember())) { throw new BusinessException(NOT_REGISTER_MEMBER); } - if (comment.isDeleted()){ + if (comment.isDeleted()) { throw new BusinessException(NO_EXIST_COMMENT); } commentRepository.delete(comment); } - private void setCommentEntity(Comment comment, String entityType, Long entityId){ + private void setCommentEntity(Comment comment, String entityType, Long entityId) { /* comment와 관계를 맺은 entity 연결 */ EntityType type; - switch (entityType){ + switch (entityType) { case Constant.Entity.NOTICE: comment.linkNotice(noticeRepository.findById(entityId) .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY))); @@ -96,12 +98,12 @@ private void setCommentEntity(Comment comment, String entityType, Long entityId) this.setCommentEntityType(comment, type); } - private void setCommentEntity(Comment comment, Comment parent){ + private void setCommentEntity(Comment comment, Comment parent) { /* 부모 comment와 관계를 맺은 entity 연결 */ EntityType type = EntityType.getEntityType(parent.getEntityType().getType()); - switch (parent.getEntityType().getType()){ + switch (parent.getEntityType().getType()) { case Constant.Entity.NOTICE: comment.linkNotice(parent.getNotice()); break; @@ -114,7 +116,7 @@ private void setCommentEntity(Comment comment, Comment parent){ this.setCommentEntityType(comment, type); } - private void setCommentEntityType(Comment comment, EntityType entityType){ + private void setCommentEntityType(Comment comment, EntityType entityType) { comment.setEntityType(entityType); } } 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 c4f0512..6260a2e 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,5 +1,6 @@ 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; @@ -15,10 +16,11 @@ @RequiredArgsConstructor @RequestMapping("/api/v1/like") public class LikeController { + private final LikeService likeService; @PostMapping() - public ResponseEntity> registerComment(@RequestBody LikeRegisterRequest likeRegisterRequest){ + public ResponseEntity> registerComment(@RequestBody LikeRegisterRequest likeRegisterRequest) { this.likeService.registerLike(likeRegisterRequest); return ResponseEntity.ok(ApiResponse.success(SUCCESS)); } 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 index 6eddf53..fa53442 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/like/entity/Like.java +++ b/src/main/java/com/example/bigbrotherbe/domain/like/entity/Like.java @@ -22,6 +22,7 @@ @IdClass(LikeId.class) @Table(name = "likes") public class Like { + @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") 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 40005d7..c46be08 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 @@ -10,6 +10,7 @@ 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.domain.rule.repository.RuleRepository; import com.example.bigbrotherbe.global.auth.util.AuthUtil; @@ -24,17 +25,20 @@ @Service @RequiredArgsConstructor -public class LikeServiceImpl implements LikeService{ +public class LikeServiceImpl implements LikeService { + private final LikeRepository likeRepository; + private final NoticeRepository noticeRepository; private final AuthUtil authUtil; + @Override public void registerLike(LikeRegisterRequest likeRegisterRequest) { Member member = authUtil.getLoginMember(); String entityType = likeRegisterRequest.getEntityType(); Long entityId = likeRegisterRequest.getEntityId(); - if (this.likeRepository.existsById(new LikeId(member, entityId, EntityType.getEntityType(entityType)))){ + if (this.likeRepository.existsById(new LikeId(member, entityId, EntityType.getEntityType(entityType)))) { throw new BusinessException(ALREADY_EXIST_LIKE); } @@ -45,6 +49,8 @@ public void registerLike(LikeRegisterRequest likeRegisterRequest) { @Override public void deleteLike(LikeDeleteRequest likeDeleteRequest) { Member member = authUtil.getLoginMember(); + Notice notice = this.noticeRepository.findById(likeDeleteRequest.getEntityId()) + .orElseThrow(() -> new BusinessException(NOT_FOUNT_ENTITY)); EntityType entityType = EntityType.getEntityType(likeDeleteRequest.getEntityType()); Optional like = this.likeRepository.findById(new LikeId(member, likeDeleteRequest.getEntityId(), entityType)); 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 index 8260414..493a73a 100644 --- a/src/main/java/com/example/bigbrotherbe/global/common/enums/EntityType.java +++ b/src/main/java/com/example/bigbrotherbe/global/common/enums/EntityType.java @@ -21,8 +21,9 @@ public enum EntityType { private final int val; private final String type; - public static EntityType getEntityType(String entity){ - switch (entity){ + + public static EntityType getEntityType(String entity) { + switch (entity) { case Constant.Entity.NOTICE: return NOTICE_TYPE; case Constant.Entity.FAQ: