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 df15d74..c8ff9b7 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/controller/BoothController.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/controller/BoothController.java @@ -18,7 +18,7 @@ public class BoothController { private final BoothService service; @GetMapping() - @Operation(summary = "모든 부스정보 조회", description = "모든 부스의 id와 좋아요를 보내준다. 그 부스 목록에 뜨는 걸로 쓰면 됨") + @Operation(summary = "모든 부스정보 조회", description = "모든 부스의 id와 좋아요를 보내준다. 그 부스 목록에 뜨는 걸로 쓰면 됨. likable은 유저별 좋아요 누르기 가능여부") public ResponseEntity getAllbooth( @RequestParam("userHash") String userHash ){ @@ -26,23 +26,25 @@ public ResponseEntity getAllbooth( return ResponseEntity.ok().body(booths); } - @GetMapping("{boothId}") - @Operation(summary = "특정 부스정보 조회", description = "특정 부스의 id, 좋아요, 오래된 순 댓글 5개를 보내준다. 부스 별 페이지에 갖다 쓰면 됨" ) + @GetMapping("/{categori}/{boothNum}") + @Operation(summary = "특정 부스정보 조회", description = "특정 부스의 id, 좋아요, 오래된 순 댓글 5개를 보내준다. 부스 별 페이지에 갖다 쓰면 됨. categori: 부스 종류, boothnum: 부스번호임. likable은 유저별 좋아요 누르기 가능여부" ) public ResponseEntity getBooth( - @PathVariable("boothId") Long boothId, + @PathVariable("boothNum") int boothNum, + @PathVariable("categori") String categori, @RequestParam("userHash") String userHash ){ - BoothDetail boothDto = service.getBooth(boothId, userHash); + BoothDetail boothDto = service.getBooth(boothNum, categori, userHash); return ResponseEntity.ok().body(boothDto); } - @PatchMapping("{boothId}") + @PatchMapping("{categori}/{boothNum}") @Operation(summary = "특정 부스 좋아요 업데이트", description = "특정 부스의 좋아요를 변경한다.") public ResponseEntity updateLikes( - @PathVariable("boothId") Long boothId, + @PathVariable("boothNum") int boothNum, + @PathVariable("categori") String categori, @RequestParam("userHash") String userHash ){ - String message = service.updateLikes(boothId, userHash); + String message = service.updateLikes(boothNum, categori, userHash); BasicResponse response = BasicResponse.builder() .message(message) .status(200) 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 2726934..8689502 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,7 @@ public class Booth { private Long id; private String boothName; private int likes; + private String categori; + private int boothnum; private 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 473b685..47e3223 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothDetail.java @@ -12,6 +12,8 @@ public class BoothDetail { private Long id; private String boothName; private int likes; + private String categori; + private int boothnum; private List urls; private boolean Likable; 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 34d2956..5c888c5 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java @@ -25,6 +25,12 @@ public class BoothEntity extends BasicEntity { @ColumnDefault("0") private int likes; + @Column(name="categori") + private String categori; + + @Column(name="booth_num") + private int boothnum; + @OneToMany(mappedBy = "booth", fetch = FetchType.LAZY) private List commentEntityList; diff --git a/src/main/java/LlikelionKNU/KNUfest/domain/booth/repository/BoothRepository.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/repository/BoothRepository.java index 07f4de2..12e6d41 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/repository/BoothRepository.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/repository/BoothRepository.java @@ -11,4 +11,6 @@ public interface BoothRepository extends JpaRepository { Optional findById(Long id); + + Optional findByBoothnumAndCategori(int boothnum, String categori); } 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 c06f3df..a1f8a3f 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothService.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothService.java @@ -6,8 +6,9 @@ public interface BoothService { AllBooth getAllbooth(String userHash); - BoothDetail getBooth(Long id, String userHash); - String updateLikes(Long id, String userHash); + BoothDetail getBooth(int boothNum, String categori, String userHash); + String updateLikes(int boothNum, String categori, String userHash); + BoothEntity findByBoothnumAndCategori(int boothnum, String categori); 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 bb11e85..33c11ae 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/booth/service/BoothServiceImpl.java @@ -45,10 +45,13 @@ public AllBooth getAllbooth(String userHash) { .id(booth.getId()) .boothName(booth.getBoothName()) .likes(booth.getLikes()) + .categori(booth.getCategori()) + .boothnum(booth.getBoothnum()) .Likable(true) .build()); } + // Likable Service if(!userBoothEntityList.isEmpty()){ for(UserBoothEntity userBooth : userBoothEntityList){ Booth tempbooth = boothDtos.get(userBooth.getBooth().getId().intValue()-1); @@ -66,29 +69,34 @@ public AllBooth getAllbooth(String userHash) { } @Override - public BoothDetail getBooth(Long boothId, String userHash) { - Optional boothOp; + public BoothDetail getBooth(int boothnum, String categori, String userHash) { + Optional boothOp = boothrepository.findByBoothnumAndCategori(boothnum, categori); - Optional userBoothEntity = userBoothRepository.findByUserIdAndBoothId(userService.getUserByHash(userHash).getId(), boothId); + if(boothOp.isEmpty()){ + throw new NoExistException("해당 부스 정보가 없습니다. (id 확인 요망)"); + } + + Optional userBoothEntity = userBoothRepository.findByUserIdAndBoothId(userService.getUserByHash(userHash).getId(), boothOp.get().getId()); BoothEntity booth; boolean temp; + + if(userBoothEntity.isEmpty()){ - boothOp = boothrepository.findById(boothId); temp = true; - if(boothOp.isEmpty()){ - throw new NoExistException("해당 부스 정보가 없습니다. (id 확인요망)"); - }else{ - booth = boothOp.get(); - } + booth = boothOp.get(); + }else{ temp = false; booth = userBoothEntity.get().getBooth(); } + return BoothDetail.builder() .id(booth.getId()) .boothName(booth.getBoothName()) .likes(booth.getLikes()) + .boothnum(booth.getBoothnum()) + .categori(booth.getCategori()) .urls(booth.getUrls()) .Likable(temp) .comments(commentService.getCommentPage(booth.getId(),5,1, "default", userHash)) @@ -96,33 +104,32 @@ public BoothDetail getBooth(Long boothId, String userHash) { } @Override - public String updateLikes(Long boothId, String userHash) { + public String updateLikes(int boothnum, String categori, String userHash) { + + Optional boothOp = boothrepository.findByBoothnumAndCategori(boothnum, categori); + if(boothOp.isEmpty()){ + throw new NoExistException("해당 부스 정보가 없습니다. (id 확인 요망)"); + } UserEntity user = userService.getUserByHash(userHash); - Optional userBoothEntity = userBoothRepository.findByUserIdAndBoothId(user.getId(), boothId); + Optional userBoothEntity = userBoothRepository.findByUserIdAndBoothId(user.getId(), boothOp.get().getId()); UserBoothEntity userBooth; 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) 하였습니다."; - } + 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(); @@ -145,4 +152,14 @@ public BoothEntity findById(Long id){ return boothOp.get(); } } + + @Override + public BoothEntity findByBoothnumAndCategori(int boothnum, String categori){ + Optional boothOp = boothrepository.findByBoothnumAndCategori(boothnum, categori); + if(boothOp.isEmpty()){ + throw new NoExistException(("해당 부스 정보가 없습니다. (id 확인 요망)")); + }else{ + 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 fe45286..7d7f42a 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/comment/controller/CommentController.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/comment/controller/CommentController.java @@ -19,7 +19,7 @@ public class CommentController { private final CommentService service; @GetMapping("booth/{boothId}/comment") - @Operation(summary = "추가 댓글 조회", description = "해당 부스의 추가 댓글내용을 제공한다. perpage = 요청당 댓글 개수 한 페이지 당 통일되게 보내야 됨, page = 요청 댓글 set 순번. order = 댓글 정렬순서 최신순은 'desc' 오래된 순은 'default' 이다. ") + @Operation(summary = "추가 댓글 조회", description = "해당 부스의 추가 댓글내용을 제공한다. perpage = 요청당 댓글 개수 한 페이지 당 통일되게 보내야 됨, page = 요청 댓글 set 순번. order = 댓글 정렬순서 최신순은 'desc' 오래된 순은 'default' 이다. deletable은 유저기반 삭제 가능 여부.") public ResponseEntity> getExtraCommentPage( @PathVariable("boothId") Long boothId, @RequestParam("perpage") int perpage, 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 3495734..46e6844 100644 --- a/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java @@ -16,4 +16,5 @@ public interface UserBoothRepository extends JpaRepository findAllByUserId(Long userId); Optional findByUserIdAndBoothId(Long userId, Long BoothId); + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bfb8251..2d8598f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,9 +1,9 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://mysql-withvol:3306/knufest - username: user - password: 1234 + url: jdbc:mysql://127.0.0.1:3306/knufest + username: root + password: root jpa: hibernate: