Skip to content

Commit

Permalink
Merge pull request #4 from LikeLion-KNU/Sik_demo3
Browse files Browse the repository at this point in the history
[ADD] Booth Column(boothnum, categori), [MODIFY] Booth Control Param
  • Loading branch information
siksik-Choi authored May 15, 2024
2 parents 8b3552b + 31a6aee commit 7911efd
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,33 @@ public class BoothController {
private final BoothService service;

@GetMapping()
@Operation(summary = "모든 부스정보 조회", description = "모든 부스의 id와 좋아요를 보내준다. 그 부스 목록에 뜨는 걸로 쓰면 됨")
@Operation(summary = "모든 부스정보 조회", description = "모든 부스의 id와 좋아요를 보내준다. 그 부스 목록에 뜨는 걸로 쓰면 됨. likable은 유저별 좋아요 누르기 가능여부")
public ResponseEntity<AllBooth> getAllbooth(
@RequestParam("userHash") String userHash
){
AllBooth booths = service.getAllbooth(userHash);
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<BoothDetail> 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<BasicResponse> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class BoothDetail {
private Long id;
private String boothName;
private int likes;
private String categori;
private int boothnum;
private List<String> urls;
private boolean Likable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommentEntity> commentEntityList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
public interface BoothRepository extends JpaRepository<BoothEntity, Long> {

Optional<BoothEntity> findById(Long id);

Optional<BoothEntity> findByBoothnumAndCategori(int boothnum, String categori);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -66,63 +69,67 @@ public AllBooth getAllbooth(String userHash) {
}

@Override
public BoothDetail getBooth(Long boothId, String userHash) {
Optional<BoothEntity> boothOp;
public BoothDetail getBooth(int boothnum, String categori, String userHash) {
Optional<BoothEntity> boothOp = boothrepository.findByBoothnumAndCategori(boothnum, categori);

Optional<UserBoothEntity> userBoothEntity = userBoothRepository.findByUserIdAndBoothId(userService.getUserByHash(userHash).getId(), boothId);
if(boothOp.isEmpty()){
throw new NoExistException("해당 부스 정보가 없습니다. (id 확인 요망)");
}

Optional<UserBoothEntity> 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))
.build();
}

@Override
public String updateLikes(Long boothId, String userHash) {
public String updateLikes(int boothnum, String categori, String userHash) {

Optional<BoothEntity> boothOp = boothrepository.findByBoothnumAndCategori(boothnum, categori);
if(boothOp.isEmpty()){
throw new NoExistException("해당 부스 정보가 없습니다. (id 확인 요망)");
}

UserEntity user = userService.getUserByHash(userHash);
Optional<UserBoothEntity> userBoothEntity = userBoothRepository.findByUserIdAndBoothId(user.getId(), boothId);
Optional<UserBoothEntity> userBoothEntity = userBoothRepository.findByUserIdAndBoothId(user.getId(), boothOp.get().getId());
UserBoothEntity userBooth;

BoothEntity booth;

if(userBoothEntity.isEmpty()){
Optional<BoothEntity> 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();
Expand All @@ -145,4 +152,14 @@ public BoothEntity findById(Long id){
return boothOp.get();
}
}

@Override
public BoothEntity findByBoothnumAndCategori(int boothnum, String categori){
Optional<BoothEntity> boothOp = boothrepository.findByBoothnumAndCategori(boothnum, categori);
if(boothOp.isEmpty()){
throw new NoExistException(("해당 부스 정보가 없습니다. (id 확인 요망)"));
}else{
return boothOp.get();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Comment>> getExtraCommentPage(
@PathVariable("boothId") Long boothId,
@RequestParam("perpage") int perpage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface UserBoothRepository extends JpaRepository<UserBoothEntity, Long
List<UserBoothEntity> findAllByUserId(Long userId);

Optional<UserBoothEntity> findByUserIdAndBoothId(Long userId, Long BoothId);

}
6 changes: 3 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 7911efd

Please sign in to comment.