Skip to content

Commit

Permalink
Merge pull request #26 from syyling/feat/21
Browse files Browse the repository at this point in the history
[feat] 리뷰 월별 조회 기능 추가
  • Loading branch information
syyling authored May 1, 2024
2 parents 10a26b8 + 7838289 commit 92029a9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,31 @@ public RecordDetailResponse(String rating, String review, LocalDate date, List<S
}
}

@Getter
@NoArgsConstructor
public static class RecordCalendarResponse{
private String rating;
private String review;
private String title;
private String genre;
private String nation;
private String poster;
private String director;
private String year;

@Builder
public RecordCalendarResponse(String rating, String review, String title, String genre,
String nation, String poster, String director, String year) {
this.rating = rating;
this.review = review;
this.title = title;
this.genre = genre;
this.nation = nation;
this.poster = poster;
this.director = director;
this.year = year;
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,17 @@ public static RecordResponse.RecordDetailResponse mapToRecordDetailResponse(Reco
.keywords(keywords)
.build();
}

public static RecordResponse.RecordCalendarResponse mapToRecordCalendarResponse(Record record, Movie movie) {
return RecordResponse.RecordCalendarResponse.builder()
.rating(record.getRating())
.review(record.getReview())
.title(movie.getTitle())
.genre(movie.getGenre())
.nation(movie.getNation())
.poster(movie.getPoster())
.director(movie.getDirector())
.year(movie.getYear())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import com.mookive.mookive_backend.keyword.domain.entity.Keyword;
import com.mookive.mookive_backend.keyword.domain.service.KeywordQueryService;
import com.mookive.mookive_backend.movie.domain.entity.Movie;
import com.mookive.mookive_backend.movie.domain.service.MovieQueryService;
import com.mookive.mookive_backend.record.application.dto.response.RecordResponse;
import com.mookive.mookive_backend.record.application.mapper.RecordMapper;
import com.mookive.mookive_backend.record.domain.entity.Record;
import com.mookive.mookive_backend.record.domain.service.RecordQueryService;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -20,6 +23,7 @@ public class RecordGetService {

private final RecordQueryService recordQueryService;
private final KeywordQueryService keywordQueryService;
private final MovieQueryService movieQueryService;

public RecordResponse.RecordDetailResponse getRecord(Long recordId) {
Record record = recordQueryService.findById(recordId);
Expand All @@ -30,4 +34,44 @@ public RecordResponse.RecordDetailResponse getRecord(Long recordId) {
}
return RecordMapper.mapToRecordDetailResponse(record, keywords);
}

public List<List<RecordResponse.RecordCalendarResponse>> getRecordByCalendar(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<List<RecordResponse.RecordCalendarResponse>> RecordCalendarResponseList = new ArrayList<>(32);
for(int i = 0; i < 32; i++){
RecordCalendarResponseList.add(null);
}
for(Record record : byDateBetween){
Long movieId = record.getMovie().getId();
Movie movie = movieQueryService.findById(movieId);
RecordResponse.RecordCalendarResponse recordCalendarResponse = RecordMapper.mapToRecordCalendarResponse(record, movie);
int dayOfMonth = record.getDate().getDayOfMonth();
if(RecordCalendarResponseList.get(dayOfMonth) != null) {
RecordCalendarResponseList.get(dayOfMonth).add(recordCalendarResponse);
} else {
List<RecordResponse.RecordCalendarResponse> recordCalendarResponseList = new ArrayList<>();
recordCalendarResponseList.add(recordCalendarResponse);
RecordCalendarResponseList.add(dayOfMonth, recordCalendarResponseList);
}
}
return RecordCalendarResponseList;
}

private static LocalDate getLocalDate(String year, String month, String day) {
if(day.equals("31")) {
if(month.equals("2")) {
day = "28";
} else if(month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11")) {
day = "30";
}
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String localDate = year + "-" + month + "-" + day;
return LocalDate.parse(localDate, formatter);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.mookive.mookive_backend.record.domain.entity.Record;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface RecordRepository extends JpaRepository<Record, Long> {

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

List<Record> findByDateBetween(LocalDate startDate, LocalDate endDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

@Service
Expand All @@ -24,4 +26,7 @@ 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mookive.mookive_backend.record.application.service.RecordGetService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -31,4 +32,11 @@ public void deleteRecord(@PathVariable Long recordId) {
recordDeleteService.deleteRecord(recordId);
}

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

}


}

0 comments on commit 92029a9

Please sign in to comment.