Skip to content

Commit

Permalink
Merge pull request #45 from syyling/feat/40
Browse files Browse the repository at this point in the history
[feat] 캘린더 월별 조회 dto tmdbId 추가, 리뷰 최근 7일 조회 기능 추가, 리뷰 월별 조회 쿼리파라미터 추가
  • Loading branch information
syyling authored May 29, 2024
2 parents ec16ebb + 00bfece commit c1e97c0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public static class RecordCalendarResponse{
private String poster;
private String director;
private String year;
private String tmdbId;

@Builder
public RecordCalendarResponse(String rating, String review, String title, String genre,
String nation, String poster, String director, String year) {
String nation, String poster, String director, String year, String tmdbId) {
this.rating = rating;
this.review = review;
this.title = title;
Expand All @@ -49,6 +50,7 @@ public RecordCalendarResponse(String rating, String review, String title, String
this.poster = poster;
this.director = director;
this.year = year;
this.tmdbId = tmdbId;
}
}

Expand Down Expand Up @@ -79,4 +81,19 @@ public RecordHomeResponse(String tmdbId, String title, String poster) {
this.poster = poster;
}
}

@Getter
@NoArgsConstructor
public static class RecordWeekResponse {
private String tmdbId;
private String title;
private String poster;

@Builder
public RecordWeekResponse(String tmdbId, String title, String poster) {
this.tmdbId = tmdbId;
this.title = title;
this.poster = poster;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static RecordResponse.RecordCalendarResponse mapToRecordCalendarResponse(
.poster(movie.getPoster())
.director(movie.getDirector())
.year(movie.getYear())
.tmdbId(movie.getTmdbId())
.build();
}

Expand All @@ -56,4 +57,12 @@ public static RecordResponse.RecordHomeResponse mapToRecordHomeResponse(Movie mo
.tmdbId(movie.getTmdbId())
.build();
}

public static RecordResponse.RecordWeekResponse mapToRecordWeekResponse(Movie movie) {
return RecordResponse.RecordWeekResponse.builder()
.title(movie.getTitle())
.poster(movie.getPoster())
.tmdbId(movie.getTmdbId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

Expand Down Expand Up @@ -51,12 +52,12 @@ public RecordResponse.RecordDetailResponse getRecord(Long userId, String tmdbId)
}
}

public List<List<RecordResponse.RecordCalendarResponse>> getRecordOfCalender(String year, String month) {
public List<List<RecordResponse.RecordCalendarResponse>> getRecordOfCalender(Long userId, String year, String month) {
String start = "01"; String end = "31";
LocalDate startDate = getLocalDate(year, month, start);
LocalDate endDate = getLocalDate(year, month, end);

List<Record> byDateBetween = recordQueryService.findByDateBetween(startDate, endDate);
List<Record> byDateBetween = recordQueryService.findByUserIdAndDateBetween(userId, startDate, endDate);
List<List<RecordResponse.RecordCalendarResponse>> RecordCalendarResponseList = new ArrayList<>(32);
for(int i = 0; i < 32; i++){
RecordCalendarResponseList.add(null);
Expand Down Expand Up @@ -133,4 +134,15 @@ public List<RecordResponse.RecordHomeResponse> getRecordOfHome(Long userId) {
}
return recordHomeResponseList;
}

public List<RecordResponse.RecordWeekResponse> getRecordWithinWeek(Long userId) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime beforeWeek = LocalDateTime.now().minusWeeks(1);

List<Record> recordList = recordQueryService.findByUserIdAndUpdatedAtBetween(userId, beforeWeek, now);

List<RecordResponse.RecordWeekResponse> recordWithinWeekList = recordList.stream().map(
record -> RecordMapper.mapToRecordWeekResponse(record.getMovie())).toList();
return recordWithinWeekList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface RecordRepository extends JpaRepository<Record, Long> {

Optional<Record> findByUserIdAndMovieId(Long userId, Long movieId);

List<Record> findByDateBetween(LocalDate startDate, LocalDate endDate);
List<Record> findByUserIdAndDateBetween(Long userId, LocalDate startDate, LocalDate endDate);

List<Record> findByUserIdAndUpdatedAtBetween(Long userId, LocalDateTime startDate, LocalDateTime endDate);

List<Record> findTop5ByUserIdOrderByUpdatedAtDesc(Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,8 +28,12 @@ public Optional<Record> findByUserIdAndMovieId(Long userId, Long movieId) {
return recordRepository.findByUserIdAndMovieId(userId, movieId);
}

public List<Record> findByDateBetween(LocalDate startDate, LocalDate endDate) {
return recordRepository.findByDateBetween(startDate, endDate);
public List<Record> findByUserIdAndDateBetween(Long userId, LocalDate startDate, LocalDate endDate) {
return recordRepository.findByUserIdAndDateBetween(userId, startDate, endDate);
}

public List<Record> findByUserIdAndUpdatedAtBetween(Long userId, LocalDateTime startDate, LocalDateTime endDate) {
return recordRepository.findByUserIdAndUpdatedAtBetween(userId, startDate, endDate);
}

public List<Record> findTop5ByUserIdOrderByUpdatedAtDesc(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void deleteRecord(@RequestParam Long userId, @RequestParam Long movieId)
}

@GetMapping("/record/calendar")
public List<List<RecordResponse.RecordCalendarResponse>> getRecordOfCalender(@RequestParam String year, @RequestParam String month) {
return recordGetService.getRecordOfCalender(year, month);
public List<List<RecordResponse.RecordCalendarResponse>> getRecordOfCalender(@RequestParam Long userId, @RequestParam String year, @RequestParam String month) {
return recordGetService.getRecordOfCalender(userId, year, month);
}

@GetMapping("/record/home/recent/{userId}")
Expand All @@ -48,4 +48,9 @@ public List<RecordResponse.RecordHomeResponse> getRecordOfHome(@PathVariable Lon
return recordGetService.getRecordOfHome(userId);
}

@GetMapping("/record/week/{userId}")
public List<RecordResponse.RecordWeekResponse> getRecordWithinWeek(@PathVariable Long userId) {
return recordGetService.getRecordWithinWeek(userId);
}

}

0 comments on commit c1e97c0

Please sign in to comment.