Skip to content

Commit

Permalink
Merge pull request #133 from TaetaetaE01/main
Browse files Browse the repository at this point in the history
[chore] : 줄 맞춤
  • Loading branch information
TaetaetaE01 authored Oct 8, 2024
2 parents 989d108 + 2bc76fb commit 7bed2ff
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CommentController {
private final CommentService commentService;

@PostMapping()
public ResponseEntity<ApiResponse<Void>> registerComment(@RequestBody CommentRegisterRequest commentRegisterRequest){
public ResponseEntity<ApiResponse<Void>> registerComment(@RequestBody CommentRegisterRequest commentRegisterRequest) {
this.commentService.registerComment(commentRegisterRequest);
return ResponseEntity.ok(ApiResponse.success(SUCCESS));
}
Expand All @@ -31,7 +31,7 @@ public ResponseEntity<ApiResponse<Void>> registerComment(@RequestBody CommentReg

@PutMapping("/{commentId}")
public ResponseEntity<ApiResponse<Void>> updateComment(@PathVariable("commentId") Long id,
@RequestBody CommentUpdateRequest commentUpdateRequest){
@RequestBody CommentUpdateRequest commentUpdateRequest) {
this.commentService.updateComment(id, commentUpdateRequest);
return ResponseEntity.ok(ApiResponse.success(SUCCESS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand All @@ -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());
Expand All @@ -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)));
Expand All @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,10 +16,11 @@
@RequiredArgsConstructor
@RequestMapping("/api/v1/like")
public class LikeController {

private final LikeService likeService;

@PostMapping()
public ResponseEntity<ApiResponse<Void>> registerComment(@RequestBody LikeRegisterRequest likeRegisterRequest){
public ResponseEntity<ApiResponse<Void>> registerComment(@RequestBody LikeRegisterRequest likeRegisterRequest) {
this.likeService.registerLike(likeRegisterRequest);
return ResponseEntity.ok(ApiResponse.success(SUCCESS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@IdClass(LikeId.class)
@Table(name = "likes")
public class Like {

@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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> like = this.likeRepository.findById(new LikeId(member, likeDeleteRequest.getEntityId(), entityType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7bed2ff

Please sign in to comment.