-
Notifications
You must be signed in to change notification settings - Fork 3
[MERGE] dev -> main #408
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
Closed
[MERGE] dev -> main #408
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import stackpot.stackpot.badge.repository.PotMemberBadgeRepository; | ||
| import stackpot.stackpot.pot.entity.mapping.PotMember; | ||
| import stackpot.stackpot.pot.repository.PotMemberRepository; | ||
| import stackpot.stackpot.task.service.TaskQueryService; | ||
| import stackpot.stackpot.todo.entity.enums.TodoStatus; | ||
| import stackpot.stackpot.todo.repository.UserTodoRepository; | ||
|
|
||
|
|
@@ -29,12 +30,11 @@ public class BadgeServiceImpl implements BadgeService { | |
| private final PotMemberRepository potMemberRepository; | ||
| private final PotMemberBadgeRepository potMemberBadgeRepository; | ||
| private final PotBadgeMemberConverter potBadgeMemberConverter; | ||
|
|
||
| private static final Long DEFAULT_BADGE_ID = 1L; | ||
| private final TaskQueryService taskQueryService; | ||
|
|
||
| @Override | ||
| public Badge getDefaultBadge() { | ||
| return badgeRepository.findBadgeByBadgeId(DEFAULT_BADGE_ID) | ||
| public Badge getBadge(Long badgeId) { | ||
| return badgeRepository.findBadgeByBadgeId(badgeId) | ||
| .orElseThrow(() -> new PotHandler(BADGE_NOT_FOUND)); | ||
| } | ||
|
|
||
|
|
@@ -57,10 +57,10 @@ public void assignBadgeToTopMembers(Long potId) { | |
| List<PotMember> topPotMembers = topUserIds.stream() | ||
| .map(userId -> potMemberRepository.findByPot_PotIdAndUser_Id(potId, userId) | ||
| .orElseThrow(() -> new PotHandler(ErrorStatus.POT_MEMBER_NOT_FOUND))) | ||
| .collect(Collectors.toList()); | ||
| .toList(); | ||
|
|
||
| // 4. 기본 배지 부여 | ||
| Badge badge = getDefaultBadge(); | ||
| // 4. Todo 배지 부여 | ||
| Badge badge = getBadge(1L); | ||
| for (PotMember potMember : topPotMembers) { | ||
| PotMemberBadge potMemberBadge = PotMemberBadge.builder() | ||
| .badge(badge) | ||
|
|
@@ -69,5 +69,27 @@ public void assignBadgeToTopMembers(Long potId) { | |
| potMemberBadgeRepository.save(potMemberBadge); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void assignTaskBadgeToTopMembers(Long potId) { | ||
| List<Long> potMemberIds = potMemberRepository.selectPotMemberIdsByPotId(potId); | ||
| if (potMemberIds.isEmpty()) { | ||
| throw new PotHandler(ErrorStatus.POT_MEMBER_NOT_FOUND); | ||
| } | ||
|
|
||
| List<PotMember> top2PotMembers = taskQueryService.getTop2TaskCountByPotMemberId(potMemberIds); | ||
| if (top2PotMembers.size() < 2) { | ||
| throw new PotHandler(ErrorStatus.BADGE_INSUFFICIENT_TOP_MEMBERS); | ||
| } | ||
|
|
||
| Badge badge = getBadge(2L); | ||
| for (PotMember potMember : top2PotMembers) { | ||
| PotMemberBadge potMemberBadge = PotMemberBadge.builder() | ||
| .badge(badge) | ||
| .potMember(potMember) | ||
| .build(); | ||
| potMemberBadgeRepository.save(potMemberBadge); | ||
| } | ||
| } | ||
|
Comment on lines
+73
to
+93
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. 🛠️ Refactor suggestion [중요] 트랜잭션/멱등성/배치 저장 개선
권장 패치: @Override
- public void assignTaskBadgeToTopMembers(Long potId) {
+ @Transactional
+ public void assignTaskBadgeToTopMembers(Long potId) {
List<Long> potMemberIds = potMemberRepository.selectPotMemberIdsByPotId(potId);
- if (potMemberIds.isEmpty()) {
+ if (potMemberIds.isEmpty()) {
throw new PotHandler(ErrorStatus.POT_MEMBER_NOT_FOUND);
}
List<PotMember> top2PotMembers = taskQueryService.getTop2TaskCountByPotMemberId(potMemberIds);
if (top2PotMembers.size() < 2) {
throw new PotHandler(ErrorStatus.BADGE_INSUFFICIENT_TOP_MEMBERS);
}
- Badge badge = getBadge(2L);
- for (PotMember potMember : top2PotMembers) {
- PotMemberBadge potMemberBadge = PotMemberBadge.builder()
- .badge(badge)
- .potMember(potMember)
- .build();
- potMemberBadgeRepository.save(potMemberBadge);
- }
+ Badge badge = getBadge(2L); // 또는 상수/코드명 사용
+ // 멱등성: 이미 보유한 대상 제외
+ List<PotMemberBadge> newBadges = top2PotMembers.stream()
+ .filter(pm -> !potMemberBadgeRepository.existsByBadgeAndPotMember(badge, pm))
+ .map(pm -> PotMemberBadge.builder().badge(badge).potMember(pm).build())
+ .collect(Collectors.toList());
+ if (!newBadges.isEmpty()) {
+ potMemberBadgeRepository.saveAll(newBadges);
+ }
}Repository 보조 메서드(외부 파일 추가 필요): // PotMemberBadgeRepository.java
boolean existsByBadgeAndPotMember(Badge badge, PotMember potMember);🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
💡 Verification agent
🧩 Analysis chain
신규 Task 배지 부여 API: 트랜잭션/권한/멱등성 점검 필요
assignTaskBadgeToTopMembers는 트랜잭션 애노테이션이 없습니다. 배지 생성이 다건으로 수행되므로 전체 작업의 원자성을 위해@Transactional적용이 필요합니다(서비스 파일에서 제안 패치 포함).원하시면 엔드투엔드 테스트/보안 설정 점검까지 같이 도와드리겠습니다.
서비스 레이어에 트랜잭션 애노테이션 적용 여부 및 컨트롤러 보안 설정 검증을 위해 아래 스크립트를 실행해주세요.
🏁 Script executed:
Length of output: 4709
트랜잭션·권한·멱등성 보강 필요
아래 사항을 반영해 주세요.
• 서비스 레이어에
@Transactional적용BadgeServiceImpl클래스나assignTaskBadgeToTopMembers메서드에 반드시 트랜잭션 경계를 지정해야 합니다.예시:
또는
• 권한 검사(@PreAuthorize) 추가
• 멱등성 보장 로직 또는 DB 제약
(pot_member_id, badge_id)같은 유니크 제약을 추가하세요.원하시면 엔드투엔드 테스트 작성 및 스프링 시큐리티 설정 점검도 함께 도와드리겠습니다.