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 e035142..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,6 +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 b175656..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,7 +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/entity/BoothEntity.java b/src/main/java/LlikelionKNU/KNUfest/domain/booth/entity/BoothEntity.java index 996c1b4..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.*; @@ -17,13 +18,20 @@ @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; + @OneToMany(mappedBy = "boothEntity", fetch = FetchType.LAZY) + private UserBoothEntity userBoothEntity; + @ElementCollection @CollectionTable( name = "URL_LIST", 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 5997e4a..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; - AllBooth result; + + 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,25 +63,33 @@ 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 확인요망)"); }else{ BoothEntity booth = boothOp.get(); + return BoothDetail.builder() - .id(booth.getId().intValue()) + .id(booth.getId()) + .boothName(booth.getBoothName()) .likes(booth.getLikes()) - .comments(commentService.getCommentPage(boothOp.get().getId().intValue(),5,1, "default")) + .urls(booth.getUrls()) + .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 new file mode 100644 index 0000000..813dcf6 --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserBoothEntity.java @@ -0,0 +1,29 @@ +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; +import jakarta.persistence.ManyToOne; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@Entity +@NoArgsConstructor +@AllArgsConstructor +public class UserBoothEntity extends BasicEntity { + + @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..560bd99 --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/entity/UserEntity.java @@ -0,0 +1,23 @@ +package LlikelionKNU.KNUfest.domain.user.entity; + + +import LlikelionKNU.KNUfest.global.basic.BasicEntity; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Entity +public class UserEntity extends BasicEntity { + + @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..3495734 --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/repository/UserBoothRepository.java @@ -0,0 +1,19 @@ +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; +import java.util.Optional; + +@Repository +public interface UserBoothRepository extends JpaRepository { + + List findAllByUserId(Long userId); + + 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 new file mode 100644 index 0000000..2ddac37 --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothService.java @@ -0,0 +1,13 @@ +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 new file mode 100644 index 0000000..70dd05d --- /dev/null +++ b/src/main/java/LlikelionKNU/KNUfest/domain/user/service/UserBoothServiceImpl.java @@ -0,0 +1,29 @@ +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/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(); + } + + } +}