From abb616e288cdbd4e202171547b9653b95efe3bdf Mon Sep 17 00:00:00 2001 From: siksik-Choi Date: Sun, 12 May 2024 15:05:24 +0900 Subject: [PATCH 1/5] [ADD] boothName & boothUrls --- .../java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java | 2 ++ .../LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java | 3 +++ .../LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java | 4 ++++ .../KNUfest/domain/booth/service/BoothServiceImpl.java | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java index e035142..3f8187c 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java @@ -11,5 +11,7 @@ @AllArgsConstructor public class Booth { int id; + String boothName; int likes; + String urls; } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java index b175656..6d66f20 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java @@ -10,6 +10,9 @@ @Builder public class BoothDetail { int id; + String boothName; int likes; + String urls; + List comments; } 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 996c1b4..fae39b0 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java @@ -17,10 +17,14 @@ @Table(name = "BOOTH") public class BoothEntity extends BasicEntity { + @Column(name="booth_name") + private String boothName; + @Column(name="likes") @ColumnDefault("0") private int likes; + @OneToMany(mappedBy = "booth", fetch = FetchType.LAZY) private List commentEntityList; 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 5997e4a..ea592e8 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java @@ -35,6 +35,7 @@ public AllBooth getAllbooth() { boothDtos.add(Booth.builder() .id(booth.getId().intValue()) + .boothName(booth.getBoothName()) .likes(booth.getLikes()) .build()); } @@ -53,9 +54,12 @@ public BoothDetail getBooth(int id) { throw new NoExistException("해당 부스 정보가 없습니다. (id 확인요망)"); }else{ BoothEntity booth = boothOp.get(); + return BoothDetail.builder() .id(booth.getId().intValue()) + .boothName(booth.getBoothName()) .likes(booth.getLikes()) + .urls(booth.getUrls().toString()) .comments(commentService.getCommentPage(boothOp.get().getId().intValue(),5,1, "default")) .build(); } From 18c04b3e03e9d91e65e9c2d6bdb4cddf8b792669 Mon Sep 17 00:00:00 2001 From: siksik-Choi Date: Sun, 12 May 2024 16:45:13 +0900 Subject: [PATCH 2/5] [MODIFY] BoothDetail_urls --- src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java | 1 - .../LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java | 2 +- .../KNUfest/domain/booth/service/BoothServiceImpl.java | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java index 3f8187c..aa2b60f 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java @@ -13,5 +13,4 @@ public class Booth { int id; String boothName; int likes; - String urls; } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java index 6d66f20..f36230e 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java @@ -12,7 +12,7 @@ public class BoothDetail { int id; String boothName; int likes; - String urls; + List urls; List comments; } 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 ea592e8..90a70af 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java @@ -25,7 +25,6 @@ public AllBooth getAllbooth() { List boothes = boothrepository.findAll(); List boothDtos; - AllBooth result; if(boothes.isEmpty()) { throw new NoExistException("부스 전체 정보가 없습니다."); @@ -59,7 +58,7 @@ public BoothDetail getBooth(int id) { .id(booth.getId().intValue()) .boothName(booth.getBoothName()) .likes(booth.getLikes()) - .urls(booth.getUrls().toString()) + .urls(booth.getUrls()) .comments(commentService.getCommentPage(boothOp.get().getId().intValue(),5,1, "default")) .build(); } From 550075a965cb4c9225ac275c4552ed7dd615a9ed Mon Sep 17 00:00:00 2001 From: siksik-Choi Date: Sun, 12 May 2024 17:58:05 +0900 Subject: [PATCH 3/5] [ADD] UserBooth domain --- .../domain/booth/entity/BoothEntity.java | 4 +++ .../domain/user/entity/UserBoothEntity.java | 28 +++++++++++++++++++ .../domain/user/entity/UserEntity.java | 22 +++++++++++++++ .../user/repository/UserBoothRepository.java | 18 ++++++++++++ .../domain/user/service/UserBoothService.java | 12 ++++++++ .../user/service/UserBoothServiceImpl.java | 28 +++++++++++++++++++ 6 files changed, 112 insertions(+) create mode 100644 src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java create mode 100644 src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java create mode 100644 src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java create mode 100644 src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java create mode 100644 src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothServiceImpl.java 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 fae39b0..5b07d2f 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java @@ -1,6 +1,7 @@ package LlikelionKNU.KNUfest.domain.booth.entity; import LlikelionKNU.KNUfest.domain.comment.entity.CommentEntity; +import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity; import LlikelionKNU.KNUfest.global.basic.BasicEntity; import jakarta.persistence.*; import lombok.*; @@ -28,6 +29,9 @@ public class BoothEntity extends BasicEntity { @OneToMany(mappedBy = "booth", fetch = FetchType.LAZY) private List commentEntityList; + @OneToMany(mappedBy = "boothEntity", fetch = FetchType.LAZY) + private UserBoothEntity userBoothEntity; + @ElementCollection @CollectionTable( name = "URL_LIST", diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java new file mode 100644 index 0000000..d7aaf3a --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java @@ -0,0 +1,28 @@ +package LlikelionKNU.KNUfest.domain.user.entity; + +import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@Entity +@NoArgsConstructor +@AllArgsConstructor +public class UserBoothEntity { + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "userId") + private UserEntity userEntity; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "boothId") + private BoothEntity boothEntity; + +} diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java new file mode 100644 index 0000000..12ae07c --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java @@ -0,0 +1,22 @@ +package LlikelionKNU.KNUfest.domain.user.entity; + + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Entity +public class UserEntity { + + @Column(name = "userHash") + private String userHash; + + @OneToMany(mappedBy = "userEntity", fetch = FetchType.LAZY, cascade = CascadeType.ALL) + private UserBoothEntity userBooth; +} diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java new file mode 100644 index 0000000..9707bd2 --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java @@ -0,0 +1,18 @@ +package LlikelionKNU.KNUfest.domain.user.repository; + +import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity; +import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface UserBoothRepository extends JpaRepository { + + List findAllByUserId(Long userId); + + UserBoothEntity findByUserIdAndBoothId(Long userId, Long BoothId); +} diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java new file mode 100644 index 0000000..e77b82a --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java @@ -0,0 +1,12 @@ +package LlikelionKNU.KNUfest.domain.user.service; + + +import LlikelionKNU.KNUfest.domain.booth.dto.Booth; +import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity; + +import java.util.List; + +public interface UserBoothService { + List getAllUserBooth(Long userId); + UserBoothEntity 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 new file mode 100644 index 0000000..207ba4e --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothServiceImpl.java @@ -0,0 +1,28 @@ +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; + +@Service +@RequiredArgsConstructor +public class UserBoothServiceImpl implements UserBoothService{ + + private final UserBoothRepository userBoothRepository; + + @Override + public List getAllUserBooth(Long userId) { + return userBoothRepository.findAllByUserId(userId); + } + + @Override + public UserBoothEntity getUserBooth(Long userId, Long boothId) { + return userBoothRepository.findByUserIdAndBoothId(userId, boothId); + } + + +} From 3c3f79581323a6bb47fa241b7412f4ddfe557891 Mon Sep 17 00:00:00 2001 From: siksik-Choi Date: Sun, 12 May 2024 19:28:56 +0900 Subject: [PATCH 4/5] [ADD] Likable Service --- .../booth/controller/BoothController.java | 13 +++--- .../KNUfest/domain/booth/dto/Booth.java | 3 +- .../KNUfest/domain/booth/dto/BoothDetail.java | 3 +- .../domain/booth/service/BoothService.java | 6 +-- .../booth/service/BoothServiceImpl.java | 40 ++++++++++++++----- .../comment/controller/CommentController.java | 8 ++-- .../KNUfest/domain/comment/dto/Comment.java | 2 +- .../domain/comment/entity/CommentEntity.java | 2 +- .../comment/repository/CommentRepository.java | 4 +- .../comment/service/CommentService.java | 6 +-- .../comment/service/CommentServiceImpl.java | 14 +++---- .../domain/user/entity/UserBoothEntity.java | 3 +- .../domain/user/entity/UserEntity.java | 3 +- .../user/repository/UserBoothRepository.java | 3 +- .../user/repository/UserRepository.java | 12 ++++++ .../domain/user/service/UserBoothService.java | 3 +- .../user/service/UserBoothServiceImpl.java | 3 +- .../domain/user/service/UserService.java | 9 +++++ .../domain/user/service/UserServiceImpl.java | 34 ++++++++++++++++ 19 files changed, 129 insertions(+), 42 deletions(-) create mode 100644 src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserRepository.java create mode 100644 src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserService.java create mode 100644 src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserServiceImpl.java 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 c413537..a0e0b9c 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/controller/BoothController.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/controller/BoothController.java @@ -17,24 +17,27 @@ public class BoothController { @GetMapping() @Operation(summary = "모든 부스정보 조회", description = "모든 부스의 id와 좋아요를 보내준다. 그 부스 목록에 뜨는 걸로 쓰면 됨") - public ResponseEntity getAllbooth(){ - AllBooth booths = service.getAllbooth(); + public ResponseEntity getAllbooth( + @RequestParam("userHash") String userHash + ){ + AllBooth booths = service.getAllbooth(userHash); return ResponseEntity.ok().body(booths); } @GetMapping("{boothId}") @Operation(summary = "특정 부스정보 조회", description = "특정 부스의 id, 좋아요, 오래된 순 댓글 5개를 보내준다. 부스 별 페이지에 갖다 쓰면 됨" ) public ResponseEntity getBooth( - @PathVariable("boothId") int boothId + @PathVariable("boothId") Long boothId, + @RequestParam("userHash") String userHash ){ - BoothDetail boothDto = service.getBooth(boothId); + BoothDetail boothDto = service.getBooth(boothId, userHash); return ResponseEntity.ok().body(boothDto); } @PatchMapping("{boothId}") @Operation(summary = "특정 부스 좋아요 업데이트", description = "특정 부스의 좋아요를 +1 한다.") public ResponseEntity updateLikes( - @PathVariable("boothId") int boothId + @PathVariable("boothId") Long boothId ){ service.updateLikes(boothId); BasicResponse response = BasicResponse.builder() diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java index aa2b60f..2d7bc1e 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/Booth.java @@ -10,7 +10,8 @@ @RequiredArgsConstructor @AllArgsConstructor public class Booth { - int id; + Long id; String boothName; int likes; + boolean Likable; } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java index f36230e..a0c83cb 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java @@ -9,10 +9,11 @@ @Data @Builder public class BoothDetail { - int id; + Long id; String boothName; int likes; List urls; + boolean Likable; List comments; } 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 55d43fd..7c56400 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothService.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothService.java @@ -4,8 +4,8 @@ import LlikelionKNU.KNUfest.domain.booth.dto.BoothDetail; public interface BoothService { - AllBooth getAllbooth(); - BoothDetail getBooth(int id); - void updateLikes(int id); + AllBooth getAllbooth(String userHash); + BoothDetail getBooth(Long id, String userHash); + void updateLikes(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 90a70af..5a02557 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java @@ -6,6 +6,10 @@ import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity; 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.service.UserService; +import LlikelionKNU.KNUfest.domain.user.service.UserServiceImpl; import LlikelionKNU.KNUfest.global.error.NoExistException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,24 +24,37 @@ public class BoothServiceImpl implements BoothService{ private final BoothRepository boothrepository; private final CommentService commentService; + private final UserBoothService userBoothService; + private final UserService userService; + @Override - public AllBooth getAllbooth() { + public AllBooth getAllbooth(String userHash) { List boothes = boothrepository.findAll(); List boothDtos; + List userBoothEntityList = userBoothService.getAllUserBooth( + userService.getUserByHash(userHash).getId()); + if(boothes.isEmpty()) { throw new NoExistException("부스 전체 정보가 없습니다."); }else{ boothDtos = new ArrayList<>(); for(BoothEntity booth : boothes){ - boothDtos.add(Booth.builder() - .id(booth.getId().intValue()) + .id(booth.getId()) .boothName(booth.getBoothName()) .likes(booth.getLikes()) + .Likable(true) .build()); } + + for(UserBoothEntity userBooth : userBoothEntityList){ + Booth tempbooth = boothDtos.get(userBooth.getBoothEntity().getId().intValue()); + tempbooth.setLikable(false); + boothDtos.set(userBooth.getBoothEntity().getId().intValue(), tempbooth); + } + return AllBooth.builder() .count(boothDtos.size()) .boothDtoes(boothDtos) @@ -46,8 +63,12 @@ public AllBooth getAllbooth() { } @Override - public BoothDetail getBooth(int id) { - Optional boothOp = boothrepository.findById(Long.valueOf(id)); + public BoothDetail getBooth(Long id, String userHash) { + Optional boothOp = boothrepository.findById(id); + + Optional userBoothEntity = userBoothService.getUserBooth(id, userService.getUserByHash(userHash).getId()); + + boolean temp = userBoothEntity.isEmpty(); if(boothOp.isEmpty()){ throw new NoExistException("해당 부스 정보가 없습니다. (id 확인요망)"); @@ -55,19 +76,20 @@ public BoothDetail getBooth(int id) { BoothEntity booth = boothOp.get(); return BoothDetail.builder() - .id(booth.getId().intValue()) + .id(booth.getId()) .boothName(booth.getBoothName()) .likes(booth.getLikes()) .urls(booth.getUrls()) - .comments(commentService.getCommentPage(boothOp.get().getId().intValue(),5,1, "default")) + .Likable(temp) + .comments(commentService.getCommentPage(boothOp.get().getId(),5,1, "default")) .build(); } } @Override - public void updateLikes(int id) { + public void updateLikes(Long id) { - Optional boothOp = boothrepository.findById(Long.valueOf(id)); + Optional boothOp = boothrepository.findById(id); BoothEntity booth; if(boothOp.isEmpty()){ 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 e6858be..d4782bb 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/controller/CommentController.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/controller/CommentController.java @@ -20,7 +20,7 @@ public class CommentController { @GetMapping("booth/{boothId}/comment") @Operation(summary = "추가 댓글 조회", description = "해당 부스의 추가 댓글내용을 제공한다. perpage = 요청당 댓글 개수 한 페이지 당 통일되게 보내야 됨, page = 요청 댓글 set 순번. order = 댓글 정렬순서 최신순은 'desc' 오래된 순은 'default' 이다. ") public ResponseEntity> getExtraCommentPage( - @PathVariable("boothId") int boothId, + @PathVariable("boothId") Long boothId, @RequestParam("perpage") int perpage, @RequestParam("page") int page, @RequestParam("order") String order @@ -32,11 +32,11 @@ public ResponseEntity> getExtraCommentPage( @PostMapping("booth/{boothId}/comment") @Operation(summary = "특정부스 댓글 생성", description = "특정 부스에 댓글을 생성한다.") public ResponseEntity postComment( - @PathVariable("boothId") int boothId, + @PathVariable("boothId") Long boothId, @RequestBody CommentRequest comment ){ - int id = service.postComment(boothId, comment); + Long id = service.postComment(boothId, comment); BasicResponse response = BasicResponse.builder() .message(boothId+"번 부스에 댓글을 생성하였습니다.") @@ -49,7 +49,7 @@ public ResponseEntity postComment( @DeleteMapping("comment/{commentId}") @Operation(summary = "특정 댓글 삭제", description = "특정 댓글을 password 가 일치할 경우 삭제한다.") public ResponseEntity deleteComment( - @PathVariable("commentId") int commentId, + @PathVariable("commentId") Long commentId, @RequestParam("password") String password ){ 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 29a0544..0ead98a 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/Comment.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/dto/Comment.java @@ -10,7 +10,7 @@ @Data @Builder public class Comment { - int id; + Long id; String name; String comment; 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 98b0165..884d1e1 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/entity/CommentEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/entity/CommentEntity.java @@ -32,7 +32,7 @@ public class CommentEntity extends BasicEntity { public Comment toDto(){ return Comment.builder() - .id(this.getId().intValue()) + .id(this.getId()) .name(this.name) .password(this.password) .comment(this.comment) diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/comment/repository/CommentRepository.java b/src/main/java/LlikelionKNU/KNUfest/domain/comment/repository/CommentRepository.java index 2802632..8acb46a 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/repository/CommentRepository.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/repository/CommentRepository.java @@ -14,8 +14,8 @@ public interface CommentRepository extends JpaRepository { @Query(value = "select * from booth_comment where booth_id= :boothId order by id limit :lim offset :offset", nativeQuery = true) - List findAllOrderById(@Param("boothId") int boothId, @Param("lim") int limit, @Param("offset") int offset); + List findAllOrderById(@Param("boothId") Long boothId, @Param("lim") int limit, @Param("offset") int offset); @Query(value = "select * from booth_comment where booth_id= :boothId order by id desc limit :lim offset :off", nativeQuery = true) - List findAllOrderByIdDESC(@Param("boothId") int boothId, @Param("lim") int limit, @Param("off") int offset); + List findAllOrderByIdDESC(@Param("boothId") Long boothId, @Param("lim") int limit, @Param("off") int offset); } 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 8d4e1f9..e112c3f 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(int boothId, int perpage, int page, String order); - int postComment(int id, CommentRequest comment); - void deleteComment(int commentId, String password); + List getCommentPage(Long boothId, int perpage, int page, String order); + Long postComment(Long id, CommentRequest comment); + 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 eb5437c..3dbbd2b 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/service/CommentServiceImpl.java @@ -21,9 +21,9 @@ public class CommentServiceImpl implements CommentService{ private final CommentRepository commentRepository; private final BoothRepository boothRepository; @Override - public List getCommentPage(int boothId, int perpage, int page, String order) { + public List getCommentPage(Long boothId, int perpage, int page, String order) { - Optional boothOp = boothRepository.findById(Long.valueOf(boothId)); + Optional boothOp = boothRepository.findById(boothId); List comments; List result; @@ -47,9 +47,9 @@ public List getCommentPage(int boothId, int perpage, int page, String o } @Override - public int postComment(int boothId, CommentRequest commentRequest) { + public Long postComment(Long boothId, CommentRequest commentRequest) { - Optional boothOp = boothRepository.findById(Long.valueOf(boothId)); + Optional boothOp = boothRepository.findById(boothId); Comment comment = Comment.builder() .name(commentRequest.getName()) @@ -62,13 +62,13 @@ public int postComment(int boothId, CommentRequest commentRequest) { }else{ CommentEntity newComment = comment.toEntity(boothOp.get()); commentRepository.save(newComment); - return newComment.getId().intValue(); + return newComment.getId(); } } @Override - public void deleteComment(int commentId, String password) { - Optional commentOp = commentRepository.findById(Long.valueOf(commentId)); + public void deleteComment(Long commentId, String password) { + Optional commentOp = commentRepository.findById(commentId); if(commentOp.isEmpty()) { throw new NoExistException("해당 댓글은 없습니다. (id 확인 요망)"); 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 d7aaf3a..813dcf6 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java @@ -1,6 +1,7 @@ package LlikelionKNU.KNUfest.domain.user.entity; 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; @@ -15,7 +16,7 @@ @Entity @NoArgsConstructor @AllArgsConstructor -public class UserBoothEntity { +public class UserBoothEntity extends BasicEntity { @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "userId") 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 12ae07c..560bd99 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.global.basic.BasicEntity; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Builder; @@ -12,7 +13,7 @@ @NoArgsConstructor @Builder @Entity -public class UserEntity { +public class UserEntity extends BasicEntity { @Column(name = "userHash") private String userHash; diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java index 9707bd2..3495734 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java @@ -8,11 +8,12 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface UserBoothRepository extends JpaRepository { List findAllByUserId(Long userId); - UserBoothEntity findByUserIdAndBoothId(Long userId, Long BoothId); + Optional findByUserIdAndBoothId(Long userId, Long BoothId); } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserRepository.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserRepository.java new file mode 100644 index 0000000..4946550 --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserRepository.java @@ -0,0 +1,12 @@ +package LlikelionKNU.KNUfest.domain.user.repository; + +import LlikelionKNU.KNUfest.domain.user.entity.UserEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface UserRepository extends JpaRepository { + Optional findByUserHash(String userHash); +} diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java index e77b82a..2ddac37 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java @@ -5,8 +5,9 @@ import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity; import java.util.List; +import java.util.Optional; public interface UserBoothService { List getAllUserBooth(Long userId); - UserBoothEntity getUserBooth(Long userId, Long boothId); + 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 index 207ba4e..70dd05d 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -20,7 +21,7 @@ public List getAllUserBooth(Long userId) { } @Override - public UserBoothEntity getUserBooth(Long userId, Long boothId) { + public Optional getUserBooth(Long userId, Long boothId) { return userBoothRepository.findByUserIdAndBoothId(userId, boothId); } diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserService.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserService.java new file mode 100644 index 0000000..8273032 --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserService.java @@ -0,0 +1,9 @@ +package LlikelionKNU.KNUfest.domain.user.service; + +import LlikelionKNU.KNUfest.domain.user.entity.UserEntity; +import org.springframework.stereotype.Service; + + +public interface UserService { + UserEntity getUserByHash(String userHash); +} diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserServiceImpl.java b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserServiceImpl.java new file mode 100644 index 0000000..23cd017 --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserServiceImpl.java @@ -0,0 +1,34 @@ +package LlikelionKNU.KNUfest.domain.user.service; + +import LlikelionKNU.KNUfest.domain.user.entity.UserEntity; +import LlikelionKNU.KNUfest.domain.user.repository.UserRepository; +import LlikelionKNU.KNUfest.global.error.NoExistException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class UserServiceImpl implements UserService{ + private final UserRepository userRepository; + + + @Override + public UserEntity getUserByHash(String userHash) { + + Optional userEntity = userRepository.findByUserHash(userHash); + UserEntity newUser; + if(userEntity.isEmpty()){ + newUser = UserEntity.builder() + .userHash(userHash).build(); + userRepository.save(newUser); + + return newUser; + } + else{ + return userEntity.get(); + } + + } +} From 48f11d22325aa4e6fe4a0511ba3c86ed0d305075 Mon Sep 17 00:00:00 2001 From: DongGeon Lee <71763322+himodu@users.noreply.github.com> Date: Sun, 12 May 2024 19:39:11 +0900 Subject: [PATCH 5/5] Update gradle.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pr closed 될때 action --- .github/workflows/gradle.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 2e1035f..855f1ce 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -6,6 +6,8 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] + types: closed + permissions: contents: read