Skip to content

Commit

Permalink
Merge pull request #33 from Central-MakeUs/fix/popcornGet
Browse files Browse the repository at this point in the history
[fix]팝콘 추천작 반환
  • Loading branch information
AlmondBreez3 authored Jan 29, 2024
2 parents fcbc91d + 08033c2 commit d8c7939
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.example.api.Popcorn.controller;

import com.example.api.Popcorn.dto.request.PostPopcornReviewRequest;
import com.example.api.Popcorn.dto.response.PopcornDetailResponse;
import com.example.api.Popcorn.dto.response.PopcornResponse;
import com.example.api.Popcorn.dto.response.PopcornReviewResponse;
import com.example.api.Popcorn.service.GetPopcornReviewUseCase;
import com.example.api.Popcorn.service.GetPopcornUseCase;
import com.example.api.Popcorn.service.GetTopRatedPopcornKeyword;
import com.example.api.Popcorn.service.PostPopcornReviewUseCase;
import com.example.api.Popcorn.service.*;
import com.example.api.screening.dto.request.PostReviewRequest;
import com.example.domains.popcorn.entity.Popcorn;
import com.example.domains.popcorn.entity.dto.PopcornKeywordResponseDto;
Expand All @@ -30,12 +28,19 @@ public class PopcornController {
private final GetPopcornReviewUseCase getPopcornReviewUseCase;

private final GetTopRatedPopcornKeyword getTopRatedPopcornKeyword;
private final GetPopcornDetailUseCase getPopcornDetailUseCase;
@Operation(summary = "지난주 투표수 가장 높았던 3개 반환. 이번 주 상영작임", description = "이번 주 상영작 3개 가져오기")
@GetMapping
public List<PopcornResponse> getPopcorn() {
return getPopcornUseCase.execute();
}

@Operation(summary = "이번 주 팝콘작 상세보기", description = "popcornId로 요청하기")
@GetMapping("/{popcornId}")
public PopcornDetailResponse getPopcornDetail(@PathVariable("popcornId") Long popcornId) {
return getPopcornDetailUseCase.execute(popcornId);
}

@Operation(summary = "지난 10분 간 만들어진 것들 중에서, 투표수 가장 높았던 3개 반환. 이번 주 상영작임", description = "이번 주 상영작 3개 가져오기")
@GetMapping("/test")
public List<PopcornResponse> getPopcornTest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.api.Popcorn.dto.response;

import com.example.domains.popcorn.entity.Popcorn;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;

@Getter
public class PopcornDetailResponse {
@Schema(defaultValue = "1", description = "합콘아이디")
private long popcornId;
@Schema(defaultValue = "괴물", description = "영화제목")
private String movieTitle;

@Schema(defaultValue = "고레에다 히로카즈", description = "영화김독")
private String directorName;
@Schema(defaultValue = "gfhffgvgvghdfhdchj.jpg", description = "영화포스터 이미지")
private String imageUrl;

@Schema(defaultValue = "agsdfgsdgfsdfgdf", description = "영화 상세 보기")
private String detail;

@Builder
public PopcornDetailResponse (Long popcornId,String movieTitle,String directorName,String imageUrl,String detail){
this.popcornId = popcornId;
this.movieTitle=movieTitle;
this.directorName=directorName;
this.imageUrl = imageUrl;
this.detail=detail;
}
public static PopcornDetailResponse from(Popcorn popcorn){
return PopcornDetailResponse.builder()
.popcornId(popcorn.getId())
.movieTitle(popcorn.getMovieTitle())
.directorName(popcorn.getDirectorName())
.imageUrl(popcorn.getImageUrl())
.detail(popcorn.getMovieDetail())
.build();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.api.Popcorn.service;

import com.example.adaptor.UseCase;
import com.example.api.Popcorn.dto.response.PopcornDetailResponse;
import com.example.api.Popcorn.dto.response.PopcornResponse;
import com.example.domains.popcorn.adaptor.PopcornAdaptor;
import com.example.domains.popcorn.entity.Popcorn;
import lombok.RequiredArgsConstructor;

@UseCase
@RequiredArgsConstructor
public class GetPopcornDetailUseCase {
private final PopcornAdaptor popcornAdaptor;
public PopcornDetailResponse execute(Long id) {
Popcorn popcorn = popcornAdaptor.findById(id);
return PopcornDetailResponse.from(popcorn);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ public void incrementVoteCount(Long recommendedPopcorn) {

public List<RecommendedPopcorn> findByThreeIds() {
List<RecommendedPopcorn> result = new ArrayList<>();
if(recommendedPopcornRepository.findAll().size()<=3) {
List<RecommendedPopcorn> thisWeekList = findAllThisWeek();

if(thisWeekList.size()<=3) {
return recommendedPopcornRepository.findAll();
}
Set<Long> numberArray = generate();
Set<Long> numberArray = generate(thisWeekList);
for (Long number : numberArray) {
Optional<RecommendedPopcorn> foundItem = recommendedPopcornRepository.findById(number);

Expand All @@ -76,11 +78,11 @@ public List<RecommendedPopcorn> findByThreeIds() {
}
return result;
}
public Set<Long> generate() {
public Set<Long> generate(List<RecommendedPopcorn> thisWeekList) {
Set<Long> arr = new HashSet<>();
Random random = new Random();
while (arr.size()!=3) {
Long randomIndex = random.nextLong(1,recommendedPopcornRepository.findAll().size()+1);
Long randomIndex = random.nextLong(thisWeekList.get(0).getId(),recommendedPopcornRepository.findAll().size()+1);
arr.add(randomIndex);
}
return arr;
Expand Down

0 comments on commit d8c7939

Please sign in to comment.