-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
82b6dfc
feat: 입덕 포인트 작성, 작성 유무 서비스 메소드 추가 #74
hanyMK d3c6543
feat: 입덕 포인트 작성, 작성 유무 컨트롤러 추가 #74
hanyMK cd601a8
feat: 입덕 포인트 작성 DTO 추가 #74
hanyMK 484d491
refactor: 입덕 포인트 엔티티 수정 메소드 변경 #74
hanyMK 1ccd917
test: 입덕 포인트 생성, 존재 유무 컨트롤러 test 추가 #74
hanyMK a7c7d21
test: 입덕 포인트 생성, 존재 유무 리포지토리 test 추가 #74
hanyMK 6d40157
test: 입덕 포인트 생성, 존재 유무 서비스 test 추가 #74
hanyMK b1205f3
Merge branch 'develop' into feature/74
hanyMK ccc8c70
feat: 입덕포인트 존재 유무 시 반환할 DTO #74
hanyMK b2f55e0
refactor: boolean -> CheckAttractionPoint 로 반환값 변경 #74
hanyMK 55240cb
test: 입덕포인트 존재 유무 test 추가 #74
hanyMK 5f23ae7
docs: 입덕포인트 생성 및 입덕포인트 존재 유무 api문서 작성 #74
hanyMK 9f7e80b
Merge branch 'develop' into feature/74
hanyMK dee5682
refactor: ConflictException, for문 stream으로 변경, #74
hanyMK 59c80cc
Merge branch 'develop' into feature/74
hanyMK 26f1064
refactor: saveAll로 변경하여 저장 #74
hanyMK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
src/main/java/io/oduck/api/domain/attractionPoint/controller/AttractionPointController.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,38 @@ | ||
package io.oduck.api.domain.attractionPoint.controller; | ||
|
||
import io.oduck.api.domain.attractionPoint.dto.AttractionPointReqDto.*; | ||
import io.oduck.api.domain.attractionPoint.service.AttractionPointService; | ||
import io.oduck.api.global.security.auth.dto.AuthUser; | ||
import io.oduck.api.global.security.auth.dto.LoginUser; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Validated | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/attraction-points") | ||
@Slf4j | ||
public class AttractionPointController { | ||
|
||
final AttractionPointService attractionPointService; | ||
|
||
@PostMapping | ||
public ResponseEntity<?> postAttractionPoint( | ||
@LoginUser AuthUser user, | ||
@RequestBody @Valid AttractionPointReq req){ | ||
//TODO: 입덕포인트 작성 | ||
attractionPointService.save(user.getId(), req); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@GetMapping("/{animeId}") | ||
public ResponseEntity<?> getAttractionPoint( | ||
@LoginUser AuthUser user, | ||
@PathVariable("animeId") Long animeId){ | ||
return ResponseEntity.ok(attractionPointService.checkAttractionPoint(user.getId(), animeId)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/io/oduck/api/domain/attractionPoint/dto/AttractionPointReqDto.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,25 @@ | ||
package io.oduck.api.domain.attractionPoint.dto; | ||
|
||
import io.oduck.api.domain.attractionPoint.entity.AttractionElement; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
public class AttractionPointReqDto { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class AttractionPointReq{ | ||
private Long animeId; | ||
@NotNull(message = "입덕포인트를 선택하세요.") | ||
List<AttractionElement> attractionElements; | ||
} | ||
|
||
|
||
} |
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
10 changes: 9 additions & 1 deletion
10
src/main/java/io/oduck/api/domain/attractionPoint/service/AttractionPointService.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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
package io.oduck.api.domain.attractionPoint.service; | ||
|
||
import io.oduck.api.domain.attractionPoint.dto.AttractionPointResDto.IsAttractionPoint; | ||
|
||
import io.oduck.api.domain.attractionPoint.dto.AttractionPointReqDto.*; | ||
import io.oduck.api.domain.attractionPoint.dto.AttractionPointResDto.*; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public interface AttractionPointService { | ||
|
||
//입덕 포인트 추가 | ||
void save(Long memberId, AttractionPointReq req); | ||
|
||
//입덕 포인트 평가 여부 | ||
CheckAttractionPoint checkAttractionPoint(Long memberId, Long animeId); | ||
|
||
//입덕포인트 조회(true/false) | ||
IsAttractionPoint isAttractionPoint(Long memberId, Long animeId); | ||
} |
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 |
---|---|---|
@@ -1,19 +1,32 @@ | ||
package io.oduck.api.domain.attractionPoint.service; | ||
|
||
import io.oduck.api.domain.attractionPoint.dto.AttractionPointResDto.IsAttractionPoint; | ||
import io.oduck.api.domain.anime.entity.Anime; | ||
import io.oduck.api.domain.anime.repository.AnimeRepository; | ||
import io.oduck.api.domain.attractionPoint.dto.AttractionPointReqDto.*; | ||
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.NotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class AttractionPointServiceImpl implements AttractionPointService { | ||
|
||
private final AttractionPointRepository attractionPointRepository; | ||
private final MemberRepository memberRepository; | ||
private final AnimeRepository animeRepository; | ||
|
||
@Override | ||
public IsAttractionPoint isAttractionPoint(Long memberId, Long animeId) { | ||
boolean drawing = false; | ||
|
@@ -41,4 +54,38 @@ public IsAttractionPoint isAttractionPoint(Long memberId, Long animeId) { | |
.voiceActor(voiceActor) | ||
.build(); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void save(Long memberId, AttractionPointReq req) { | ||
if(checkAttractionPoint(memberId, req.getAnimeId()).getIsAttractionPoint()){ | ||
throw new BadRequestException("AttractionPoint is already exists."); | ||
} | ||
|
||
Member member = memberRepository.findById(memberId) | ||
.orElseThrow(() -> new NotFoundException("Member")); | ||
|
||
Anime anime = animeRepository.findById(req.getAnimeId()) | ||
.orElseThrow(() -> new NotFoundException("Anime")); | ||
|
||
|
||
for(int i = 0; i < req.getAttractionElements().size(); i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. steam으로 쓰실 수 있으면 더 좋습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다 수정했습니다! |
||
AttractionPoint attractionPoint = AttractionPoint | ||
.builder() | ||
.member(member) | ||
.anime(anime) | ||
.attractionElement(req.getAttractionElements().get(i)) | ||
.build(); | ||
attractionPointRepository.save(attractionPoint); | ||
} | ||
} | ||
|
||
@Override | ||
public CheckAttractionPoint checkAttractionPoint(Long memberId, Long animeId) { | ||
List<AttractionPoint> findPoint = attractionPointRepository.findAllByAnimeIdAndMemberId(memberId, animeId); | ||
return CheckAttractionPoint | ||
.builder() | ||
.isAttractionPoint(!findPoint.isEmpty()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
중복 -> 충돌 -> 409 ConflictException 쓰시면 됩니다~