-
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 #23 from Central-MakeUs/feat/popcorn
[Feat] 독립영화 기능 구현
- Loading branch information
Showing
48 changed files
with
1,428 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.api.Popcorn.controller; | ||
|
||
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; | ||
|
||
@RestController | ||
@RequestMapping("/popcorn") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@SecurityRequirement(name = "access-token") | ||
public class PopcornController { | ||
//TODO 지난주 (테스트는 3분) 팝콘작 중 투표수 가장 높았던 것 3개 반환 | ||
//TODO 이번 주 (테스트는 3분) 팝콘작 선정 된 것 저장 -> 스케쥴링? PopCorn | ||
//TODO 5. 팝콘작 리뷰하기 | ||
//TODO 6. 팝콘작 팝콘지수 산출 - 스케쥴링 | ||
} |
32 changes: 32 additions & 0 deletions
32
Api/src/main/java/com/example/api/diverseMovie/controller/DiverseMovieController.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,32 @@ | ||
package com.example.api.diverseMovie.controller; | ||
|
||
import com.example.api.diverseMovie.dto.response.DiverseMovieResponse; | ||
import com.example.api.diverseMovie.service.GetTopRatedMovies; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/diverse") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class DiverseMovieController { | ||
private final GetTopRatedMovies getTopRatedMovies; | ||
|
||
@GetMapping("/dev") | ||
public void savePopcorn(){ | ||
getTopRatedMovies.getTopRated(); | ||
} | ||
|
||
|
||
//TODO 1. 독립영화 Top5 매 주 월요일 저장 - 스케쥴링 - 완료 | ||
|
||
@GetMapping("/toprated") | ||
public List<DiverseMovieResponse> getDiverseMovies() { | ||
return getTopRatedMovies.getTopratedList(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Api/src/main/java/com/example/api/diverseMovie/dto/response/DiverseMovieResponse.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,34 @@ | ||
package com.example.api.diverseMovie.dto.response; | ||
|
||
import com.example.api.screening.dto.response.BookMarkResponse; | ||
import com.example.domains.diverseMovie.entity.dto.DiverseMovieResponseDto; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DiverseMovieResponse { | ||
@Schema(defaultValue = "괴물", description = "영화제목") | ||
private String movieTitle; | ||
|
||
@Schema(defaultValue = "asfdhihfajsfodhasf.jpg", description = "영화포스터 이미지") | ||
private String imageUrl; | ||
|
||
@Schema(defaultValue = "1", description = "영화 순위") | ||
private String rank; | ||
|
||
@Builder | ||
public DiverseMovieResponse(String movieTitle,String imageUrl, String rank){ | ||
this.movieTitle=movieTitle; | ||
this.imageUrl=imageUrl; | ||
this.rank=rank; | ||
} | ||
public static DiverseMovieResponse from(DiverseMovieResponseDto diverseMovieResponseDto){ | ||
return DiverseMovieResponse.builder() | ||
.movieTitle(diverseMovieResponseDto.getMovieTitle()) | ||
.imageUrl(diverseMovieResponseDto.getMovieImgUrl()) | ||
.rank(diverseMovieResponseDto.getMovieRank()) | ||
.build(); | ||
|
||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
Api/src/main/java/com/example/api/diverseMovie/service/GetTopRatedMovies.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,143 @@ | ||
package com.example.api.diverseMovie.service; | ||
|
||
import com.example.adaptor.UseCase; | ||
import com.example.api.diverseMovie.dto.response.DiverseMovieResponse; | ||
import com.example.domains.diverseMovie.adaptor.DiverseMovieAdaptor; | ||
import com.example.domains.diverseMovie.entity.DiverseMovie; | ||
import com.example.domains.diverseMovie.entity.dto.DiverseMovieResponseDto; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class GetTopRatedMovies { | ||
private final DiverseMovieAdaptor diverseMovieAdaptor; | ||
|
||
public void getTopRated() { | ||
OkHttpClient client = new OkHttpClient(); | ||
// 현재 날짜를 얻어오기 | ||
String currentDate = getFirstDayOfWeek(); | ||
|
||
// URL 구성 | ||
String url = "http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=1eac3f860b5d6af757c4b409321d9f74&multiMovieYn=Y&targetDt=" + currentDate + "&itemPerPage=5"; | ||
|
||
Request request = new Request.Builder() | ||
.url(url) | ||
.build(); | ||
|
||
try { | ||
Response response = client.newCall(request).execute(); | ||
|
||
if (response.isSuccessful()) { | ||
String responseData = response.body().string(); | ||
System.out.println("Response Data:"); | ||
System.out.println(responseData); | ||
saveMovie(responseData); | ||
} else { | ||
System.out.println("Request failed with code: " + response.code()); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
private void saveMovie(String responseData) throws JsonProcessingException { | ||
// JSON 파싱 | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
try { | ||
JsonNode rootNode = objectMapper.readTree(responseData); | ||
JsonNode dailyBoxOfficeList = rootNode.path("boxOfficeResult").path("dailyBoxOfficeList"); | ||
|
||
if (dailyBoxOfficeList.isArray()) { | ||
for (JsonNode movieData : dailyBoxOfficeList) { | ||
String rank = movieData.path("rank").asText(); | ||
String movieNm = movieData.path("movieNm").asText(); | ||
|
||
final DiverseMovie diverseMovie = DiverseMovie.of(movieNm,rank); | ||
diverseMovieAdaptor.save(diverseMovie); | ||
} | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
// 예외 처리 로직 추가 | ||
} | ||
|
||
} | ||
|
||
// public void getImages(String responseData) { | ||
// // JSON 데이터를 BoxOfficeResult 객체로 매핑 | ||
// BoxOfficeResult boxOfficeResult = parseJson(responseData); | ||
// | ||
// // "movieNm" 속성을 가져와서 리스트로 만들기 | ||
// List<String> movieNames = extractMovieNames(boxOfficeResult); | ||
// | ||
// // 결과 출력 | ||
// System.out.println("Movie Names: " + movieNames); | ||
// getImageUrl(movieNames); | ||
// } | ||
|
||
private static String getCurrentDate() { | ||
// 현재 날짜를 문자열로 변환 | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); | ||
return dateFormat.format(new Date()); | ||
} | ||
|
||
private static String getFirstDayOfWeek() { | ||
// 현재 날짜 설정 | ||
Calendar calendar = Calendar.getInstance(); | ||
// 현재 날짜를 그 주의 첫 날(일요일)로 설정 | ||
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); | ||
|
||
// 현재 날짜를 문자열로 변환 | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); | ||
return dateFormat.format(calendar.getTime()); | ||
} | ||
|
||
public List<DiverseMovieResponse> getTopratedList() { | ||
List<DiverseMovieResponseDto> result = diverseMovieAdaptor.findTop5ByOrderByCreatedAtDesc(); | ||
List<DiverseMovieResponse> responseList = new ArrayList<>(); | ||
for (DiverseMovieResponseDto dto : result) { | ||
final DiverseMovieResponseDto responseDto = dto; | ||
DiverseMovieResponse diverseMovieResponse = DiverseMovieResponse.from(dto); | ||
responseList.add(diverseMovieResponse); | ||
} | ||
return responseList; | ||
} | ||
|
||
// private static BoxOfficeResult parseJson(String jsonString) { | ||
// try { | ||
// ObjectMapper objectMapper = new ObjectMapper(); | ||
// return objectMapper.readValue(jsonString, BoxOfficeResult.class); | ||
// } catch (Exception e) { | ||
// e.printStackTrace(); | ||
// return null; | ||
// } | ||
// } | ||
// | ||
// private static List<String> extractMovieNames(BoxOfficeResult boxOfficeResult) { | ||
// List<String> movieNames = new ArrayList<>(); | ||
// if (boxOfficeResult != null && boxOfficeResult.getBoxOfficeResult() != null | ||
// && boxOfficeResult.getBoxOfficeResult().getDailyBoxOfficeList() != null) { | ||
// for (DailyBoxOffice dailyBoxOffice : boxOfficeResult.getBoxOfficeResult().getDailyBoxOfficeList()) { | ||
// if (dailyBoxOffice != null && dailyBoxOffice.getMovieNm() != null) { | ||
// movieNames.add(dailyBoxOffice.getMovieNm()); | ||
// } | ||
// } | ||
// } | ||
// return movieNames; | ||
// } | ||
} |
46 changes: 46 additions & 0 deletions
46
...main/java/com/example/api/recommendedPopcorn/controller/RecommendedPopcornController.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,46 @@ | ||
package com.example.api.recommendedPopcorn.controller; | ||
|
||
import com.example.api.recommendedPopcorn.dto.request.RecommendedPopcornRequest; | ||
import com.example.api.recommendedPopcorn.dto.response.RecommendedPopcornResponse; | ||
import com.example.api.recommendedPopcorn.service.GetRecommendedPopocornUseCase; | ||
import com.example.api.recommendedPopcorn.service.PostRecommendPopcornUseCase; | ||
import com.example.api.recommendedPopcorn.service.PostVoteRecommendedPopcorn; | ||
import com.example.domains.recommendedPopcorn.entity.RecommendedPopcorn; | ||
import com.example.domains.recommendedPopcornUser.entity.RecommendedPopcornUser; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/popcorn/recommend") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@SecurityRequirement(name = "access-token") | ||
public class RecommendedPopcornController { | ||
//TODO 2. 팝콘작 추천하기 - 예비팝콘 - movieId로 분별 (0) | ||
private final PostRecommendPopcornUseCase recommendedPopcornUseCase; | ||
private final GetRecommendedPopocornUseCase getRecommendedPopocornUseCase; | ||
private final PostVoteRecommendedPopcorn postVoteRecommendedPopcorn; | ||
@PostMapping | ||
public void postRecommendPopcorn(@RequestBody RecommendedPopcornRequest request) throws IOException { | ||
recommendedPopcornUseCase.execute(request); | ||
} | ||
// | ||
@GetMapping("/all") | ||
public List<RecommendedPopcorn> getRecommendPopcornList() { | ||
return getRecommendedPopocornUseCase.execute(); | ||
} | ||
|
||
//TODO 4. 예비 팝콘작 투표하기 | ||
@PostMapping("/vote") | ||
public void voteByIdRecommendPopcorn(@RequestParam("recommendedPopcorn") Long recommendedPopcorn) { | ||
postVoteRecommendedPopcorn.execute(recommendedPopcorn); | ||
} | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...c/main/java/com/example/api/recommendedPopcorn/dto/request/RecommendedPopcornRequest.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,24 @@ | ||
package com.example.api.recommendedPopcorn.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class RecommendedPopcornRequest { | ||
@Schema(defaultValue = "1255", description = "영화 id") | ||
private String movieId; | ||
@Schema(defaultValue = "너무 재밌어요", description = "추천하는 이유") | ||
private String reason; | ||
@Schema(defaultValue = "true", description = "게시글 정책 확인 여부") | ||
private boolean isAgreed; | ||
|
||
@Builder | ||
public RecommendedPopcornRequest(String movieId,String reason,boolean isAgreed) { | ||
this.movieId=movieId; | ||
this.reason=reason; | ||
this.isAgreed=isAgreed; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...main/java/com/example/api/recommendedPopcorn/dto/response/RecommendedPopcornResponse.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,7 @@ | ||
package com.example.api.recommendedPopcorn.dto.response; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class RecommendedPopcornResponse { | ||
} |
18 changes: 18 additions & 0 deletions
18
...c/main/java/com/example/api/recommendedPopcorn/service/GetRecommendedPopocornUseCase.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,18 @@ | ||
package com.example.api.recommendedPopcorn.service; | ||
|
||
import com.example.adaptor.UseCase; | ||
import com.example.api.recommendedPopcorn.dto.response.RecommendedPopcornResponse; | ||
import com.example.domains.recommendedPopcorn.adaptor.RecommendedPopcornAdaptor; | ||
import com.example.domains.recommendedPopcorn.entity.RecommendedPopcorn; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class GetRecommendedPopocornUseCase { | ||
private final RecommendedPopcornAdaptor recommendedPopcornAdaptor; | ||
public List<RecommendedPopcorn> execute() { | ||
return recommendedPopcornAdaptor.findAll(); | ||
} | ||
} |
Oops, something went wrong.