-
Notifications
You must be signed in to change notification settings - Fork 0
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 syyling/feat/18
[feat] movie 테이블 tagline 필드 추가, Review 테이블명 Record로 변경
- Loading branch information
Showing
26 changed files
with
247 additions
and
237 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
src/main/java/com/mookive/mookive_backend/keyword/application/mapper/KeywordMapper.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
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
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
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
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
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
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
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
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
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
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
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/mookive/mookive_backend/record/application/mapper/RecordMapper.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,31 @@ | ||
package com.mookive.mookive_backend.record.application.mapper; | ||
|
||
import com.mookive.mookive_backend.movie.domain.entity.Movie; | ||
import com.mookive.mookive_backend.record.application.dto.request.RecordRequest; | ||
import com.mookive.mookive_backend.record.application.dto.response.RecordResponse; | ||
import com.mookive.mookive_backend.record.domain.entity.Record; | ||
import com.mookive.mookive_backend.user.domain.entity.User; | ||
|
||
import java.util.List; | ||
|
||
public class RecordMapper { | ||
|
||
public static Record mapToRecord(RecordRequest.RecordCreateRequest recordCreateRequest, Movie movie, User user) { | ||
return Record.builder() | ||
.movie(movie) | ||
.user(user) | ||
.rating(recordCreateRequest.getRating()) | ||
.review(recordCreateRequest.getReview()) | ||
.date(recordCreateRequest.getDate()) | ||
.build(); | ||
} | ||
|
||
public static RecordResponse.RecordDetailResponse mapToRecordDetailResponse(Record record, List<String> keywords) { | ||
return RecordResponse.RecordDetailResponse.builder() | ||
.rating(record.getRating()) | ||
.review(record.getReview()) | ||
.date(record.getDate()) | ||
.keywords(keywords) | ||
.build(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...main/java/com/mookive/mookive_backend/record/application/service/RecordCreateService.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,67 @@ | ||
package com.mookive.mookive_backend.record.application.service; | ||
|
||
|
||
import com.mookive.mookive_backend.keyword.application.mapper.KeywordMapper; | ||
import com.mookive.mookive_backend.keyword.domain.entity.Keyword; | ||
import com.mookive.mookive_backend.keyword.domain.service.KeywordDeleteService; | ||
import com.mookive.mookive_backend.keyword.domain.service.KeywordSaveService; | ||
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.request.RecordRequest; | ||
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 com.mookive.mookive_backend.record.domain.service.RecordSaveService; | ||
import com.mookive.mookive_backend.user.domain.entity.User; | ||
import com.mookive.mookive_backend.user.domain.service.UserQueryService; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class RecordCreateService { | ||
|
||
private final MovieQueryService movieQueryService; | ||
private final UserQueryService userQueryService; | ||
private final RecordSaveService recordSaveService; | ||
private final KeywordSaveService keywordSaveService; | ||
private final KeywordDeleteService keywordDeleteService; | ||
private final RecordQueryService recordQueryService; | ||
|
||
public void createRecord(RecordRequest.RecordCreateRequest recordCreateRequest) { | ||
Long movieId = recordCreateRequest.getMovieId(); | ||
Long userId = recordCreateRequest.getUserId(); | ||
Optional<Record> optionalRecord = recordQueryService.findByUserIdAndMovieId(userId, movieId); | ||
if(optionalRecord.isPresent()){ | ||
Record record = optionalRecord.get(); | ||
LocalDate date = recordCreateRequest.getDate(); | ||
String rating = recordCreateRequest.getRating(); | ||
String review = recordCreateRequest.getReview(); | ||
ArrayList<String> keywords = recordCreateRequest.getKeywords(); | ||
record.updateRecord(rating, review, date); | ||
keywordDeleteService.deleteAllByRecordId(record.getId()); | ||
saveKeywords(keywords, record, movieId); | ||
} | ||
else { | ||
Movie movie = movieQueryService.findById(movieId); | ||
User user = userQueryService.findById(userId); | ||
Record record = RecordMapper.mapToRecord(recordCreateRequest, movie, user); | ||
recordSaveService.saveRecord(record); | ||
ArrayList<String> keywords = recordCreateRequest.getKeywords(); | ||
saveKeywords(keywords, record, movieId); | ||
} | ||
} | ||
|
||
private void saveKeywords(ArrayList<String> keywords, Record record, Long movieId) { | ||
for(String word : keywords){ | ||
Keyword keyword = KeywordMapper.mapToKeyword(record, word, movieId); | ||
keywordSaveService.saveKeyword(keyword); | ||
} | ||
} | ||
} |
Oops, something went wrong.