-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Central-MakeUs/feat/popcornReview
[Feat] 팝콘작 관련 기능 구현
- Loading branch information
Showing
46 changed files
with
1,781 additions
and
131 deletions.
There are no files selected for viewing
70 changes: 64 additions & 6 deletions
70
Api/src/main/java/com/example/api/Popcorn/controller/PopcornController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,77 @@ | ||
package com.example.api.Popcorn.controller; | ||
|
||
import com.example.api.Popcorn.dto.request.PostPopcornReviewRequest; | ||
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.screening.dto.request.PostReviewRequest; | ||
import com.example.domains.popcorn.entity.Popcorn; | ||
import com.example.domains.popcorn.entity.dto.PopcornKeywordResponseDto; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping("/popcorn") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@SecurityRequirement(name = "access-token") | ||
public class PopcornController { | ||
//TODO 지난주 (테스트는 3분) 팝콘작 중 투표수 가장 높았던 것 3개 반환 | ||
//TODO 이번 주 (테스트는 3분) 팝콘작 선정 된 것 저장 -> 스케쥴링? PopCorn | ||
//TODO 5. 팝콘작 리뷰하기 | ||
//TODO 6. 팝콘작 팝콘지수 산출 - 스케쥴링 | ||
private final GetPopcornUseCase getPopcornUseCase; | ||
private final PostPopcornReviewUseCase postPopcornReviewUseCase; | ||
private final GetPopcornReviewUseCase getPopcornReviewUseCase; | ||
|
||
private final GetTopRatedPopcornKeyword getTopRatedPopcornKeyword; | ||
@Operation(summary = "지난주 투표수 가장 높았던 3개 반환. 이번 주 상영작임", description = "이번 주 상영작 3개 가져오기") | ||
@GetMapping | ||
public List<PopcornResponse> getPopcorn() { | ||
return getPopcornUseCase.execute(); | ||
} | ||
|
||
//TODO 5. 팝콘작 리뷰하기, 중복 금지 | ||
@Operation(summary = "특정 팝콘작에에 리뷰 달기", description = "popcorn id가져와서 리뷰하기") | ||
@PostMapping("/review/{popcornId}") | ||
public PopcornReviewResponse reviewOnScreening(@PathVariable("popcornId") Long popcornId, @RequestBody PostPopcornReviewRequest request) { | ||
return postPopcornReviewUseCase.execute(popcornId, request); | ||
} | ||
|
||
|
||
//TODO 7: 팝콘작 팝콘지수 산출 로직 팝콘지수 GET | ||
@Operation(summary = "특정 팝콘작들에 대한 팝콘 지수", description = "popcornId 가져와서 요청하기") | ||
@GetMapping("/rate/{popcornId}") | ||
public int popcornRate(@PathVariable("popcornId") Long popcornId) { | ||
return getPopcornReviewUseCase.getRate(popcornId); | ||
} | ||
|
||
//TODO 팝콘작들에 대한 리뷰 반환 | ||
@Operation(summary = "팝콘작들에 대한 리뷰 반환", description = "popcornId 가져와서 요청하기") | ||
@GetMapping("/reviews/{popcornId}") | ||
public List<PopcornReviewResponse> reviewResponseList(@PathVariable("popcornId") Long popcornId) { | ||
return getPopcornReviewUseCase.execute(popcornId); | ||
} | ||
|
||
//TODO 내가 쓴 팝콘작 리뷰 | ||
@Operation(summary = "팝콘작들에 대한 나의 리뷰 반환", description = "popcornId 가져와서 요청하기") | ||
@GetMapping("/my/reviews") | ||
public List<PopcornReviewResponse> reviewMyResponseList() { | ||
return getPopcornReviewUseCase.getMyReviews(); | ||
} | ||
|
||
|
||
//TODO 8: 팝콘 키워드 Top3 GET | ||
@Operation(summary = "팝콘작들에 대한 나의 리뷰 반환", description = "popcornId 가져와서 요청하기") | ||
@GetMapping("/top-keywords/{popcornId}") | ||
public List<Map.Entry<String, Integer>> reviewMyResponseList(@PathVariable("popcornId") Long popcornId){ | ||
return getTopRatedPopcornKeyword.execute(popcornId); | ||
} | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
Api/src/main/java/com/example/api/Popcorn/dto/request/PostPopcornReviewRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.example.api.Popcorn.dto.request; | ||
|
||
import com.example.domains.popcorn.entity.Popcorn; | ||
import com.example.domains.popcornUser.entity.enums.PopcornNegative; | ||
import com.example.domains.popcornUser.entity.enums.PopcornPositive; | ||
import com.example.domains.screeningReview.entity.enums.Negative; | ||
import com.example.domains.screeningReview.entity.enums.Positive; | ||
import com.example.domains.user.entity.User; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class PostPopcornReviewRequest { | ||
@Schema(defaultValue = "true", description = "관람 여부") | ||
private boolean hasWatched; | ||
@Schema(defaultValue = "true", description = "관람 전 만족도") | ||
private boolean beforeScreening; | ||
@Schema(defaultValue = "true", description = "관람 후 만족도") | ||
private boolean afterScreening; | ||
@Schema(defaultValue = "너무 좋았습니다", description = "텍스트 리뷰") | ||
private String review; | ||
|
||
@Schema(defaultValue = "true", description = "정책 약관") | ||
private boolean hasAgreed; | ||
|
||
@Schema(description = "Positive attributes") | ||
private PopcornPositive popcornPositive; | ||
@Schema(description = "Negative attributes") | ||
private PopcornNegative popcornNegative; | ||
|
||
|
||
@Builder | ||
public PostPopcornReviewRequest(boolean hasWatched, boolean beforeScreening, boolean afterScreening, String review, boolean hasAgreed, PopcornPositive popcornPositive, PopcornNegative popcornNegative) { | ||
this.hasWatched=hasWatched; | ||
this.beforeScreening = beforeScreening; | ||
this.afterScreening = afterScreening; | ||
this.review = review; | ||
this.hasAgreed =hasAgreed; | ||
this.popcornPositive = popcornPositive; | ||
this.popcornNegative = popcornNegative; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Api/src/main/java/com/example/api/Popcorn/dto/response/PopcornResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.example.api.Popcorn.dto.response; | ||
|
||
import com.example.api.diverseMovie.dto.response.DiverseMovieResponse; | ||
import com.example.domains.diverseMovie.entity.dto.DiverseMovieResponseDto; | ||
import com.example.domains.popcorn.entity.Popcorn; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class PopcornResponse { | ||
@Schema(defaultValue = "1", description = "합콘아이디") | ||
private long popcornId; | ||
@Schema(defaultValue = "괴물", description = "영화제목") | ||
private String movieTitle; | ||
|
||
@Schema(defaultValue = "고레에다 히로카즈", description = "영화김독") | ||
private String directorName; | ||
// @Schema(defaultValue = "제 76회 칸 국제영화제에서...", description = "영화포스터 이미지") | ||
// private String detail; | ||
|
||
|
||
@Builder | ||
public PopcornResponse(Long popcornId,String movieTitle,String directorName){ | ||
this.popcornId = popcornId; | ||
this.movieTitle=movieTitle; | ||
this.directorName=directorName; | ||
} | ||
public static PopcornResponse from(Popcorn popcorn){ | ||
return PopcornResponse.builder() | ||
.popcornId(popcorn.getId()) | ||
.movieTitle(popcorn.getMovieTitle()) | ||
.directorName(popcorn.getDirectorName()) | ||
.build(); | ||
|
||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Api/src/main/java/com/example/api/Popcorn/dto/response/PopcornReviewResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.example.api.Popcorn.dto.response; | ||
|
||
import com.example.domains.popcornUser.entity.PopcornUser; | ||
import com.example.domains.popcornUser.entity.enums.PopcornNegative; | ||
import com.example.domains.popcornUser.entity.enums.PopcornPositive; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class PopcornReviewResponse { | ||
@Schema(defaultValue = "true", description = "관람 여부") | ||
private boolean hasWatched; | ||
@Schema(defaultValue = "true", description = "관람 전 만족도") | ||
private boolean beforeScreening; | ||
@Schema(defaultValue = "true", description = "관람 후 만족도") | ||
private boolean afterScreening; | ||
@Schema(defaultValue = "너무 좋았습니다", description = "텍스트 리뷰") | ||
private String review; | ||
|
||
@Schema(defaultValue = "true", description = "정책 약관") | ||
private boolean hasAgreed; | ||
|
||
@Schema(description = "Positive attributes") | ||
private PopcornPositive popcornPositive; | ||
@Schema(description = "Negative attributes") | ||
private PopcornNegative popcornNegative; | ||
|
||
|
||
@Builder | ||
public PopcornReviewResponse(boolean hasWatched, boolean beforeScreening, boolean afterScreening, String review, boolean hasAgreed, PopcornPositive popcornPositive, PopcornNegative popcornNegative) { | ||
this.hasWatched=hasWatched; | ||
this.beforeScreening = beforeScreening; | ||
this.afterScreening = afterScreening; | ||
this.review = review; | ||
this.hasAgreed =hasAgreed; | ||
this.popcornPositive = popcornPositive; | ||
this.popcornNegative = popcornNegative; | ||
} | ||
|
||
public static PopcornReviewResponse from(PopcornUser popcornUser) { | ||
return PopcornReviewResponse.builder() | ||
.hasWatched(popcornUser.isHasWatched()) | ||
.beforeScreening(popcornUser.isBeforeScreening()) | ||
.afterScreening(popcornUser.isAfterScreening()) | ||
.review(popcornUser.getReview()) | ||
.popcornPositive(popcornUser.getPopcornPositive()) | ||
.popcornNegative(popcornUser.getPopcornNegative()) | ||
.build(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Api/src/main/java/com/example/api/Popcorn/service/GetPopcornReviewUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.example.api.Popcorn.service; | ||
|
||
import com.example.adaptor.UseCase; | ||
import com.example.api.Popcorn.dto.response.PopcornReviewResponse; | ||
import com.example.api.config.security.SecurityUtil; | ||
import com.example.domains.popcorn.adaptor.PopcornAdaptor; | ||
import com.example.domains.popcorn.entity.Popcorn; | ||
import com.example.domains.popcornUser.adaptor.PopcornUserAdaptor; | ||
import com.example.domains.popcornUser.entity.PopcornUser; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class GetPopcornReviewUseCase { | ||
private final PopcornUserAdaptor popcornUserAdaptor; | ||
private final PopcornAdaptor popcornAdaptor; | ||
public List<PopcornReviewResponse> execute(Long popcornId) { | ||
List<PopcornUser> popcornUserList = popcornUserAdaptor.findAllByPopcornId(popcornId); | ||
List<PopcornReviewResponse> popcornReviewResponses = new ArrayList<>(); | ||
for (PopcornUser popcornUser : popcornUserList) { | ||
final PopcornReviewResponse newPopcornReview = PopcornReviewResponse.from(popcornUser); | ||
popcornReviewResponses.add(newPopcornReview); | ||
} | ||
return popcornReviewResponses; | ||
} | ||
|
||
public List<PopcornReviewResponse> getMyReviews() { | ||
Long userId = SecurityUtil.getCurrentUserId(); | ||
List<PopcornUser> popcornUserList = popcornUserAdaptor.findAllByUserId(userId); | ||
List<PopcornReviewResponse> popcornReviewResponses = new ArrayList<>(); | ||
|
||
for (PopcornUser popcornUser : popcornUserList) { | ||
final PopcornReviewResponse newPopcornReview = PopcornReviewResponse.from(popcornUser); | ||
popcornReviewResponses.add(newPopcornReview); | ||
} | ||
return popcornReviewResponses; | ||
} | ||
|
||
public int getRate(Long popcornId) { | ||
List<PopcornUser> popcornUsers = popcornUserAdaptor.findAllByPopcornId(popcornId); | ||
int length = popcornUsers.size(); | ||
|
||
if (length == 0) { | ||
// Handle the case where there are no users to avoid division by zero | ||
return 0; // Or you can choose a default value or throw an exception | ||
} | ||
|
||
int totalNumber = popcornAdaptor.findById(popcornId).getPopcornRate(); | ||
|
||
// Perform rounding and return the result | ||
return Math.round((float) totalNumber / length); | ||
|
||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Api/src/main/java/com/example/api/Popcorn/service/GetPopcornUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.example.api.Popcorn.service; | ||
|
||
import com.example.adaptor.UseCase; | ||
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; | ||
import org.springframework.security.core.parameters.P; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
@UseCase | ||
@RequiredArgsConstructor | ||
public class GetPopcornUseCase { | ||
private final PopcornAdaptor popcornAdaptor; | ||
public List<PopcornResponse> execute() { | ||
List<Popcorn> popcornList = popcornAdaptor.findLastWeekPopcorns(); | ||
List<PopcornResponse> response = new ArrayList<>(); | ||
|
||
for(Popcorn popcorn : popcornList) { | ||
final PopcornResponse popcornResponse = PopcornResponse.from(popcorn); | ||
response.add(popcornResponse); | ||
} | ||
return response; | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
Api/src/main/java/com/example/api/Popcorn/service/GetTopRatedPopcornKeyword.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.example.api.Popcorn.service; | ||
|
||
import com.example.adaptor.UseCase; | ||
import com.example.domains.popcorn.adaptor.PopcornAdaptor; | ||
import com.example.domains.popcorn.entity.dto.PopcornKeywordResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class GetTopRatedPopcornKeyword { | ||
private final PopcornAdaptor popcornAdaptor; | ||
public List<Map.Entry<String, Integer>> execute(Long popcornId) { | ||
PopcornKeywordResponseDto keywordList = popcornAdaptor.getTopRatedCounts(popcornId); | ||
|
||
Map<String, Integer> newList = addingToList(keywordList); | ||
// 내림차순으로 정렬 | ||
// Map을 리스트로 변환 | ||
List<Map.Entry<String, Integer>> sortedList = newList.entrySet() | ||
.stream() | ||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) | ||
.limit(3) | ||
.collect(Collectors.toList()); | ||
|
||
|
||
return sortedList; | ||
} | ||
|
||
private Map<String, Integer> addingToList(PopcornKeywordResponseDto keywordList) { | ||
Map<String, Integer> valueMap = new HashMap<>(); | ||
valueMap.put("cineMaster", keywordList.getCineMaster()); | ||
valueMap.put("greatFilming", keywordList.getGreatFilming()); | ||
valueMap.put("pom", keywordList.getPom()); | ||
valueMap.put("animationIsGood", keywordList.getAnimationIsGood()); | ||
valueMap.put("artIsGood", keywordList.getArtIsGood()); | ||
valueMap.put("setIsArt", keywordList.getSetIsArt()); | ||
valueMap.put("custom", keywordList.getCustom()); | ||
valueMap.put("music", keywordList.getMusic()); | ||
valueMap.put("ost", keywordList.getOst()); | ||
valueMap.put("writtenByGod", keywordList.getWrittenByGod()); | ||
valueMap.put("topicIsGood", keywordList.getTopicIsGood()); | ||
valueMap.put("linesAreGood", keywordList.getLinesAreGood()); | ||
valueMap.put("endingIsGood", keywordList.getEndingIsGood()); | ||
valueMap.put("castingIsGood", keywordList.getCastingIsGood()); | ||
valueMap.put("actingIsGood", keywordList.getActingIsGood()); | ||
valueMap.put("chemistryIsGood", keywordList.getChemistryIsGood()); | ||
valueMap.put("iffy", keywordList.getIffy()); | ||
valueMap.put("badEditing", keywordList.getBadEditing()); | ||
valueMap.put("badAngle", keywordList.getBadAngle()); | ||
valueMap.put("badDetail", keywordList.getBadDetail()); | ||
valueMap.put("badColor", keywordList.getBadColor()); | ||
valueMap.put("badCustom", keywordList.getBadCustom()); | ||
valueMap.put("badMusic", keywordList.getBadMusic()); | ||
valueMap.put("badSound", keywordList.getBadSound()); | ||
valueMap.put("badEnding", keywordList.getBadEnding()); | ||
valueMap.put("endingLoose", keywordList.getEndingLoose()); | ||
valueMap.put("noDetail", keywordList.getNoDetail()); | ||
valueMap.put("badTopic", keywordList.getBadTopic()); | ||
valueMap.put("badActing", keywordList.getBadActing()); | ||
valueMap.put("badCasting", keywordList.getBadCasting()); | ||
|
||
return valueMap; | ||
} | ||
|
||
|
||
//TODO Positive먼저 나오게 | ||
} |
Oops, something went wrong.