diff --git a/src/main/java/com/flickspick/auth/application/TokenService.java b/src/main/java/com/flickspick/auth/application/TokenService.java index 68f0094..a3ef674 100644 --- a/src/main/java/com/flickspick/auth/application/TokenService.java +++ b/src/main/java/com/flickspick/auth/application/TokenService.java @@ -1,5 +1,7 @@ package com.flickspick.auth.application; +import static com.flickspick.auth.AuthConstants.AUTH_TOKEN_HEADER_KEY; + import com.flickspick.auth.model.AuthToken; import com.flickspick.auth.model.AuthUser; import com.flickspick.auth.model.AuthUserImpl; @@ -10,16 +12,13 @@ import io.jsonwebtoken.Jws; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; +import java.util.Date; +import javax.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import javax.servlet.http.HttpServletRequest; -import java.util.Date; - -import static com.flickspick.auth.AuthConstants.AUTH_TOKEN_HEADER_KEY; - @Slf4j @Component @RequiredArgsConstructor diff --git a/src/main/java/com/flickspick/batch/BatchController.java b/src/main/java/com/flickspick/batch/BatchController.java index 0edd296..2335c0a 100644 --- a/src/main/java/com/flickspick/batch/BatchController.java +++ b/src/main/java/com/flickspick/batch/BatchController.java @@ -1,29 +1,23 @@ package com.flickspick.batch; -import java.util.List; - +import com.flickspick.client.chatgpt.ChatGPTClient; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.flickspick.client.chatgpt.ChatGPTClient; -import com.flickspick.rec.dto.RecRequest.QuestionModel; - -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; - @Tag(name = "배치 서비스") @RestController @RequestMapping(path = "/api/v1/batch", produces = MediaType.APPLICATION_JSON_VALUE) @RequiredArgsConstructor public class BatchController { - private final BatchService batchService; - private final ChatGPTClient chatGPTClient; + private final BatchService batchService; + private final ChatGPTClient chatGPTClient; - @PostMapping - public void batch() { - batchService.batch(); - } + @PostMapping + public void batch() { + batchService.batch(); + } } diff --git a/src/main/java/com/flickspick/batch/BatchService.java b/src/main/java/com/flickspick/batch/BatchService.java index 1f0651f..eca72f4 100644 --- a/src/main/java/com/flickspick/batch/BatchService.java +++ b/src/main/java/com/flickspick/batch/BatchService.java @@ -1,10 +1,5 @@ package com.flickspick.batch; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import org.springframework.stereotype.Service; - import com.flickspick.client.chatgpt.ChatGPTClient; import com.flickspick.client.dto.ResponseContent; import com.flickspick.client.dto.ResponseMessage; @@ -12,8 +7,6 @@ import com.flickspick.movie.infrastructure.MovieRepository; import com.flickspick.movie_recommendtype.domain.MovieRecommendType; import com.flickspick.movie_recommendtype.infrastructure.MovieRecommendTypeRepository; -import com.flickspick.user_movie_history.domain.UserMovieHistory; -import com.flickspick.user_movie_history.infrastructure.UserMovieHistoryRepository; import com.flickspick.ott.domain.Ott; import com.flickspick.ott.infrastructure.OttRepository; import com.flickspick.question.domain.Question; @@ -23,81 +16,111 @@ import com.flickspick.rec.dto.RecRequest; import com.flickspick.recommendtype.domain.RecommendType; import com.flickspick.recommendtype.infrastructure.RecommendTypeRepository; - +import com.flickspick.user_movie_history.domain.UserMovieHistory; +import com.flickspick.user_movie_history.infrastructure.UserMovieHistoryRepository; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; @Slf4j @Service @RequiredArgsConstructor public class BatchService { - private final UserMovieHistoryRepository userMovieHistoryRepository; - private final MovieRecommendTypeRepository movieRecommendTypeRepository; - private final RecommendTypeRepository recommendTypeRepository; - private final MovieRepository movieRepository; - private final OttRepository ottRepository; - private final QuestionRepository questionRepository; - private final QuestionAnswerRepository questionAnswerRepository; - private final ChatGPTClient chatGPTClient; - - public void batch() { - log.info("start batch job"); - List ottList = ottRepository.findAll(); - List questionList = questionRepository.findAll(); - AtomicInteger count = new AtomicInteger(0); - for (Question question: questionList) { - List questionAnswerList = questionAnswerRepository.findAllByQuestionId(question.getId()); - for (QuestionAnswer questionAnswer: questionAnswerList) { - List answers = List.of(new RecRequest.QuestionModel(question.getId(), questionAnswer.getId())); - for (Ott ott: ottList) { - List ottIds = List.of(ott.getId()); - try { - count.addAndGet(1); - ResponseMessage responseMessage = chatGPTClient.query(answers, ottIds); - ResponseContent responseContent = responseMessage.getContent(); - RecommendType recommendType = recommendTypeRepository.findByRecommendType( - responseContent.getRecommend_type()) - .orElseThrow(() -> new IllegalArgumentException("RecommendType이 없습니다.")); - Movie movie = Movie.builder() - .title(responseContent.getTitle()) - .reason(responseContent.getReason()) - .plot(responseContent.getPlot()) - .recommendTypeId(recommendType.getId()) - .build(); - movieRepository.save(movie); - UserMovieHistory userMovieHistory = userMovieHistoryRepository.findByRecommendTypeIdAndMovieId( - recommendType.getId(), movie.getId()) - .orElseGet(() -> { - UserMovieHistory newMovieResult = UserMovieHistory.builder() - .recommendTypeId(recommendType.getId()) - .movieId(movie.getId()) - .build(); - return userMovieHistoryRepository.save(newMovieResult); - }); - userMovieHistory.addQuestionAndAnswer(question.getId(), questionAnswer.getId()); - userMovieHistoryRepository.save(userMovieHistory); + private final UserMovieHistoryRepository userMovieHistoryRepository; + private final MovieRecommendTypeRepository movieRecommendTypeRepository; + private final RecommendTypeRepository recommendTypeRepository; + private final MovieRepository movieRepository; + private final OttRepository ottRepository; + private final QuestionRepository questionRepository; + private final QuestionAnswerRepository questionAnswerRepository; + private final ChatGPTClient chatGPTClient; - MovieRecommendType movieRecommendType = MovieRecommendType.builder() - .recommendTypeId(recommendType.getId()) - .movieId(movie.getId()) - .build(); - movieRecommendTypeRepository.save(movieRecommendType); - log.info("성공 질문 count: {}, id: {}, 답변id: {}, ottId: {}", count.get(), question.getId(), questionAnswer.getId(), ott.getId()); - } catch (Exception e) { - if (e instanceof IllegalArgumentException) { - log.info("RecommendType이 없습니다."); - } - log.error("실패 질문 count: {}, id: {}, 답변id: {}, ottId: {}", count.get(), question.getId(), questionAnswer.getId(), ott.getId()); - } - try { - Thread.sleep(22000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - } - } - log.info("finish batch job"); - } + public void batch() { + log.info("start batch job"); + List ottList = ottRepository.findAll(); + List questionList = questionRepository.findAll(); + AtomicInteger count = new AtomicInteger(0); + for (Question question : questionList) { + List questionAnswerList = + questionAnswerRepository.findAllByQuestionId(question.getId()); + for (QuestionAnswer questionAnswer : questionAnswerList) { + List answers = + List.of( + new RecRequest.QuestionModel( + question.getId(), questionAnswer.getId())); + for (Ott ott : ottList) { + List ottIds = List.of(ott.getId()); + try { + count.addAndGet(1); + ResponseMessage responseMessage = chatGPTClient.query(answers, ottIds); + ResponseContent responseContent = responseMessage.getContent(); + RecommendType recommendType = + recommendTypeRepository + .findByRecommendType(responseContent.getRecommend_type()) + .orElseThrow( + () -> + new IllegalArgumentException( + "RecommendType이 없습니다.")); + Movie movie = + Movie.builder() + .title(responseContent.getTitle()) + .reason(responseContent.getReason()) + .plot(responseContent.getPlot()) + .recommendTypeId(recommendType.getId()) + .build(); + movieRepository.save(movie); + UserMovieHistory userMovieHistory = + userMovieHistoryRepository + .findByRecommendTypeIdAndMovieId( + recommendType.getId(), movie.getId()) + .orElseGet( + () -> { + UserMovieHistory newMovieResult = + UserMovieHistory.builder() + .recommendTypeId( + recommendType.getId()) + .movieId(movie.getId()) + .build(); + return userMovieHistoryRepository.save( + newMovieResult); + }); + userMovieHistory.addQuestionAndAnswer( + question.getId(), questionAnswer.getId()); + userMovieHistoryRepository.save(userMovieHistory); + MovieRecommendType movieRecommendType = + MovieRecommendType.builder() + .recommendTypeId(recommendType.getId()) + .movieId(movie.getId()) + .build(); + movieRecommendTypeRepository.save(movieRecommendType); + log.info( + "성공 질문 count: {}, id: {}, 답변id: {}, ottId: {}", + count.get(), + question.getId(), + questionAnswer.getId(), + ott.getId()); + } catch (Exception e) { + if (e instanceof IllegalArgumentException) { + log.info("RecommendType이 없습니다."); + } + log.error( + "실패 질문 count: {}, id: {}, 답변id: {}, ottId: {}", + count.get(), + question.getId(), + questionAnswer.getId(), + ott.getId()); + } + try { + Thread.sleep(22000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + } + log.info("finish batch job"); + } } diff --git a/src/main/java/com/flickspick/client/chatgpt/ChatGPTClient.java b/src/main/java/com/flickspick/client/chatgpt/ChatGPTClient.java index 013a609..a67fed7 100644 --- a/src/main/java/com/flickspick/client/chatgpt/ChatGPTClient.java +++ b/src/main/java/com/flickspick/client/chatgpt/ChatGPTClient.java @@ -1,10 +1,9 @@ package com.flickspick.client.chatgpt; -import java.util.List; - import com.flickspick.client.dto.ResponseMessage; import com.flickspick.rec.dto.RecRequest; +import java.util.List; public interface ChatGPTClient { - ResponseMessage query(List answers, List ottIds); + ResponseMessage query(List answers, List ottIds); } diff --git a/src/main/java/com/flickspick/client/chatgpt/ChatGPTClientImpl.java b/src/main/java/com/flickspick/client/chatgpt/ChatGPTClientImpl.java index 13c54c5..29a7d44 100644 --- a/src/main/java/com/flickspick/client/chatgpt/ChatGPTClientImpl.java +++ b/src/main/java/com/flickspick/client/chatgpt/ChatGPTClientImpl.java @@ -1,18 +1,9 @@ package com.flickspick.client.chatgpt; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Service; -import org.springframework.web.reactive.function.client.WebClient; - import com.flickspick.client.dto.ChatGPTQueryRequest; import com.flickspick.client.dto.ChatGPTQueryResponse; import com.flickspick.client.dto.ChatGPTRole; import com.flickspick.client.dto.RequestMessage; -import com.flickspick.client.dto.ResponseContent; import com.flickspick.client.dto.ResponseMessage; import com.flickspick.common.client.WebClientFactory; import com.flickspick.ott.domain.Ott; @@ -22,62 +13,83 @@ import com.flickspick.question.repository.QuestionAnswerRepository; import com.flickspick.question.repository.QuestionRepository; import com.flickspick.rec.dto.RecRequest.QuestionModel; - +import java.util.ArrayList; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @Slf4j @Service @RequiredArgsConstructor public class ChatGPTClientImpl implements ChatGPTClient { - @Value("${chatgpt.api-key}") - private String apiKey; + @Value("${chatgpt.api-key}") + private String apiKey; - private final OttRepository ottRepository; - private final QuestionRepository questionRepository; - private final QuestionAnswerRepository questionAnswerRepository; + private final OttRepository ottRepository; + private final QuestionRepository questionRepository; + private final QuestionAnswerRepository questionAnswerRepository; - @Override - public ResponseMessage query(List answers, List ottIds) { - WebClient webClient = WebClientFactory.generate("https://api.openai.com/v1/chat/completions", - 20000, - 15000L, - 15000L - ); - List requestMessageList = new ArrayList<>(); - StringBuilder ottNames = new StringBuilder(); - for (Long ottId: ottIds) { - Ott ott = ottRepository.findById(ottId) - .orElseThrow(() -> new IllegalArgumentException("찾는 OTT가 없습니다.")); - if (ottNames.length() > 0) { - ottNames.append(" And "); - } - ottNames.append(ott.getNameEng()); - } - requestMessageList.add(new RequestMessage(ChatGPTRole.SYSTEM.getValue(), "You are an OTT movie recommendation expert. You can recommend movies currently available on OTT services like" + ottNames + ". Please specify the OTT service (e.g., Netflix) and the country (e.g., Korea) for the recommendation. Provide your recommendation in the following format: {\\\"title\\\":\\\"xxx\\\", \\\"reason\\\":\\\"xxx\\\", \\\"plot\\\":\\\"xxx\\\", \\\"recommend_type\\\":\\\"[types 중 1개 선택]\\\"}. Please respond only in Korean.")); - requestMessageList.add(new RequestMessage(ChatGPTRole.SYSTEM.getValue(), "types: ['코난 꿈나무', '방구석 액션전문가', '4계절 내내 여름 공포중독자', '극 I, 평화주의자', '인간 수도꼭지', '영화계의 설민석', '이별중이신가요?', '벚꽃이 보이시나요?']")); + @Override + public ResponseMessage query(List answers, List ottIds) { + WebClient webClient = + WebClientFactory.generate( + "https://api.openai.com/v1/chat/completions", 20000, 15000L, 15000L); + List requestMessageList = new ArrayList<>(); + StringBuilder ottNames = new StringBuilder(); + for (Long ottId : ottIds) { + Ott ott = + ottRepository + .findById(ottId) + .orElseThrow(() -> new IllegalArgumentException("찾는 OTT가 없습니다.")); + if (ottNames.length() > 0) { + ottNames.append(" And "); + } + ottNames.append(ott.getNameEng()); + } + requestMessageList.add( + new RequestMessage( + ChatGPTRole.SYSTEM.getValue(), + "You are an OTT movie recommendation expert. You can recommend movies currently available on OTT services like" + + ottNames + + ". Please specify the OTT service (e.g., Netflix) and the country (e.g., Korea) for the recommendation. Provide your recommendation in the following format: {\\\"title\\\":\\\"xxx\\\", \\\"reason\\\":\\\"xxx\\\", \\\"plot\\\":\\\"xxx\\\", \\\"recommend_type\\\":\\\"[types 중 1개 선택]\\\"}. Please respond only in Korean.")); + requestMessageList.add( + new RequestMessage( + ChatGPTRole.SYSTEM.getValue(), + "types: ['코난 꿈나무', '방구석 액션전문가', '4계절 내내 여름 공포중독자', '극 I, 평화주의자', '인간 수도꼭지', '영화계의 설민석', '이별중이신가요?', '벚꽃이 보이시나요?']")); - for (QuestionModel answer: answers) { - Question question = questionRepository.findById(answer.getQuestionId()) - .orElseThrow(() -> new IllegalArgumentException("찾는 질문이 없습니다.")); - requestMessageList.add(new RequestMessage(ChatGPTRole.USER.getValue(), question.getQuestion())); - QuestionAnswer questionAnswer = questionAnswerRepository.findById(answer.getAnswerId()) - .orElseThrow(() -> new IllegalArgumentException("찾는 질문이 없습니다.")); - requestMessageList.add(new RequestMessage(ChatGPTRole.ASSISTANT.getValue(), questionAnswer.getAnswer())); - } + for (QuestionModel answer : answers) { + Question question = + questionRepository + .findById(answer.getQuestionId()) + .orElseThrow(() -> new IllegalArgumentException("찾는 질문이 없습니다.")); + requestMessageList.add( + new RequestMessage(ChatGPTRole.USER.getValue(), question.getQuestion())); + QuestionAnswer questionAnswer = + questionAnswerRepository + .findById(answer.getAnswerId()) + .orElseThrow(() -> new IllegalArgumentException("찾는 질문이 없습니다.")); + requestMessageList.add( + new RequestMessage( + ChatGPTRole.ASSISTANT.getValue(), questionAnswer.getAnswer())); + } - ChatGPTQueryRequest chatGPTQueryRequest = new ChatGPTQueryRequest( - "gpt-3.5-turbo", - requestMessageList - ); + ChatGPTQueryRequest chatGPTQueryRequest = + new ChatGPTQueryRequest("gpt-3.5-turbo", requestMessageList); - ChatGPTQueryResponse queryResponse = webClient.post() - .header("Authorization", "Bearer " + apiKey) - .body(Mono.just(chatGPTQueryRequest), ChatGPTQueryRequest.class) - .accept(MediaType.APPLICATION_JSON) - .retrieve() - .bodyToMono(ChatGPTQueryResponse.class).block(); - return queryResponse.getChoices().get(0).getMessage(); - } + ChatGPTQueryResponse queryResponse = + webClient + .post() + .header("Authorization", "Bearer " + apiKey) + .body(Mono.just(chatGPTQueryRequest), ChatGPTQueryRequest.class) + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(ChatGPTQueryResponse.class) + .block(); + return queryResponse.getChoices().get(0).getMessage(); + } } diff --git a/src/main/java/com/flickspick/client/dto/ChatGPTChoice.java b/src/main/java/com/flickspick/client/dto/ChatGPTChoice.java index cecbe22..b4a1517 100644 --- a/src/main/java/com/flickspick/client/dto/ChatGPTChoice.java +++ b/src/main/java/com/flickspick/client/dto/ChatGPTChoice.java @@ -8,7 +8,7 @@ @NoArgsConstructor @AllArgsConstructor public class ChatGPTChoice { - private Integer index; - private ResponseMessage message; - private String finish_reason; + private Integer index; + private ResponseMessage message; + private String finish_reason; } diff --git a/src/main/java/com/flickspick/client/dto/ChatGPTQueryRequest.java b/src/main/java/com/flickspick/client/dto/ChatGPTQueryRequest.java index db1a54a..464b3a9 100644 --- a/src/main/java/com/flickspick/client/dto/ChatGPTQueryRequest.java +++ b/src/main/java/com/flickspick/client/dto/ChatGPTQueryRequest.java @@ -1,9 +1,6 @@ package com.flickspick.client.dto; import java.util.List; - -import org.apache.coyote.Request; - import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/flickspick/client/dto/ChatGPTQueryResponse.java b/src/main/java/com/flickspick/client/dto/ChatGPTQueryResponse.java index 29afd95..639e514 100644 --- a/src/main/java/com/flickspick/client/dto/ChatGPTQueryResponse.java +++ b/src/main/java/com/flickspick/client/dto/ChatGPTQueryResponse.java @@ -1,8 +1,6 @@ package com.flickspick.client.dto; import java.util.List; - -import com.flickspick.ott.domain.Ott; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/flickspick/client/dto/ChatGPTRole.java b/src/main/java/com/flickspick/client/dto/ChatGPTRole.java index a123534..9dee8ea 100644 --- a/src/main/java/com/flickspick/client/dto/ChatGPTRole.java +++ b/src/main/java/com/flickspick/client/dto/ChatGPTRole.java @@ -6,10 +6,9 @@ @Getter @AllArgsConstructor public enum ChatGPTRole { - SYSTEM("system"), - USER("user"), - ASSISTANT("assistant") - ; + SYSTEM("system"), + USER("user"), + ASSISTANT("assistant"); - private String value; + private String value; } diff --git a/src/main/java/com/flickspick/client/dto/ChatGPTUsage.java b/src/main/java/com/flickspick/client/dto/ChatGPTUsage.java index 05a63ef..a15358b 100644 --- a/src/main/java/com/flickspick/client/dto/ChatGPTUsage.java +++ b/src/main/java/com/flickspick/client/dto/ChatGPTUsage.java @@ -8,7 +8,7 @@ @NoArgsConstructor @AllArgsConstructor public class ChatGPTUsage { - private Integer prompt_tokens; - private Integer completion_tokens; - private Integer total_tokens; + private Integer prompt_tokens; + private Integer completion_tokens; + private Integer total_tokens; } diff --git a/src/main/java/com/flickspick/client/dto/RequestMessage.java b/src/main/java/com/flickspick/client/dto/RequestMessage.java index 141da7e..34c15f6 100644 --- a/src/main/java/com/flickspick/client/dto/RequestMessage.java +++ b/src/main/java/com/flickspick/client/dto/RequestMessage.java @@ -8,6 +8,6 @@ @NoArgsConstructor @AllArgsConstructor public class RequestMessage { - private String role; - private String content; + private String role; + private String content; } diff --git a/src/main/java/com/flickspick/client/dto/ResponseContent.java b/src/main/java/com/flickspick/client/dto/ResponseContent.java index 505148b..0b2b92c 100644 --- a/src/main/java/com/flickspick/client/dto/ResponseContent.java +++ b/src/main/java/com/flickspick/client/dto/ResponseContent.java @@ -1,6 +1,5 @@ package com.flickspick.client.dto; - import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -9,8 +8,8 @@ @NoArgsConstructor @AllArgsConstructor public class ResponseContent { - private String title; - private String reason; - private String plot; - private String recommend_type; + private String title; + private String reason; + private String plot; + private String recommend_type; } diff --git a/src/main/java/com/flickspick/client/dto/ResponseMessage.java b/src/main/java/com/flickspick/client/dto/ResponseMessage.java index 036a8b5..3f8897c 100644 --- a/src/main/java/com/flickspick/client/dto/ResponseMessage.java +++ b/src/main/java/com/flickspick/client/dto/ResponseMessage.java @@ -8,6 +8,6 @@ @NoArgsConstructor @AllArgsConstructor public class ResponseMessage { - private String role; - private ResponseContent content; + private String role; + private ResponseContent content; } diff --git a/src/main/java/com/flickspick/client/themoviedb/TheMovieDbListModel.java b/src/main/java/com/flickspick/client/themoviedb/TheMovieDbListModel.java index bb71c76..852928a 100644 --- a/src/main/java/com/flickspick/client/themoviedb/TheMovieDbListModel.java +++ b/src/main/java/com/flickspick/client/themoviedb/TheMovieDbListModel.java @@ -1,11 +1,10 @@ package com.flickspick.client.themoviedb; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.List; - @Data @AllArgsConstructor @NoArgsConstructor diff --git a/src/main/java/com/flickspick/client/themoviedb/ThemoviedbClient.java b/src/main/java/com/flickspick/client/themoviedb/ThemoviedbClient.java index a964f3e..6481be7 100644 --- a/src/main/java/com/flickspick/client/themoviedb/ThemoviedbClient.java +++ b/src/main/java/com/flickspick/client/themoviedb/ThemoviedbClient.java @@ -11,15 +11,17 @@ public class ThemoviedbClient { @Value("${themoviedb.api-key}") private String apiKey; - private final WebClient webClient = WebClientFactory - .generate("https://api.themoviedb.org", 20000, 15000L, 15000L); + private final WebClient webClient = + WebClientFactory.generate("https://api.themoviedb.org", 20000, 15000L, 15000L); public TheMovieDbListModel getMovies(int list) { - return webClient.get() + return webClient + .get() .uri("/3/list/" + list + "?language=ko") .header("Authorization", "Bearer " + apiKey) .accept(MediaType.APPLICATION_JSON) .retrieve() - .bodyToMono(TheMovieDbListModel.class).block(); + .bodyToMono(TheMovieDbListModel.class) + .block(); } } diff --git a/src/main/java/com/flickspick/common/client/WebClientFactory.java b/src/main/java/com/flickspick/common/client/WebClientFactory.java index d7861c8..9b7952c 100644 --- a/src/main/java/com/flickspick/common/client/WebClientFactory.java +++ b/src/main/java/com/flickspick/common/client/WebClientFactory.java @@ -3,21 +3,20 @@ import io.netty.channel.ChannelOption; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; +import java.util.concurrent.TimeUnit; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.reactive.function.client.WebClient; import reactor.netty.http.client.HttpClient; -import java.util.concurrent.TimeUnit; - public class WebClientFactory { public static WebClient generate( String baseUrl, Integer connectionTimeoutMillis, Long readTimeoutMillis, - Long writeTimeoutMillis - ) { - var clientHttpConnector = createFactory(connectionTimeoutMillis, readTimeoutMillis, writeTimeoutMillis); + Long writeTimeoutMillis) { + var clientHttpConnector = + createFactory(connectionTimeoutMillis, readTimeoutMillis, writeTimeoutMillis); return WebClient.builder() .baseUrl(baseUrl) .codecs(codecs -> codecs.defaultCodecs().enableLoggingRequestDetails(true)) @@ -26,25 +25,27 @@ public static WebClient generate( } private static ClientHttpConnector createFactory( - Integer connectionTimeoutMillis, - Long readTimeoutMillis, - Long writeTimeoutMillis - ) { + Integer connectionTimeoutMillis, Long readTimeoutMillis, Long writeTimeoutMillis) { var httpClient = httpClient(connectionTimeoutMillis, readTimeoutMillis, writeTimeoutMillis); return new ReactorClientHttpConnector(httpClient); } private static HttpClient httpClient( - Integer connectionTimeoutMillis, - Long readTimeoutMillis, - Long writeTimeoutMillis - ) { - var httpClient = HttpClient.create() - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutMillis) - .doOnConnected(connection -> connection - .addHandlerLast(new ReadTimeoutHandler(readTimeoutMillis, TimeUnit.MILLISECONDS)) - .addHandlerLast(new WriteTimeoutHandler(writeTimeoutMillis, TimeUnit.MILLISECONDS)) - ); + Integer connectionTimeoutMillis, Long readTimeoutMillis, Long writeTimeoutMillis) { + var httpClient = + HttpClient.create() + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutMillis) + .doOnConnected( + connection -> + connection + .addHandlerLast( + new ReadTimeoutHandler( + readTimeoutMillis, + TimeUnit.MILLISECONDS)) + .addHandlerLast( + new WriteTimeoutHandler( + writeTimeoutMillis, + TimeUnit.MILLISECONDS))); httpClient.warmup().block(); httpClient.compress(true); diff --git a/src/main/java/com/flickspick/common/model/entity/BaseEntity.java b/src/main/java/com/flickspick/common/model/entity/BaseEntity.java index 7105d85..52c9479 100644 --- a/src/main/java/com/flickspick/common/model/entity/BaseEntity.java +++ b/src/main/java/com/flickspick/common/model/entity/BaseEntity.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import java.time.LocalDateTime; - import javax.persistence.Column; import javax.persistence.EntityListeners; import javax.persistence.MappedSuperclass; diff --git a/src/main/java/com/flickspick/exception/dto/ErrorType.java b/src/main/java/com/flickspick/exception/dto/ErrorType.java index f201209..0c9d299 100644 --- a/src/main/java/com/flickspick/exception/dto/ErrorType.java +++ b/src/main/java/com/flickspick/exception/dto/ErrorType.java @@ -17,22 +17,20 @@ public enum ErrorType { AUTHORIZATION_ERROR(HttpStatus.UNAUTHORIZED, "인증, 인가 오류"), USER_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "유저 정보를 찾을 수 없습니다."), - //rec + // rec RECOMMEND_TYPE_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "추천 타입을 찾을 수 없습니다."), - //movie + // movie MOVIE_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "영화 정보를 찾을 수 없습니다."), - //movieRecommendType + // movieRecommendType MOVIE_RECOMMEND_TYPE_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "영화 타입 매핑 정보를 찾을 수 없습니다."), - //userMovieHistory + // userMovieHistory USER_MOVIE_HISTORY_NOT_FOUND(HttpStatus.NOT_FOUND, "유저 영화 히스토리를 찾을 수 없습니다."), - //ott + // ott OTT_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "OTT 정보를 찾을 수 없습니다."), - - ; private final HttpStatus status; diff --git a/src/main/java/com/flickspick/exception/movie/MovieNotFoundException.java b/src/main/java/com/flickspick/exception/movie/MovieNotFoundException.java index c71ecec..01b2bbd 100644 --- a/src/main/java/com/flickspick/exception/movie/MovieNotFoundException.java +++ b/src/main/java/com/flickspick/exception/movie/MovieNotFoundException.java @@ -4,7 +4,7 @@ import com.flickspick.exception.dto.ErrorType; public class MovieNotFoundException extends BusinessException { - public MovieNotFoundException(ErrorType errorType) { - super(errorType); - } + public MovieNotFoundException(ErrorType errorType) { + super(errorType); + } } diff --git a/src/main/java/com/flickspick/exception/movie_recommendtype/MovieRecommendTypeNotFoundException.java b/src/main/java/com/flickspick/exception/movie_recommendtype/MovieRecommendTypeNotFoundException.java index d142fb6..6ab3a8e 100644 --- a/src/main/java/com/flickspick/exception/movie_recommendtype/MovieRecommendTypeNotFoundException.java +++ b/src/main/java/com/flickspick/exception/movie_recommendtype/MovieRecommendTypeNotFoundException.java @@ -4,7 +4,7 @@ import com.flickspick.exception.dto.ErrorType; public class MovieRecommendTypeNotFoundException extends BusinessException { - public MovieRecommendTypeNotFoundException(ErrorType errorType) { - super(errorType); - } + public MovieRecommendTypeNotFoundException(ErrorType errorType) { + super(errorType); + } } diff --git a/src/main/java/com/flickspick/exception/ott/OttNotFoundException.java b/src/main/java/com/flickspick/exception/ott/OttNotFoundException.java index af8897a..e5badb6 100644 --- a/src/main/java/com/flickspick/exception/ott/OttNotFoundException.java +++ b/src/main/java/com/flickspick/exception/ott/OttNotFoundException.java @@ -5,7 +5,7 @@ public class OttNotFoundException extends BusinessException { - public OttNotFoundException(ErrorType errorType) { - super(errorType); - } + public OttNotFoundException(ErrorType errorType) { + super(errorType); + } } diff --git a/src/main/java/com/flickspick/exception/rec/RecommendTypeNotFoundException.java b/src/main/java/com/flickspick/exception/rec/RecommendTypeNotFoundException.java index 23d1cc1..ef5982b 100644 --- a/src/main/java/com/flickspick/exception/rec/RecommendTypeNotFoundException.java +++ b/src/main/java/com/flickspick/exception/rec/RecommendTypeNotFoundException.java @@ -4,7 +4,7 @@ import com.flickspick.exception.dto.ErrorType; public class RecommendTypeNotFoundException extends BusinessException { - public RecommendTypeNotFoundException(ErrorType errorType) { - super(errorType); - } + public RecommendTypeNotFoundException(ErrorType errorType) { + super(errorType); + } } diff --git a/src/main/java/com/flickspick/exception/user_movie_history/UserMovieHistoryNotFoundException.java b/src/main/java/com/flickspick/exception/user_movie_history/UserMovieHistoryNotFoundException.java index 9681d26..991d4d5 100644 --- a/src/main/java/com/flickspick/exception/user_movie_history/UserMovieHistoryNotFoundException.java +++ b/src/main/java/com/flickspick/exception/user_movie_history/UserMovieHistoryNotFoundException.java @@ -4,7 +4,7 @@ import com.flickspick.exception.dto.ErrorType; public class UserMovieHistoryNotFoundException extends BusinessException { - public UserMovieHistoryNotFoundException(ErrorType errorType) { - super(errorType); - } + public UserMovieHistoryNotFoundException(ErrorType errorType) { + super(errorType); + } } diff --git a/src/main/java/com/flickspick/home/application/HomeService.java b/src/main/java/com/flickspick/home/application/HomeService.java index 328a1c8..454d15f 100644 --- a/src/main/java/com/flickspick/home/application/HomeService.java +++ b/src/main/java/com/flickspick/home/application/HomeService.java @@ -16,11 +16,10 @@ import com.flickspick.user.model.UserModel; import com.flickspick.user_movie_history.application.UserMovieHistoryService; import com.flickspick.user_movie_history.domain.UserMovieHistory; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - import java.util.List; import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor @@ -33,11 +32,15 @@ public class HomeService { private final UserService userService; public MyHomeResponse getHome(AuthUser authUser) { - var user = userRepository.findById(authUser.getId()) - .orElseThrow(() -> new UserNotFoundException(ErrorType.USER_NOT_FOUND_ERROR)); + var user = + userRepository + .findById(authUser.getId()) + .orElseThrow( + () -> new UserNotFoundException(ErrorType.USER_NOT_FOUND_ERROR)); UserModel userModel = UserModel.from(user); UserMovieHistory userMovieHistory = userMovieHistoryService.getRecentHistory(user.getId()); - RecTypeModel recTypeModel = recommendTypeService.getRecTypeModel(userMovieHistory.getRecommendTypeId()); + RecTypeModel recTypeModel = + recommendTypeService.getRecTypeModel(userMovieHistory.getRecommendTypeId()); List tags = recTypeModel.getTags(); @@ -47,13 +50,15 @@ public MyHomeResponse getHome(AuthUser authUser) { List differentMovies = movieService.getList(userMovieHistory.getMovieId(), 3); - return MyHomeResponse.toResponse(userModel, List.of(recTypeModel), tags, similarMovies, differentMovies); + return MyHomeResponse.toResponse( + userModel, List.of(recTypeModel), tags, similarMovies, differentMovies); } public MyProfileResponse getMyProfile(AuthUser authUser) { var userModel = userService.getUserModel(authUser.getId()); - UserMovieHistory userMovieHistory = userMovieHistoryService.getRecentHistory(userModel.getId()); + UserMovieHistory userMovieHistory = + userMovieHistoryService.getRecentHistory(userModel.getId()); RecTypeModel recTypeModel = recommendTypeService.get(userMovieHistory.getRecommendTypeId()); List tags = recTypeModel.getTags(); @@ -62,10 +67,11 @@ public MyProfileResponse getMyProfile(AuthUser authUser) { MovieModel movieModel = movieService.get(userMovieHistory.getMovieId()); similarMovies.add(movieModel); - List ottModelList = ottService.findAllByUid(userModel.getId()) - .stream() - .map(ottUser -> ottService.get(ottUser.getOttId())) - .collect(Collectors.toList()); - return MyProfileResponse.toResponse(userModel, ottModelList, List.of(recTypeModel), tags, similarMovies); + List ottModelList = + ottService.findAllByUid(userModel.getId()).stream() + .map(ottUser -> ottService.get(ottUser.getOttId())) + .collect(Collectors.toList()); + return MyProfileResponse.toResponse( + userModel, ottModelList, List.of(recTypeModel), tags, similarMovies); } } diff --git a/src/main/java/com/flickspick/home/dto/response/MyHomeResponse.java b/src/main/java/com/flickspick/home/dto/response/MyHomeResponse.java index a1e7bd0..1473b7f 100644 --- a/src/main/java/com/flickspick/home/dto/response/MyHomeResponse.java +++ b/src/main/java/com/flickspick/home/dto/response/MyHomeResponse.java @@ -1,14 +1,12 @@ package com.flickspick.home.dto.response; import com.flickspick.movie.model.MovieModel; -import com.flickspick.ott.model.OttModel; import com.flickspick.recommendtype.model.RecTypeModel; import com.flickspick.user.model.UserModel; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; - @Data @AllArgsConstructor public class MyHomeResponse { @@ -18,7 +16,12 @@ public class MyHomeResponse { private List similarMovies; private List differentMovies; - public static MyHomeResponse toResponse(UserModel user, List recType, List tags, List similarMovies, List differentMovies) { + public static MyHomeResponse toResponse( + UserModel user, + List recType, + List tags, + List similarMovies, + List differentMovies) { return new MyHomeResponse(user, recType, tags, similarMovies, differentMovies); } } diff --git a/src/main/java/com/flickspick/home/dto/response/MyProfileResponse.java b/src/main/java/com/flickspick/home/dto/response/MyProfileResponse.java index 9cc767a..3355e2c 100644 --- a/src/main/java/com/flickspick/home/dto/response/MyProfileResponse.java +++ b/src/main/java/com/flickspick/home/dto/response/MyProfileResponse.java @@ -4,11 +4,10 @@ import com.flickspick.ott.model.OttModel; import com.flickspick.recommendtype.model.RecTypeModel; import com.flickspick.user.model.UserModel; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; - @Data @AllArgsConstructor public class MyProfileResponse { @@ -18,7 +17,12 @@ public class MyProfileResponse { private List tags; private List similarMovies; - public static MyProfileResponse toResponse(UserModel user, List otts, List recType, List tags, List similarMovies) { + public static MyProfileResponse toResponse( + UserModel user, + List otts, + List recType, + List tags, + List similarMovies) { return new MyProfileResponse(user, otts, recType, tags, similarMovies); } } diff --git a/src/main/java/com/flickspick/movie/application/MovieService.java b/src/main/java/com/flickspick/movie/application/MovieService.java index 073b329..77a21de 100644 --- a/src/main/java/com/flickspick/movie/application/MovieService.java +++ b/src/main/java/com/flickspick/movie/application/MovieService.java @@ -2,26 +2,18 @@ import com.flickspick.exception.dto.ErrorType; import com.flickspick.exception.movie.MovieNotFoundException; -import com.flickspick.exception.rec.RecommendTypeNotFoundException; -import com.flickspick.movie.domain.Movie; import com.flickspick.movie.dto.MovieResponse; import com.flickspick.movie.infrastructure.MovieRepository; import com.flickspick.movie.model.MovieModel; -import com.flickspick.recommendtype.model.RecTypeModel; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.concurrent.CompletableFuture; import java.util.function.Function; import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; @Slf4j @Service @@ -38,8 +30,7 @@ public void refreshMovieModels() { } public Map refresh() { - return movieRepository.findAll() - .stream() + return movieRepository.findAll().stream() .map(MovieModel::toModel) .collect(Collectors.toMap(MovieModel::getId, Function.identity())); } @@ -55,10 +46,11 @@ public MovieModel get(Long id) { } public List getList(Long movieId, int count) { - List movieList = movieModels.keySet() - .stream().map(movieModels::get) - .filter(movieModel -> movieModel.getId() != movieId) - .collect(Collectors.toList()); + List movieList = + movieModels.keySet().stream() + .map(movieModels::get) + .filter(movieModel -> movieModel.getId() != movieId) + .collect(Collectors.toList()); Collections.shuffle(movieList); diff --git a/src/main/java/com/flickspick/movie/domain/Movie.java b/src/main/java/com/flickspick/movie/domain/Movie.java index a836f9c..de439a5 100644 --- a/src/main/java/com/flickspick/movie/domain/Movie.java +++ b/src/main/java/com/flickspick/movie/domain/Movie.java @@ -1,18 +1,17 @@ package com.flickspick.movie.domain; import com.flickspick.common.model.entity.BaseEntity; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityListeners; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Entity @NoArgsConstructor diff --git a/src/main/java/com/flickspick/movie/dto/MovieResponse.java b/src/main/java/com/flickspick/movie/dto/MovieResponse.java index 3b76c66..d09b69e 100644 --- a/src/main/java/com/flickspick/movie/dto/MovieResponse.java +++ b/src/main/java/com/flickspick/movie/dto/MovieResponse.java @@ -1,19 +1,17 @@ package com.flickspick.movie.dto; -import java.util.List; - import com.flickspick.movie.model.MovieModel; - +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; @Data @AllArgsConstructor public class MovieResponse { - private MovieModel movie; - private List recMovies; + private MovieModel movie; + private List recMovies; - public static MovieResponse toResponse(MovieModel movieModel, List recMovies) { - return new MovieResponse(movieModel, recMovies); - } + public static MovieResponse toResponse(MovieModel movieModel, List recMovies) { + return new MovieResponse(movieModel, recMovies); + } } diff --git a/src/main/java/com/flickspick/movie/infrastructure/MovieRepository.java b/src/main/java/com/flickspick/movie/infrastructure/MovieRepository.java index 00a3df6..e507316 100644 --- a/src/main/java/com/flickspick/movie/infrastructure/MovieRepository.java +++ b/src/main/java/com/flickspick/movie/infrastructure/MovieRepository.java @@ -5,6 +5,4 @@ import org.springframework.stereotype.Repository; @Repository -public interface MovieRepository extends JpaRepository { - -} +public interface MovieRepository extends JpaRepository {} diff --git a/src/main/java/com/flickspick/movie/model/MovieModel.java b/src/main/java/com/flickspick/movie/model/MovieModel.java index 864ff65..f0277bd 100644 --- a/src/main/java/com/flickspick/movie/model/MovieModel.java +++ b/src/main/java/com/flickspick/movie/model/MovieModel.java @@ -29,7 +29,6 @@ public static MovieModel toModel(Movie movie) { movie.getProducer(), movie.getScenario(), movie.getGrade(), - movie.getImageUrl() - ); + movie.getImageUrl()); } } diff --git a/src/main/java/com/flickspick/movie/presentation/MovieController.java b/src/main/java/com/flickspick/movie/presentation/MovieController.java index b20bc8a..5388b35 100644 --- a/src/main/java/com/flickspick/movie/presentation/MovieController.java +++ b/src/main/java/com/flickspick/movie/presentation/MovieController.java @@ -1,22 +1,18 @@ package com.flickspick.movie.presentation; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - import com.flickspick.auth.model.AuthUser; import com.flickspick.common.model.dto.ResponseDto; -import com.flickspick.home.application.HomeService; import com.flickspick.movie.application.MovieService; import com.flickspick.movie.dto.MovieResponse; -import com.flickspick.movie.model.MovieModel; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @Tag(name = "무비") @RestController diff --git a/src/main/java/com/flickspick/movie_recommendtype/application/MovieRecommendTypeService.java b/src/main/java/com/flickspick/movie_recommendtype/application/MovieRecommendTypeService.java index 7b72001..573efb4 100644 --- a/src/main/java/com/flickspick/movie_recommendtype/application/MovieRecommendTypeService.java +++ b/src/main/java/com/flickspick/movie_recommendtype/application/MovieRecommendTypeService.java @@ -1,15 +1,11 @@ package com.flickspick.movie_recommendtype.application; -import org.springframework.stereotype.Service; - import com.flickspick.movie_recommendtype.infrastructure.MovieRecommendTypeRepository; - import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor public class MovieRecommendTypeService { - private final MovieRecommendTypeRepository movieRecommendTypeRepository; - - + private final MovieRecommendTypeRepository movieRecommendTypeRepository; } diff --git a/src/main/java/com/flickspick/movie_recommendtype/domain/MovieRecommendType.java b/src/main/java/com/flickspick/movie_recommendtype/domain/MovieRecommendType.java index e14da4f..3424c44 100644 --- a/src/main/java/com/flickspick/movie_recommendtype/domain/MovieRecommendType.java +++ b/src/main/java/com/flickspick/movie_recommendtype/domain/MovieRecommendType.java @@ -1,19 +1,16 @@ package com.flickspick.movie_recommendtype.domain; +import com.flickspick.common.model.entity.BaseEntity; import javax.persistence.Entity; import javax.persistence.EntityListeners; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; - -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import com.flickspick.common.model.entity.BaseEntity; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Entity @NoArgsConstructor @@ -22,11 +19,11 @@ @Builder @EntityListeners(AuditingEntityListener.class) public class MovieRecommendType extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - private Long movieId; + private Long movieId; - private Long recommendTypeId; + private Long recommendTypeId; } diff --git a/src/main/java/com/flickspick/movie_recommendtype/infrastructure/MovieRecommendTypeRepository.java b/src/main/java/com/flickspick/movie_recommendtype/infrastructure/MovieRecommendTypeRepository.java index 08283d8..322ccca 100644 --- a/src/main/java/com/flickspick/movie_recommendtype/infrastructure/MovieRecommendTypeRepository.java +++ b/src/main/java/com/flickspick/movie_recommendtype/infrastructure/MovieRecommendTypeRepository.java @@ -1,11 +1,9 @@ package com.flickspick.movie_recommendtype.infrastructure; +import com.flickspick.movie_recommendtype.domain.MovieRecommendType; import java.util.Optional; - import org.springframework.data.jpa.repository.JpaRepository; -import com.flickspick.movie_recommendtype.domain.MovieRecommendType; - public interface MovieRecommendTypeRepository extends JpaRepository { - Optional findByMovieId(Long movieId); + Optional findByMovieId(Long movieId); } diff --git a/src/main/java/com/flickspick/ott/domain/OttUser.java b/src/main/java/com/flickspick/ott/domain/OttUser.java index 53d95a5..5768567 100644 --- a/src/main/java/com/flickspick/ott/domain/OttUser.java +++ b/src/main/java/com/flickspick/ott/domain/OttUser.java @@ -1,17 +1,16 @@ package com.flickspick.ott.domain; import com.flickspick.common.model.entity.BaseEntity; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; @Data @Entity diff --git a/src/main/java/com/flickspick/ott/dto/OttRequest.java b/src/main/java/com/flickspick/ott/dto/OttRequest.java index 3bae1bf..8e31377 100644 --- a/src/main/java/com/flickspick/ott/dto/OttRequest.java +++ b/src/main/java/com/flickspick/ott/dto/OttRequest.java @@ -1,11 +1,10 @@ package com.flickspick.ott.dto; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.RequiredArgsConstructor; -import java.util.List; - @Data @RequiredArgsConstructor @AllArgsConstructor diff --git a/src/main/java/com/flickspick/ott/infrastructure/OttUserRepository.java b/src/main/java/com/flickspick/ott/infrastructure/OttUserRepository.java index 8221940..f66fcc8 100644 --- a/src/main/java/com/flickspick/ott/infrastructure/OttUserRepository.java +++ b/src/main/java/com/flickspick/ott/infrastructure/OttUserRepository.java @@ -1,12 +1,11 @@ package com.flickspick.ott.infrastructure; import com.flickspick.ott.domain.OttUser; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @Repository public interface OttUserRepository extends JpaRepository { @Transactional(readOnly = true) diff --git a/src/main/java/com/flickspick/ott/model/OttModel.java b/src/main/java/com/flickspick/ott/model/OttModel.java index 065ca5f..4fbbcf2 100644 --- a/src/main/java/com/flickspick/ott/model/OttModel.java +++ b/src/main/java/com/flickspick/ott/model/OttModel.java @@ -1,7 +1,6 @@ package com.flickspick.ott.model; import com.flickspick.ott.domain.Ott; - import lombok.AllArgsConstructor; import lombok.Data; @@ -15,6 +14,11 @@ public class OttModel { private String imageUrl; public static OttModel toModel(Ott ott) { - return new OttModel(ott.getId(), ott.getName(), ott.getNameEng(), ott.getDescription(), ott.getImageUrl()); + return new OttModel( + ott.getId(), + ott.getName(), + ott.getNameEng(), + ott.getDescription(), + ott.getImageUrl()); } } diff --git a/src/main/java/com/flickspick/ott/presentation/OttController.java b/src/main/java/com/flickspick/ott/presentation/OttController.java index 265aab4..e310427 100644 --- a/src/main/java/com/flickspick/ott/presentation/OttController.java +++ b/src/main/java/com/flickspick/ott/presentation/OttController.java @@ -32,10 +32,7 @@ public ResponseEntity getAll(@Nullable AuthUser user) { @Operation(summary = "Ott 정보 기록") @PostMapping - public ResponseEntity create( - AuthUser user, - @RequestBody OttRequest request - ) { + public ResponseEntity create(AuthUser user, @RequestBody OttRequest request) { ottService.create(user, request); return ResponseDto.noContent(); } diff --git a/src/main/java/com/flickspick/ott/service/OttService.java b/src/main/java/com/flickspick/ott/service/OttService.java index fba0ceb..4b8d7e1 100644 --- a/src/main/java/com/flickspick/ott/service/OttService.java +++ b/src/main/java/com/flickspick/ott/service/OttService.java @@ -11,17 +11,16 @@ import com.flickspick.ott.infrastructure.OttRepository; import com.flickspick.ott.infrastructure.OttUserRepository; import com.flickspick.ott.model.OttModel; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - @Slf4j @Service @RequiredArgsConstructor @@ -38,8 +37,7 @@ public void refreshOtts() { } public Map refresh() { - return ottRepository.findAll() - .stream() + return ottRepository.findAll().stream() .map(OttModel::toModel) .collect(Collectors.toMap(OttModel::getId, Function.identity())); } @@ -72,11 +70,7 @@ public void create(AuthUser user, OttRequest request) { @Transactional public OttUser saveOttUser(AuthUser user, Ott ott) { return ottUserRepository.save( - OttUser.builder() - .uid(user.getId()) - .ottId(ott.getId()) - .build() - ); + OttUser.builder().uid(user.getId()).ottId(ott.getId()).build()); } public List findAllByUid(Long uid) { @@ -84,7 +78,8 @@ public List findAllByUid(Long uid) { } public Ott findById(Long ottId) { - return ottRepository.findById(ottId) + return ottRepository + .findById(ottId) .orElseThrow(() -> new OttNotFoundException(ErrorType.OTT_NOT_FOUND_ERROR)); } } diff --git a/src/main/java/com/flickspick/question/application/QuestionService.java b/src/main/java/com/flickspick/question/application/QuestionService.java index 5265945..e90b802 100644 --- a/src/main/java/com/flickspick/question/application/QuestionService.java +++ b/src/main/java/com/flickspick/question/application/QuestionService.java @@ -5,42 +5,44 @@ import com.flickspick.question.dto.response.QuestionsResponse; import com.flickspick.question.repository.QuestionAnswerRepository; import com.flickspick.question.repository.QuestionRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - import java.util.Collections; import java.util.function.Function; import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor public class QuestionService { private final QuestionRepository questionRepository; private final QuestionAnswerRepository questionAnswerRepository; - private final static Integer LIMIT_COUNT = 5; + private static final Integer LIMIT_COUNT = 5; public QuestionsResponse getQuestions() { var questions = questionRepository.findAll(); - var questionAnswer = questionAnswerRepository.findAll() - .stream() - .map(q -> new QuestionAnswerResponse( - q.getId(), - q.getQuestionId(), - q.getAnswer() - ) - ).collect(Collectors.toMap(QuestionAnswerResponse::getId, Function.identity())); + var questionAnswer = + questionAnswerRepository.findAll().stream() + .map( + q -> + new QuestionAnswerResponse( + q.getId(), q.getQuestionId(), q.getAnswer())) + .collect( + Collectors.toMap( + QuestionAnswerResponse::getId, Function.identity())); Collections.shuffle(questions); - - var questionAndAnswerModel = questions.stream() - .limit(LIMIT_COUNT) - .map(q -> - QuestionResponse.of( - q, - q.getAnswers().stream().map(questionAnswer::get).collect(Collectors.toList()) - ) - ).collect(Collectors.toList()); + var questionAndAnswerModel = + questions.stream() + .limit(LIMIT_COUNT) + .map( + q -> + QuestionResponse.of( + q, + q.getAnswers().stream() + .map(questionAnswer::get) + .collect(Collectors.toList()))) + .collect(Collectors.toList()); return new QuestionsResponse(questionAndAnswerModel); } diff --git a/src/main/java/com/flickspick/question/domain/Question.java b/src/main/java/com/flickspick/question/domain/Question.java index dbc632e..4f21d9c 100644 --- a/src/main/java/com/flickspick/question/domain/Question.java +++ b/src/main/java/com/flickspick/question/domain/Question.java @@ -2,18 +2,17 @@ import com.flickspick.common.model.converter.LongArrayConverter; import com.flickspick.common.model.entity.BaseEntity; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - +import java.util.List; import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; -import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; @Data @Entity diff --git a/src/main/java/com/flickspick/question/domain/QuestionAnswer.java b/src/main/java/com/flickspick/question/domain/QuestionAnswer.java index d6748cc..175760c 100644 --- a/src/main/java/com/flickspick/question/domain/QuestionAnswer.java +++ b/src/main/java/com/flickspick/question/domain/QuestionAnswer.java @@ -1,17 +1,16 @@ package com.flickspick.question.domain; import com.flickspick.common.model.entity.BaseEntity; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; @Data @Entity diff --git a/src/main/java/com/flickspick/question/dto/response/QuestionResponse.java b/src/main/java/com/flickspick/question/dto/response/QuestionResponse.java index d53a662..22af24b 100644 --- a/src/main/java/com/flickspick/question/dto/response/QuestionResponse.java +++ b/src/main/java/com/flickspick/question/dto/response/QuestionResponse.java @@ -1,11 +1,10 @@ package com.flickspick.question.dto.response; import com.flickspick.question.domain.Question; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; - @Data @AllArgsConstructor public class QuestionResponse { @@ -14,10 +13,6 @@ public class QuestionResponse { private List answers; public static QuestionResponse of(Question question, List answers) { - return new QuestionResponse( - question.getId(), - question.getQuestion(), - answers - ); + return new QuestionResponse(question.getId(), question.getQuestion(), answers); } } diff --git a/src/main/java/com/flickspick/question/dto/response/QuestionsResponse.java b/src/main/java/com/flickspick/question/dto/response/QuestionsResponse.java index a7b0dc6..7551ced 100644 --- a/src/main/java/com/flickspick/question/dto/response/QuestionsResponse.java +++ b/src/main/java/com/flickspick/question/dto/response/QuestionsResponse.java @@ -1,10 +1,9 @@ package com.flickspick.question.dto.response; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; - @Data @AllArgsConstructor public class QuestionsResponse { diff --git a/src/main/java/com/flickspick/question/repository/QuestionAnswerRepository.java b/src/main/java/com/flickspick/question/repository/QuestionAnswerRepository.java index ed77063..6da7699 100644 --- a/src/main/java/com/flickspick/question/repository/QuestionAnswerRepository.java +++ b/src/main/java/com/flickspick/question/repository/QuestionAnswerRepository.java @@ -1,12 +1,11 @@ package com.flickspick.question.repository; -import java.util.List; - import com.flickspick.question.domain.QuestionAnswer; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface QuestionAnswerRepository extends JpaRepository { - List findAllByQuestionId(Long id); + List findAllByQuestionId(Long id); } diff --git a/src/main/java/com/flickspick/question/repository/QuestionRepository.java b/src/main/java/com/flickspick/question/repository/QuestionRepository.java index 4870d40..004baa3 100644 --- a/src/main/java/com/flickspick/question/repository/QuestionRepository.java +++ b/src/main/java/com/flickspick/question/repository/QuestionRepository.java @@ -5,5 +5,4 @@ import org.springframework.stereotype.Repository; @Repository -public interface QuestionRepository extends JpaRepository { -} +public interface QuestionRepository extends JpaRepository {} diff --git a/src/main/java/com/flickspick/rec/application/RecService.java b/src/main/java/com/flickspick/rec/application/RecService.java index 26defb1..85ff32e 100644 --- a/src/main/java/com/flickspick/rec/application/RecService.java +++ b/src/main/java/com/flickspick/rec/application/RecService.java @@ -13,15 +13,13 @@ import com.flickspick.user.application.UserService; import com.flickspick.user_movie_history.application.UserMovieHistoryService; import com.flickspick.user_movie_history.domain.UserMovieHistory; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import org.springframework.stereotype.Service; - import java.security.SecureRandom; import java.util.Map; import java.util.Random; -import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor @@ -37,21 +35,26 @@ public RecResponse get(AuthUser user, RecRequest request) { var userModel = userService.getUserModel(user.getId()); Random rand = new SecureRandom(); - Map questionAndAnswer = request.getAnswers() - .stream() - .collect( - Collectors.toMap( - QuestionModel::getAnswerId, - QuestionModel::getQuestionId, - (a, b) -> b) - ); + Map questionAndAnswer = + request.getAnswers().stream() + .collect( + Collectors.toMap( + QuestionModel::getAnswerId, + QuestionModel::getQuestionId, + (a, b) -> b)); Long movieId = (Math.abs(rand.nextLong()) % movieService.getMovieCount()) + 1; - Long recommendTypeId = movieRecommendTypeRepository.findByMovieId(movieId) - .orElseThrow(() -> new MovieRecommendTypeNotFoundException(ErrorType.MOVIE_RECOMMEND_TYPE_NOT_FOUND_ERROR)) - .getRecommendTypeId(); + Long recommendTypeId = + movieRecommendTypeRepository + .findByMovieId(movieId) + .orElseThrow( + () -> + new MovieRecommendTypeNotFoundException( + ErrorType.MOVIE_RECOMMEND_TYPE_NOT_FOUND_ERROR)) + .getRecommendTypeId(); - UserMovieHistory userMovieHistory = UserMovieHistory.of(user.getId(), recommendTypeId, movieId); + UserMovieHistory userMovieHistory = + UserMovieHistory.of(user.getId(), recommendTypeId, movieId); userMovieHistory.updateQuestionAndAnswer(questionAndAnswer); RecTypeModel recTypeModel = recommendTypeService.get(recommendTypeId); diff --git a/src/main/java/com/flickspick/rec/dto/RecRequest.java b/src/main/java/com/flickspick/rec/dto/RecRequest.java index 20b035b..5bd1a9f 100644 --- a/src/main/java/com/flickspick/rec/dto/RecRequest.java +++ b/src/main/java/com/flickspick/rec/dto/RecRequest.java @@ -1,10 +1,9 @@ package com.flickspick.rec.dto; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; - @Data @AllArgsConstructor public class RecRequest { diff --git a/src/main/java/com/flickspick/rec/dto/RecResponse.java b/src/main/java/com/flickspick/rec/dto/RecResponse.java index a772f7b..eee734a 100644 --- a/src/main/java/com/flickspick/rec/dto/RecResponse.java +++ b/src/main/java/com/flickspick/rec/dto/RecResponse.java @@ -3,11 +3,10 @@ import com.flickspick.movie.model.MovieModel; import com.flickspick.recommendtype.model.RecTypeModel; import com.flickspick.user.model.UserModel; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; - @Data @AllArgsConstructor public class RecResponse { @@ -20,8 +19,7 @@ public static RecResponse toResponse( RecTypeModel recTypeModel, MovieModel movie, List recMovies, - UserModel user - ) { + UserModel user) { return new RecResponse(user, recTypeModel, movie, recMovies); } } diff --git a/src/main/java/com/flickspick/recommendtype/application/RecommendTypeService.java b/src/main/java/com/flickspick/recommendtype/application/RecommendTypeService.java index 3b0ab18..94fbbe3 100644 --- a/src/main/java/com/flickspick/recommendtype/application/RecommendTypeService.java +++ b/src/main/java/com/flickspick/recommendtype/application/RecommendTypeService.java @@ -5,15 +5,14 @@ import com.flickspick.recommendtype.domain.RecommendType; import com.flickspick.recommendtype.infrastructure.RecommendTypeRepository; import com.flickspick.recommendtype.model.RecTypeModel; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - @Slf4j @Service @RequiredArgsConstructor @@ -29,14 +28,18 @@ public void refreshRecTypeModels() { } public RecTypeModel getRecTypeModel(Long recommendTypeId) { - RecommendType recommendType = recommendTypeRepository.findById(recommendTypeId) - .orElseThrow(() -> new RecommendTypeNotFoundException(ErrorType.RECOMMEND_TYPE_NOT_FOUND_ERROR)); + RecommendType recommendType = + recommendTypeRepository + .findById(recommendTypeId) + .orElseThrow( + () -> + new RecommendTypeNotFoundException( + ErrorType.RECOMMEND_TYPE_NOT_FOUND_ERROR)); return RecTypeModel.toModel(recommendType); } public Map refresh() { - return recommendTypeRepository.findAll() - .stream() + return recommendTypeRepository.findAll().stream() .map(RecTypeModel::toModel) .collect(Collectors.toMap(RecTypeModel::getId, Function.identity())); } diff --git a/src/main/java/com/flickspick/recommendtype/domain/RecommendType.java b/src/main/java/com/flickspick/recommendtype/domain/RecommendType.java index 8fa5306..5ca9fff 100644 --- a/src/main/java/com/flickspick/recommendtype/domain/RecommendType.java +++ b/src/main/java/com/flickspick/recommendtype/domain/RecommendType.java @@ -1,21 +1,19 @@ package com.flickspick.recommendtype.domain; -import java.util.List; - import com.flickspick.common.model.converter.StringArrayConverter; import com.flickspick.common.model.entity.BaseEntity; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - +import java.util.List; import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EntityListeners; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Entity @NoArgsConstructor diff --git a/src/main/java/com/flickspick/recommendtype/infrastructure/RecommendTypeRepository.java b/src/main/java/com/flickspick/recommendtype/infrastructure/RecommendTypeRepository.java index f8ca7e6..34bc008 100644 --- a/src/main/java/com/flickspick/recommendtype/infrastructure/RecommendTypeRepository.java +++ b/src/main/java/com/flickspick/recommendtype/infrastructure/RecommendTypeRepository.java @@ -1,13 +1,11 @@ package com.flickspick.recommendtype.infrastructure; +import com.flickspick.recommendtype.domain.RecommendType; import java.util.Optional; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import com.flickspick.recommendtype.domain.RecommendType; - @Repository public interface RecommendTypeRepository extends JpaRepository { - Optional findByRecommendType(String recommendType); + Optional findByRecommendType(String recommendType); } diff --git a/src/main/java/com/flickspick/recommendtype/model/RecTypeModel.java b/src/main/java/com/flickspick/recommendtype/model/RecTypeModel.java index 0ac022e..275d2d7 100644 --- a/src/main/java/com/flickspick/recommendtype/model/RecTypeModel.java +++ b/src/main/java/com/flickspick/recommendtype/model/RecTypeModel.java @@ -1,12 +1,10 @@ package com.flickspick.recommendtype.model; +import com.flickspick.recommendtype.domain.RecommendType; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; - -import com.flickspick.recommendtype.domain.RecommendType; - @Data @AllArgsConstructor public class RecTypeModel { @@ -20,7 +18,6 @@ public static RecTypeModel toModel(RecommendType recommendType) { recommendType.getId(), recommendType.getRecommendType(), recommendType.getTags(), - recommendType.getImageUrl() - ); + recommendType.getImageUrl()); } } diff --git a/src/main/java/com/flickspick/share/application/ShareService.java b/src/main/java/com/flickspick/share/application/ShareService.java index dd66f98..ad4bddd 100644 --- a/src/main/java/com/flickspick/share/application/ShareService.java +++ b/src/main/java/com/flickspick/share/application/ShareService.java @@ -8,13 +8,12 @@ import com.flickspick.share.dto.response.ShareResponse; import com.flickspick.user.application.UserService; import com.flickspick.user_movie_history.application.UserMovieHistoryService; +import java.util.List; +import java.util.concurrent.CompletableFuture; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.concurrent.CompletableFuture; - @Service @RequiredArgsConstructor public class ShareService { @@ -32,17 +31,14 @@ public ShareResponse share(AuthUser authUser) { var userMovieHistory = userMovieHistoryCf.get(); - RecTypeModel recTypeModel = recommendTypeService.getRecTypeModel(userMovieHistory.getRecommendTypeId()); + RecTypeModel recTypeModel = + recommendTypeService.getRecTypeModel(userMovieHistory.getRecommendTypeId()); List similarMovies = movieService.getList(userMovieHistory.getMovieId(), 2); MovieModel movieModel = movieService.get(userMovieHistory.getMovieId()); similarMovies.add(movieModel); return new ShareResponse( - userCf.get(), - List.of(recTypeModel), - recTypeModel.getTags(), - similarMovies - ); + userCf.get(), List.of(recTypeModel), recTypeModel.getTags(), similarMovies); } } diff --git a/src/main/java/com/flickspick/share/dto/response/ShareResponse.java b/src/main/java/com/flickspick/share/dto/response/ShareResponse.java index 913b9bd..42bec4c 100644 --- a/src/main/java/com/flickspick/share/dto/response/ShareResponse.java +++ b/src/main/java/com/flickspick/share/dto/response/ShareResponse.java @@ -3,11 +3,10 @@ import com.flickspick.movie.model.MovieModel; import com.flickspick.recommendtype.model.RecTypeModel; import com.flickspick.user.model.UserModel; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; - @Data @AllArgsConstructor public class ShareResponse { diff --git a/src/main/java/com/flickspick/user/application/UserService.java b/src/main/java/com/flickspick/user/application/UserService.java index 478ff9d..e1eea5f 100644 --- a/src/main/java/com/flickspick/user/application/UserService.java +++ b/src/main/java/com/flickspick/user/application/UserService.java @@ -10,13 +10,12 @@ import com.flickspick.user.dto.response.UserSignResponse; import com.flickspick.user.infrastructure.UserRepository; import com.flickspick.user.model.UserModel; +import java.util.concurrent.CompletableFuture; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.concurrent.CompletableFuture; - @Service @RequiredArgsConstructor public class UserService { @@ -55,8 +54,11 @@ public UserResponse get(AuthUser authUser, Long id) { } public UserModel getUserModel(Long id) { - var user = userRepository.findById(id) - .orElseThrow(() -> new UserNotFoundException(ErrorType.USER_NOT_FOUND_ERROR)); + var user = + userRepository + .findById(id) + .orElseThrow( + () -> new UserNotFoundException(ErrorType.USER_NOT_FOUND_ERROR)); return UserModel.from(user); } diff --git a/src/main/java/com/flickspick/user/model/UserModel.java b/src/main/java/com/flickspick/user/model/UserModel.java index 40dfe83..112872c 100644 --- a/src/main/java/com/flickspick/user/model/UserModel.java +++ b/src/main/java/com/flickspick/user/model/UserModel.java @@ -12,10 +12,6 @@ public class UserModel { private String nickname; public static UserModel from(User user) { - return new UserModel( - user.getId(), - user.getUsername(), - user.getNickname() - ); + return new UserModel(user.getId(), user.getUsername(), user.getNickname()); } } diff --git a/src/main/java/com/flickspick/user_movie_history/application/UserMovieHistoryService.java b/src/main/java/com/flickspick/user_movie_history/application/UserMovieHistoryService.java index e73c424..a3b8a8b 100644 --- a/src/main/java/com/flickspick/user_movie_history/application/UserMovieHistoryService.java +++ b/src/main/java/com/flickspick/user_movie_history/application/UserMovieHistoryService.java @@ -4,13 +4,12 @@ import com.flickspick.exception.user_movie_history.UserMovieHistoryNotFoundException; import com.flickspick.user_movie_history.domain.UserMovieHistory; import com.flickspick.user_movie_history.infrastructure.UserMovieHistoryRepository; +import java.util.concurrent.CompletableFuture; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.concurrent.CompletableFuture; - @Service @RequiredArgsConstructor public class UserMovieHistoryService { @@ -22,11 +21,16 @@ public UserMovieHistory saveUserMovieHistory(UserMovieHistory userMovieHistory) } public UserMovieHistory getRecentHistory(Long userId) { - var userMovieHistory = userMovieHistoryRepository.findTopByUserIdOrderByCreatedAtDesc(userId); + var userMovieHistory = + userMovieHistoryRepository.findTopByUserIdOrderByCreatedAtDesc(userId); if (userMovieHistory.isEmpty()) { - return userMovieHistoryRepository.findTop1ByOrderByCreatedAtDesc() - .orElseThrow(() -> new UserMovieHistoryNotFoundException(ErrorType.USER_MOVIE_HISTORY_NOT_FOUND)); + return userMovieHistoryRepository + .findTop1ByOrderByCreatedAtDesc() + .orElseThrow( + () -> + new UserMovieHistoryNotFoundException( + ErrorType.USER_MOVIE_HISTORY_NOT_FOUND)); } return userMovieHistory.get(); diff --git a/src/main/java/com/flickspick/user_movie_history/domain/UserMovieHistory.java b/src/main/java/com/flickspick/user_movie_history/domain/UserMovieHistory.java index e80a7bc..2d13777 100644 --- a/src/main/java/com/flickspick/user_movie_history/domain/UserMovieHistory.java +++ b/src/main/java/com/flickspick/user_movie_history/domain/UserMovieHistory.java @@ -1,24 +1,20 @@ package com.flickspick.user_movie_history.domain; +import com.flickspick.common.model.converter.MapConverter; +import com.flickspick.common.model.entity.BaseEntity; import java.util.HashMap; import java.util.Map; - import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EntityListeners; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; - -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import com.flickspick.common.model.converter.MapConverter; -import com.flickspick.common.model.entity.BaseEntity; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Entity @NoArgsConstructor @@ -27,35 +23,35 @@ @Builder @EntityListeners(AuditingEntityListener.class) public class UserMovieHistory extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - private Long userId; + private Long userId; - @Convert(converter = MapConverter.class) - private Map questionAndAnswer; + @Convert(converter = MapConverter.class) + private Map questionAndAnswer; - private Long recommendTypeId; + private Long recommendTypeId; - private Long movieId; + private Long movieId; - public static UserMovieHistory of(Long userId, Long recommendTypeId, Long movieId) { - return UserMovieHistory.builder() - .userId(userId) - .recommendTypeId(recommendTypeId) - .movieId(movieId) - .build(); - } + public static UserMovieHistory of(Long userId, Long recommendTypeId, Long movieId) { + return UserMovieHistory.builder() + .userId(userId) + .recommendTypeId(recommendTypeId) + .movieId(movieId) + .build(); + } - public void addQuestionAndAnswer(Long questionId, Long answerId) { - if (questionAndAnswer == null) { - questionAndAnswer = new HashMap<>(); - } - questionAndAnswer.put(questionId, answerId); - } + public void addQuestionAndAnswer(Long questionId, Long answerId) { + if (questionAndAnswer == null) { + questionAndAnswer = new HashMap<>(); + } + questionAndAnswer.put(questionId, answerId); + } - public void updateQuestionAndAnswer(Map questionAndAnswer) { - this.questionAndAnswer = questionAndAnswer; - } + public void updateQuestionAndAnswer(Map questionAndAnswer) { + this.questionAndAnswer = questionAndAnswer; + } } diff --git a/src/main/java/com/flickspick/user_movie_history/infrastructure/UserMovieHistoryRepository.java b/src/main/java/com/flickspick/user_movie_history/infrastructure/UserMovieHistoryRepository.java index 4d59766..f83525e 100644 --- a/src/main/java/com/flickspick/user_movie_history/infrastructure/UserMovieHistoryRepository.java +++ b/src/main/java/com/flickspick/user_movie_history/infrastructure/UserMovieHistoryRepository.java @@ -1,9 +1,8 @@ package com.flickspick.user_movie_history.infrastructure; import com.flickspick.user_movie_history.domain.UserMovieHistory; -import org.springframework.data.jpa.repository.JpaRepository; - import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; public interface UserMovieHistoryRepository extends JpaRepository { Optional findByRecommendTypeIdAndMovieId(Long recommendTypeId, Long movieId);