Skip to content

Commit

Permalink
[ADD] BoothLike
Browse files Browse the repository at this point in the history
  • Loading branch information
siksik-Choi committed May 21, 2024
1 parent e554586 commit 8fde405
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import LlikelionKNU.KNUfest.domain.booth.dto.AllBooth;
import LlikelionKNU.KNUfest.domain.booth.dto.BoothDetail;
import LlikelionKNU.KNUfest.domain.booth.dto.BoothLike;
import LlikelionKNU.KNUfest.global.basic.BasicResponse;
import LlikelionKNU.KNUfest.domain.booth.service.BoothService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -39,18 +40,19 @@ public ResponseEntity<BoothDetail> getBooth(

@PatchMapping("{categori}/{boothNum}")
@Operation(summary = "특정 부스 좋아요 업데이트", description = "특정 부스의 좋아요를 변경한다.")
public ResponseEntity<BasicResponse> updateLikes(
public ResponseEntity<BoothLike> updateLikes(
@PathVariable("boothNum") int boothNum,
@PathVariable("categori") String categori,
@RequestParam("userHash") String userHash
){
String message = service.updateLikes(boothNum, categori, userHash);
BasicResponse response = BasicResponse.builder()
.message(message)
.status(200)
.timeStamp(LocalDateTime.now())
.build();
return ResponseEntity.ok().body(response);
BoothLike boothLike= service.updateLikes(boothNum, categori, userHash);
// String message = service.updateLikes(boothNum, categori, userHash);
// BasicResponse response = BasicResponse.builder()
// .message(message)
// .status(200)
// .timeStamp(LocalDateTime.now())
// .build();
return ResponseEntity.ok().body(boothLike);
}

}
15 changes: 15 additions & 0 deletions src/main/java/LlikelionKNU/KNUfest/domain/booth/dto/BoothLike.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package LlikelionKNU.KNUfest.domain.booth.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@Builder
@RequiredArgsConstructor
@AllArgsConstructor
public class BoothLike {
private int likeNum;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import LlikelionKNU.KNUfest.domain.booth.dto.AllBooth;
import LlikelionKNU.KNUfest.domain.booth.dto.BoothDetail;
import LlikelionKNU.KNUfest.domain.booth.dto.BoothLike;
import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity;

public interface BoothService {
AllBooth getAllbooth(String userHash);
BoothDetail getBooth(int boothNum, String categori, String userHash);
String updateLikes(int boothNum, String categori, String userHash);
BoothLike 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 @@ -3,6 +3,7 @@
import LlikelionKNU.KNUfest.domain.booth.dto.AllBooth;
import LlikelionKNU.KNUfest.domain.booth.dto.BoothDetail;
import LlikelionKNU.KNUfest.domain.booth.dto.Booth;
import LlikelionKNU.KNUfest.domain.booth.dto.BoothLike;
import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity;
import LlikelionKNU.KNUfest.domain.booth.repository.BoothRepository;
import LlikelionKNU.KNUfest.domain.comment.service.CommentService;
Expand Down Expand Up @@ -102,7 +103,7 @@ public BoothDetail getBooth(int boothnum, String categori, String userHash) {
}

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

Optional<BoothEntity> boothOp = boothrepository.findByBoothnumAndCategori(boothnum, categori);
if(boothOp.isEmpty()){
Expand All @@ -115,6 +116,9 @@ public String updateLikes(int boothnum, String categori, String userHash) {

BoothEntity booth;

BoothLike boothLikeDto;
String message;

if(userBoothEntity.isEmpty()){

booth = boothOp.get();
Expand All @@ -127,7 +131,9 @@ public String updateLikes(int boothnum, String categori, String userHash) {
.build();

userBoothRepository.save(userBooth);
return "좋아요를 업데이트(+1) 하였습니다.";


message = "좋아요를 업데이트(+1) 하였습니다.";

}else{
booth = userBoothEntity.get().getBooth();
Expand All @@ -136,9 +142,15 @@ public String updateLikes(int boothnum, String categori, String userHash) {

userBoothRepository.delete(userBoothEntity.get());

return "좋아요를 업데이트(-1) 하였습니다.";
message = "좋아요를 업데이트(-1) 하였습니다.";
}

boothLikeDto = BoothLike.builder()
.likeNum(booth.getLikes())
.message(message)
.build();

return boothLikeDto;
}

@Override
Expand Down

0 comments on commit 8fde405

Please sign in to comment.