Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

입덕포인트 생성, 존재 유무 구현 #74 #109

Merged
merged 16 commits into from
Nov 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: ConflictException, for문 stream으로 변경, #74
hanyMK committed Nov 17, 2023
commit dee5682cae78bf007d4e17cba6f5acbbb941eba0
Original file line number Diff line number Diff line change
@@ -6,12 +6,12 @@
import io.oduck.api.domain.attractionPoint.dto.AttractionPointResDto.*;
import io.oduck.api.domain.attractionPoint.entity.AttractionPoint;
import io.oduck.api.domain.attractionPoint.repository.AttractionPointRepository;

import java.util.List;
import java.util.Optional;

import io.oduck.api.domain.member.entity.Member;
import io.oduck.api.domain.member.repository.MemberRepository;
import io.oduck.api.global.exception.BadRequestException;
import io.oduck.api.global.exception.ConflictException;
import io.oduck.api.global.exception.NotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -59,7 +59,7 @@ public IsAttractionPoint isAttractionPoint(Long memberId, Long animeId) {
@Transactional
public void save(Long memberId, AttractionPointReq req) {
if(checkAttractionPoint(memberId, req.getAnimeId()).getIsAttractionPoint()){
throw new BadRequestException("AttractionPoint is already exists.");
throw new ConflictException("AttractionPoint");
}

Member member = memberRepository.findById(memberId)
@@ -68,16 +68,16 @@ public void save(Long memberId, AttractionPointReq req) {
Anime anime = animeRepository.findById(req.getAnimeId())
.orElseThrow(() -> new NotFoundException("Anime"));

req.getAttractionElements()
.stream()
.map(attractionElement -> AttractionPoint
.builder()
.member(member)
.anime(anime)
.attractionElement(attractionElement)
.build())
.forEach(attractionPointRepository::save);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

동일한 엔티티를 여러번 저장하는 경우, 리스트에 담아서 saveAll로 저장하는 걸 추천 드립니다.

https://maivve.tistory.com/342

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 감사합니다 수정했습니다!


for(int i = 0; i < req.getAttractionElements().size(); i++){
AttractionPoint attractionPoint = AttractionPoint
.builder()
.member(member)
.anime(anime)
.attractionElement(req.getAttractionElements().get(i))
.build();
attractionPointRepository.save(attractionPoint);
}
}

@Override