diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/controller/BoothController.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/controller/BoothController.java index a0e0b9c..df15d74 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/controller/BoothController.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/controller/BoothController.java @@ -9,6 +9,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; + @RestController @RequestMapping("api/v1/booth") @RequiredArgsConstructor @@ -35,14 +37,16 @@ public ResponseEntity getBooth( } @PatchMapping("{boothId}") - @Operation(summary = "특정 부스 좋아요 업데이트", description = "특정 부스의 좋아요를 +1 한다.") + @Operation(summary = "특정 부스 좋아요 업데이트", description = "특정 부스의 좋아요를 변경한다.") public ResponseEntity updateLikes( - @PathVariable("boothId") Long boothId + @PathVariable("boothId") Long boothId, + @RequestParam("userHash") String userHash ){ - service.updateLikes(boothId); + String message = service.updateLikes(boothId, userHash); BasicResponse response = BasicResponse.builder() - .message("좋아요를 성공적으로 업데이트(+1) 하였습니다.") + .message(message) .status(200) + .timeStamp(LocalDateTime.now()) .build(); return ResponseEntity.ok().body(response); } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java index 5b07d2f..34d2956 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java @@ -29,8 +29,8 @@ public class BoothEntity extends BasicEntity { @OneToMany(mappedBy = "booth", fetch = FetchType.LAZY) private List commentEntityList; - @OneToMany(mappedBy = "boothEntity", fetch = FetchType.LAZY) - private UserBoothEntity userBoothEntity; + @OneToMany(mappedBy = "booth", fetch = FetchType.LAZY) + private List userBoothEntity; @ElementCollection @CollectionTable( diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothService.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothService.java index 7c56400..c06f3df 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothService.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothService.java @@ -2,10 +2,13 @@ import LlikelionKNU.KNUfest.domain.booth.dto.AllBooth; import LlikelionKNU.KNUfest.domain.booth.dto.BoothDetail; +import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity; public interface BoothService { AllBooth getAllbooth(String userHash); BoothDetail getBooth(Long id, String userHash); - void updateLikes(Long id); + String updateLikes(Long id, String userHash); + + BoothEntity findById(Long id); } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java index 5a02557..bb11e85 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java @@ -7,9 +7,9 @@ import LlikelionKNU.KNUfest.domain.booth.repository.BoothRepository; import LlikelionKNU.KNUfest.domain.comment.service.CommentService; import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity; -import LlikelionKNU.KNUfest.domain.user.service.UserBoothService; +import LlikelionKNU.KNUfest.domain.user.entity.UserEntity; +import LlikelionKNU.KNUfest.domain.user.repository.UserBoothRepository; import LlikelionKNU.KNUfest.domain.user.service.UserService; -import LlikelionKNU.KNUfest.domain.user.service.UserServiceImpl; import LlikelionKNU.KNUfest.global.error.NoExistException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,8 +23,9 @@ public class BoothServiceImpl implements BoothService{ private final BoothRepository boothrepository; + private final UserBoothRepository userBoothRepository; + private final CommentService commentService; - private final UserBoothService userBoothService; private final UserService userService; @Override @@ -33,8 +34,7 @@ public AllBooth getAllbooth(String userHash) { List boothes = boothrepository.findAll(); List boothDtos; - List userBoothEntityList = userBoothService.getAllUserBooth( - userService.getUserByHash(userHash).getId()); + List userBoothEntityList = userBoothRepository.findAllByUserId(userService.getUserByHash(userHash).getId()); if(boothes.isEmpty()) { throw new NoExistException("부스 전체 정보가 없습니다."); @@ -49,12 +49,15 @@ public AllBooth getAllbooth(String userHash) { .build()); } - for(UserBoothEntity userBooth : userBoothEntityList){ - Booth tempbooth = boothDtos.get(userBooth.getBoothEntity().getId().intValue()); - tempbooth.setLikable(false); - boothDtos.set(userBooth.getBoothEntity().getId().intValue(), tempbooth); + if(!userBoothEntityList.isEmpty()){ + for(UserBoothEntity userBooth : userBoothEntityList){ + Booth tempbooth = boothDtos.get(userBooth.getBooth().getId().intValue()-1); + tempbooth.setLikable(false); + boothDtos.set(userBooth.getBooth().getId().intValue()-1, tempbooth); + } } + return AllBooth.builder() .count(boothDtos.size()) .boothDtoes(boothDtos) @@ -63,41 +66,83 @@ public AllBooth getAllbooth(String userHash) { } @Override - public BoothDetail getBooth(Long id, String userHash) { - Optional boothOp = boothrepository.findById(id); - - Optional userBoothEntity = userBoothService.getUserBooth(id, userService.getUserByHash(userHash).getId()); + public BoothDetail getBooth(Long boothId, String userHash) { + Optional boothOp; - boolean temp = userBoothEntity.isEmpty(); + Optional userBoothEntity = userBoothRepository.findByUserIdAndBoothId(userService.getUserByHash(userHash).getId(), boothId); + BoothEntity booth; - if(boothOp.isEmpty()){ - throw new NoExistException("해당 부스 정보가 없습니다. (id 확인요망)"); + boolean temp; + if(userBoothEntity.isEmpty()){ + boothOp = boothrepository.findById(boothId); + temp = true; + if(boothOp.isEmpty()){ + throw new NoExistException("해당 부스 정보가 없습니다. (id 확인요망)"); + }else{ + booth = boothOp.get(); + } }else{ - BoothEntity booth = boothOp.get(); - + temp = false; + booth = userBoothEntity.get().getBooth(); + } return BoothDetail.builder() .id(booth.getId()) .boothName(booth.getBoothName()) .likes(booth.getLikes()) .urls(booth.getUrls()) .Likable(temp) - .comments(commentService.getCommentPage(boothOp.get().getId(),5,1, "default")) + .comments(commentService.getCommentPage(booth.getId(),5,1, "default", userHash)) .build(); - } } @Override - public void updateLikes(Long id) { + public String updateLikes(Long boothId, String userHash) { + + UserEntity user = userService.getUserByHash(userHash); + Optional userBoothEntity = userBoothRepository.findByUserIdAndBoothId(user.getId(), boothId); + UserBoothEntity userBooth; - Optional boothOp = boothrepository.findById(id); BoothEntity booth; + if(userBoothEntity.isEmpty()){ + Optional boothOp = boothrepository.findById(boothId); + + if(boothOp.isEmpty()){ + throw new NoExistException("해당 부스 정보가 없습니다. (id 확인 요망)"); + }else{ + booth = boothOp.get(); + booth.setLikes(booth.getLikes()+1); + boothrepository.save(booth); + + userBooth = UserBoothEntity.builder() + .booth(booth) + .user(user) + .build(); + + userBoothRepository.save(userBooth); + return "좋아요를 업데이트(+1) 하였습니다."; + } + + + }else{ + booth = userBoothEntity.get().getBooth(); + booth.setLikes(booth.getLikes()-1); + boothrepository.save(booth); + + userBoothRepository.delete(userBoothEntity.get()); + + return "좋아요를 업데이트(-1) 하였습니다."; + } + + } + + @Override + public BoothEntity findById(Long id){ + Optional boothOp = boothrepository.findById(id); if(boothOp.isEmpty()){ throw new NoExistException("해당 부스 정보가 없습니다. (id 확인 요망)"); }else{ - booth = boothOp.get(); - booth.setLikes(booth.getLikes()+1); - boothrepository.save(booth); + return boothOp.get(); } } } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/comment/controller/CommentController.java b/src/main/java/LlikelionKNU/KNUfest/domain/comment/controller/CommentController.java index d4782bb..fe45286 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/controller/CommentController.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/controller/CommentController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.*; import java.net.URI; +import java.time.LocalDateTime; import java.util.List; @RestController @@ -23,9 +24,10 @@ public ResponseEntity> getExtraCommentPage( @PathVariable("boothId") Long boothId, @RequestParam("perpage") int perpage, @RequestParam("page") int page, - @RequestParam("order") String order + @RequestParam("order") String order, + @RequestParam("userHash") String userHash ){ - List result = service.getCommentPage(boothId, perpage, page, order); + List result = service.getCommentPage(boothId, perpage, page, order, userHash); return ResponseEntity.ok().body(result); } @@ -33,31 +35,33 @@ public ResponseEntity> getExtraCommentPage( @Operation(summary = "특정부스 댓글 생성", description = "특정 부스에 댓글을 생성한다.") public ResponseEntity postComment( @PathVariable("boothId") Long boothId, - @RequestBody CommentRequest comment + @RequestParam("userHash") String userHash, + @RequestBody CommentRequest commentRequest ){ - Long id = service.postComment(boothId, comment); + Long id = service.postComment(boothId, commentRequest, userHash); BasicResponse response = BasicResponse.builder() - .message(boothId+"번 부스에 댓글을 생성하였습니다.") + .message(boothId+"번 부스에 " + id + "번째 댓글을 생성하였습니다.") .status(201) + .timeStamp(LocalDateTime.now()) .build(); return ResponseEntity.created(URI.create("comment"+id)).body(response); } @DeleteMapping("comment/{commentId}") - @Operation(summary = "특정 댓글 삭제", description = "특정 댓글을 password 가 일치할 경우 삭제한다.") + @Operation(summary = "특정 댓글 삭제", description = "특정 댓글을 userHash 값을 통해 비교하여 삭제한다.") public ResponseEntity deleteComment( @PathVariable("commentId") Long commentId, - @RequestParam("password") String password + @RequestParam("userHash") String userHash ){ - - service.deleteComment(commentId, password); + service.deleteComment(commentId, userHash); BasicResponse basicResponse = BasicResponse.builder() .message("성공적으로 삭제되었습니다.") .status(200) + .timeStamp(LocalDateTime.now()) .build(); return ResponseEntity.ok().body(basicResponse); diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/Comment.java b/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/Comment.java index d9573c2..ba5e07c 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/Comment.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/Comment.java @@ -2,10 +2,12 @@ import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity; import LlikelionKNU.KNUfest.domain.comment.entity.CommentEntity; +import LlikelionKNU.KNUfest.domain.user.entity.UserEntity; import lombok.Builder; import lombok.Data; import java.time.Instant; +import java.time.LocalDateTime; @Data @Builder @@ -13,15 +15,15 @@ public class Comment { private Long id; private String name; private String comment; - private String password; - private Instant created; + private LocalDateTime created; + private Boolean deleteable; - public CommentEntity toEntity(BoothEntity booth){ + public static CommentEntity toEntity(CommentRequest commentRequest, BoothEntity booth, UserEntity user){ return CommentEntity.builder() - .name(this.name) - .password(this.password) - .comment(this.comment) + .name(commentRequest.getName()) + .comment(commentRequest.getComment()) .booth(booth) + .user(user) .build(); } } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/CommentRequest.java b/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/CommentRequest.java index ddb11fd..bbf3dcc 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/CommentRequest.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/CommentRequest.java @@ -8,5 +8,4 @@ public class CommentRequest { private String name; private String comment; - private String password; } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/comment/entity/CommentEntity.java b/src/main/java/LlikelionKNU/KNUfest/domain/comment/entity/CommentEntity.java index 884d1e1..ef38bfb 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/entity/CommentEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/entity/CommentEntity.java @@ -3,6 +3,7 @@ import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity; import LlikelionKNU.KNUfest.domain.comment.dto.Comment; +import LlikelionKNU.KNUfest.domain.user.entity.UserEntity; import LlikelionKNU.KNUfest.global.basic.BasicEntity; import jakarta.persistence.*; import lombok.*; @@ -23,18 +24,18 @@ public class CommentEntity extends BasicEntity { @Column(name = "comment") private String comment; - @Column(name = "password", length = 10) - private String password; - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "booth_id") + @JoinColumn(name = "boothId") private BoothEntity booth; + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "userId") + private UserEntity user; + public Comment toDto(){ return Comment.builder() .id(this.getId()) .name(this.name) - .password(this.password) .comment(this.comment) .created(this.getCreatedAt()) .build(); diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentService.java b/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentService.java index e112c3f..adf4178 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentService.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentService.java @@ -6,8 +6,8 @@ import java.util.List; public interface CommentService { - List getCommentPage(Long boothId, int perpage, int page, String order); - Long postComment(Long id, CommentRequest comment); + List getCommentPage(Long boothId, int perpage, int page, String order, String userHash); + Long postComment(Long id, CommentRequest comment, String userHash); void deleteComment(Long commentId, String password); } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentServiceImpl.java b/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentServiceImpl.java index 3dbbd2b..5ede49c 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentServiceImpl.java @@ -6,8 +6,10 @@ import LlikelionKNU.KNUfest.domain.comment.dto.CommentRequest; import LlikelionKNU.KNUfest.domain.comment.entity.CommentEntity; import LlikelionKNU.KNUfest.domain.comment.repository.CommentRepository; +import LlikelionKNU.KNUfest.domain.user.entity.UserEntity; +import LlikelionKNU.KNUfest.domain.user.service.UserService; import LlikelionKNU.KNUfest.global.error.NoExistException; -import LlikelionKNU.KNUfest.global.error.PasswordWrongException; +import LlikelionKNU.KNUfest.global.error.UserHashWrongException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,64 +21,77 @@ @RequiredArgsConstructor public class CommentServiceImpl implements CommentService{ private final CommentRepository commentRepository; + private final BoothRepository boothRepository; + private final UserService userService; + + @Override - public List getCommentPage(Long boothId, int perpage, int page, String order) { + public List getCommentPage(Long boothId, int perpage, int page, String order, String userHash) { Optional boothOp = boothRepository.findById(boothId); - List comments; - List result; - + BoothEntity booth; if(boothOp.isEmpty()){ - throw new NoExistException("댓글을 불러올 부스 정보가 없습니다. (id 확인 요망)"); + throw new NoExistException("해당 부스 정보가 없습니다. (id 확인 요망)"); }else{ - result = new ArrayList<>(); + booth = boothOp.get(); + } - int offset = (page-1) * perpage; + List comments; + List result = new ArrayList<>(); - if(order.equals("desc")){ - comments = commentRepository.findAllOrderByIdDESC(boothId, perpage, offset); - }else{ - comments = commentRepository.findAllOrderById(boothId, perpage, offset); - } - for(CommentEntity c: comments){ - result.add(c.toDto()); + int offset = (page-1) * perpage; + + if(order.equals("desc")){ + comments = commentRepository.findAllOrderByIdDESC(booth.getId(), perpage, offset); + }else{ + comments = commentRepository.findAllOrderById(booth.getId(), perpage, offset); + } + + if(!comments.isEmpty()) { + for (CommentEntity c : comments) { + Comment comment = c.toDto(); + if (c.getUser().getUserHash().equals(userHash)) { + comment.setDeleteable(true); + } else { + comment.setDeleteable(false); + } + result.add(comment); } - return result; } + return result; + } @Override - public Long postComment(Long boothId, CommentRequest commentRequest) { + public Long postComment(Long boothId, CommentRequest commentRequest, String userHash) { - Optional boothOp = boothRepository.findById(boothId); - - Comment comment = Comment.builder() - .name(commentRequest.getName()) - .comment(commentRequest.getComment()) - .password(commentRequest.getPassword()) - .build(); + UserEntity user = userService.getUserByHash(userHash); + Optional boothOp = boothRepository.findById(boothId); + BoothEntity booth; if(boothOp.isEmpty()){ - throw new NoExistException("댓글을 추가할 부스 정보가 없습니다. (id 확인 요망)"); + throw new NoExistException("해당 부스 정보가 없습니다. (id 확인 요망)"); }else{ - CommentEntity newComment = comment.toEntity(boothOp.get()); - commentRepository.save(newComment); - return newComment.getId(); + booth = boothOp.get(); } + + CommentEntity newComment = Comment.toEntity(commentRequest, booth, user); + commentRepository.save(newComment); + return newComment.getId(); } @Override - public void deleteComment(Long commentId, String password) { + public void deleteComment(Long commentId, String userHash) { Optional commentOp = commentRepository.findById(commentId); if(commentOp.isEmpty()) { throw new NoExistException("해당 댓글은 없습니다. (id 확인 요망)"); }else{ - if(commentOp.get().getPassword().equals(password)){ + if(commentOp.get().getUser().getUserHash().equals(userHash)){ commentRepository.delete(commentOp.get()); }else{ - throw new PasswordWrongException("비밀번호가 틀렸습니다."); + throw new UserHashWrongException("userHash 값이 일치하지 않습니다."); } } } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java index 813dcf6..e8a8880 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java @@ -2,10 +2,7 @@ import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity; import LlikelionKNU.KNUfest.global.basic.BasicEntity; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -16,14 +13,15 @@ @Entity @NoArgsConstructor @AllArgsConstructor +@Table(name = "likes") public class UserBoothEntity extends BasicEntity { @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "userId") - private UserEntity userEntity; + private UserEntity user; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "boothId") - private BoothEntity boothEntity; + private BoothEntity booth; } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java index 560bd99..ce89e1d 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java @@ -1,6 +1,7 @@ package LlikelionKNU.KNUfest.domain.user.entity; +import LlikelionKNU.KNUfest.domain.comment.entity.CommentEntity; import LlikelionKNU.KNUfest.global.basic.BasicEntity; import jakarta.persistence.*; import lombok.AllArgsConstructor; @@ -8,16 +9,22 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; + @Data @AllArgsConstructor @NoArgsConstructor @Builder @Entity +@Table(name="users") public class UserEntity extends BasicEntity { @Column(name = "userHash") private String userHash; - @OneToMany(mappedBy = "userEntity", fetch = FetchType.LAZY, cascade = CascadeType.ALL) - private UserBoothEntity userBooth; + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) + private List userBoothes; + + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) + private List comments; } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java deleted file mode 100644 index 2ddac37..0000000 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java +++ /dev/null @@ -1,13 +0,0 @@ -package LlikelionKNU.KNUfest.domain.user.service; - - -import LlikelionKNU.KNUfest.domain.booth.dto.Booth; -import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity; - -import java.util.List; -import java.util.Optional; - -public interface UserBoothService { - List getAllUserBooth(Long userId); - Optional getUserBooth(Long userId, Long boothId); -} diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothServiceImpl.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothServiceImpl.java deleted file mode 100644 index 70dd05d..0000000 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothServiceImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -package LlikelionKNU.KNUfest.domain.user.service; - -import LlikelionKNU.KNUfest.domain.booth.dto.Booth; -import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity; -import LlikelionKNU.KNUfest.domain.user.repository.UserBoothRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Optional; - -@Service -@RequiredArgsConstructor -public class UserBoothServiceImpl implements UserBoothService{ - - private final UserBoothRepository userBoothRepository; - - @Override - public List getAllUserBooth(Long userId) { - return userBoothRepository.findAllByUserId(userId); - } - - @Override - public Optional getUserBooth(Long userId, Long boothId) { - return userBoothRepository.findByUserIdAndBoothId(userId, boothId); - } - - -} diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserServiceImpl.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserServiceImpl.java index 23cd017..8cf57ff 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserServiceImpl.java @@ -12,8 +12,6 @@ @RequiredArgsConstructor public class UserServiceImpl implements UserService{ private final UserRepository userRepository; - - @Override public UserEntity getUserByHash(String userHash) { diff --git a/src/main/java/LlikelionKNU/KNUfest/global/basic/BasicEntity.java b/src/main/java/LlikelionKNU/KNUfest/global/basic/BasicEntity.java index 75a0151..9be5b26 100644 --- a/src/main/java/LlikelionKNU/KNUfest/global/basic/BasicEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/global/basic/BasicEntity.java @@ -4,12 +4,10 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.context.annotation.Configuration; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import java.time.Instant; +import java.time.LocalDateTime; @MappedSuperclass @EntityListeners(AuditingEntityListener.class) @@ -24,10 +22,10 @@ public class BasicEntity { @CreatedDate @Column(updatable = false) - private Instant createdAt; + private LocalDateTime createdAt; @LastModifiedDate @Column(updatable = true) - private Instant updatedAt; + private LocalDateTime updatedAt; } diff --git a/src/main/java/LlikelionKNU/KNUfest/global/basic/BasicResponse.java b/src/main/java/LlikelionKNU/KNUfest/global/basic/BasicResponse.java index 32f8104..06b64b7 100644 --- a/src/main/java/LlikelionKNU/KNUfest/global/basic/BasicResponse.java +++ b/src/main/java/LlikelionKNU/KNUfest/global/basic/BasicResponse.java @@ -5,6 +5,8 @@ import lombok.Data; import lombok.RequiredArgsConstructor; +import java.time.LocalDateTime; + @Data @Builder @RequiredArgsConstructor @@ -12,4 +14,5 @@ public class BasicResponse { private int status; private String message; + private LocalDateTime timeStamp; } diff --git a/src/main/java/LlikelionKNU/KNUfest/global/error/CustomExceptionHandler.java b/src/main/java/LlikelionKNU/KNUfest/global/error/CustomExceptionHandler.java index 0e478ec..12b9e6b 100644 --- a/src/main/java/LlikelionKNU/KNUfest/global/error/CustomExceptionHandler.java +++ b/src/main/java/LlikelionKNU/KNUfest/global/error/CustomExceptionHandler.java @@ -1,13 +1,13 @@ package LlikelionKNU.KNUfest.global.error; -import org.apache.coyote.Response; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; +import java.time.LocalDateTime; import java.util.Date; @RestControllerAdvice @@ -18,19 +18,19 @@ public ResponseEntity NoExistException(NoExistException ex){ ErrorMessage message = ErrorMessage.builder() .status(HttpStatus.NOT_FOUND.value()) .message(ex.getMessage()) - .timeStamp(new Date()) + .timeStamp(LocalDateTime.now()) .build(); return ResponseEntity.status(HttpStatus.NOT_FOUND).body(message); } - @ExceptionHandler(PasswordWrongException.class) + @ExceptionHandler(UserHashWrongException.class) @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) - public ResponseEntity PasswordWrongException(PasswordWrongException ex){ + public ResponseEntity PasswordWrongException(UserHashWrongException ex){ ErrorMessage message = ErrorMessage.builder() .status(HttpStatus.NOT_ACCEPTABLE.value()) .message(ex.getMessage()) - .timeStamp(new Date()) + .timeStamp(LocalDateTime.now()) .build(); return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body(message); diff --git a/src/main/java/LlikelionKNU/KNUfest/global/error/ErrorMessage.java b/src/main/java/LlikelionKNU/KNUfest/global/error/ErrorMessage.java index f470249..01d4eb5 100644 --- a/src/main/java/LlikelionKNU/KNUfest/global/error/ErrorMessage.java +++ b/src/main/java/LlikelionKNU/KNUfest/global/error/ErrorMessage.java @@ -2,6 +2,7 @@ import lombok.*; +import java.time.LocalDateTime; import java.util.Date; @Data @@ -9,5 +10,5 @@ public class ErrorMessage { private int status; private String message; - private Date timeStamp; + private LocalDateTime timeStamp; } diff --git a/src/main/java/LlikelionKNU/KNUfest/global/error/PasswordWrongException.java b/src/main/java/LlikelionKNU/KNUfest/global/error/PasswordWrongException.java deleted file mode 100644 index 5281e7c..0000000 --- a/src/main/java/LlikelionKNU/KNUfest/global/error/PasswordWrongException.java +++ /dev/null @@ -1,7 +0,0 @@ -package LlikelionKNU.KNUfest.global.error; - -public class PasswordWrongException extends RuntimeException{ - public PasswordWrongException(String message){ - super(message); - } -} diff --git a/src/main/java/LlikelionKNU/KNUfest/global/error/UserHashWrongException.java b/src/main/java/LlikelionKNU/KNUfest/global/error/UserHashWrongException.java new file mode 100644 index 0000000..b9758da --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/global/error/UserHashWrongException.java @@ -0,0 +1,7 @@ +package LlikelionKNU.KNUfest.global.error; + +public class UserHashWrongException extends RuntimeException{ + public UserHashWrongException(String message){ + super(message); + } +} diff --git a/src/main/java/LlikelionKNU/KNUfest/global/time/controller/TimeController.java b/src/main/java/LlikelionKNU/KNUfest/global/time/controller/TimeController.java index b03320c..dc122fb 100644 --- a/src/main/java/LlikelionKNU/KNUfest/global/time/controller/TimeController.java +++ b/src/main/java/LlikelionKNU/KNUfest/global/time/controller/TimeController.java @@ -8,12 +8,13 @@ import org.springframework.web.bind.annotation.RestController; import java.time.Instant; +import java.time.LocalDateTime; @RestController("api/v1") public class TimeController { @GetMapping("time") @Operation(summary = "서버 시간 조회", description = "서버 현재 시간을 보내준다.") - public ResponseEntity getServerTime(){ - return ResponseEntity.ok().body(Instant.now()); + public ResponseEntity getServerTime(){ + return ResponseEntity.ok().body(LocalDateTime.now()); } }