Skip to content

Commit

Permalink
refactor : programDetail에 유저 좋아요여부 체크 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
MyunghyunNero committed Nov 21, 2023
1 parent 9994d21 commit cbc0f96
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,16 @@ public ResponseEntity<BaseResponse<ProgramPageMainRes>> findProgramsByFilter(
@Operation(summary = "프로그램 세부내용 가져오기")
@GetMapping("/program")
public ResponseEntity<BaseResponse<ProgramDetailRes>> findProgramDetail(
Principal principal,

@Parameter(description = "프로그램 ID")
@RequestParam(value = "id", required = true) Long id
){
return ResponseEntity.ok(new BaseResponse<>(this.programService.getProgramDetail(id)));
String username = null;
if(principal != null) {
username = principal.getName();
}
return ResponseEntity.ok(new BaseResponse<>(this.programService.getProgramDetail(id,username)));
}

@Operation(summary = "프로그램 지역에 맞게 여행 추천해주기")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ProgramDetailRes {

private String location;

private boolean userLikeCheck;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
private LocalDate recruitStartDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public interface ProgramService {

ProgramDetailRes getProgramDetail(Long id);
ProgramDetailRes getProgramDetail(Long id, String username);

ProgramPageMainRes getProgramsByDynamicQuery(ProgramSearchReq programSearchReq, String username);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import kusitms.gallae.domain.Program;
import kusitms.gallae.global.TourApiService;
import kusitms.gallae.global.jwt.JwtProvider;
import kusitms.gallae.repository.favorite.FavoriteRepository;
import kusitms.gallae.repository.program.ProgramRepositoryCustom;
import kusitms.gallae.repository.program.ProgramRepositoryImpl;
import kusitms.gallae.repository.program.ProgramRespository;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class ProgramServiceImpl implements ProgramService {

private final TourApiService tourApiService;

private final FavoriteRepository favoriteRepository;


@Override
public ProgramPageMainRes getProgramsByDynamicQuery(ProgramSearchReq programSearchReq,String username) {
Expand Down Expand Up @@ -105,9 +108,10 @@ public List<ProgramMapRes> getProgramsMap(){
}

@Override
public ProgramDetailRes getProgramDetail(Long id){
public ProgramDetailRes getProgramDetail(Long id, String username){
Program program = programRespository.findById(id).orElse(null);
program.setViewCount(program.getViewCount()+1);

if(program == null) {
throw new BaseException(BaseResponseStatus.BAD_REQUEST);
}else{
Expand All @@ -126,6 +130,13 @@ public ProgramDetailRes getProgramDetail(Long id){
programDetailRes.setTripStartDate(program.getTripStartDate());
programDetailRes.setTripEndDate(program.getTripEndDate());
programDetailRes.setLike(program.getProgramLike());
User user = null;
if(username != null){
user = userRepository.findById(Long.valueOf(username)).orElse(null);
if(user !=null && favoriteRepository.existsByUserAndProgram(user,program)){
programDetailRes.setUserLikeCheck(true);
}
}
programDetailRes.setPhotoUrl(program.getPhotoUrl());
LocalDate localDate = LocalDate.of(program.getRecruitEndDate().getYear(),
program.getRecruitEndDate().getMonth(),program.getRecruitEndDate().getDayOfMonth());
Expand Down

0 comments on commit cbc0f96

Please sign in to comment.