-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#63 스탬프 기능 구현 #64
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
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1389fd8
feat: Stamp 엔티티 생성
1winhyun 17baa9a
feat: StampRepository 구현
1winhyun d38cf0f
refactor: Review 생성 Response DTO에 해당 유저의 스탬프 수 추가
1winhyun bf68938
refactor: getCreateResult 메서드 해당 유저의 스탬프 개수 반환 로직 추가
1winhyun 7f722b8
feat: 스탬프 부여 로직 구현 및 리뷰 작성 로직에 이를 추가
1winhyun d6cf754
feat: User 엔티티에 isRewardNeeded 컬럼 추가 및 스탬프 10개 획득 시 해당 컬럼을 true로 바꾸도록 구현
1winhyun d83fc38
refactor: RewardNeeded 컬럼명 수정
1winhyun fd1aabe
refactor: rewardNeeded 컬럼명 수정
1winhyun f3e06ca
feat: 관리자 전용 스탬프 보상이 필요한 유저 목록 조회 기능 구현
1winhyun ec0594c
feat: 관리자 전용 스탬프 보상 제공 기능 구현
1winhyun 4e4e68f
feat: 사용자의 스탬프 보상 조회 기능 구현
1winhyun ca51498
feat: 사용자의 스탬프 개수 및 스탬프 받은 리뷰 조회 기능 구현
1winhyun 315da79
feat: rewardNeeded가 바뀌는 조건문 수정
1winhyun d94d70c
refactor: grantRewardToUser 누락된 @RequestBody 어노테이션 추가
1winhyun 2f1e8e8
refactor: 필드명 오류 camelCase 적용
1winhyun 599a53a
refactor: getStampRewardNeededUserList N+1 문제 해결
1winhyun 6dd074c
refactor: 스탬프 보상이 필요한 유저 목록 조회 기능 api 앤드포인트 수정
1winhyun ea9f0d0
refactor: 미사용 의존성, 메서드 제거
1winhyun 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/com/campus/campus/domain/manager/application/dto/request/RewardRequest.java
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.campus.campus.domain.manager.application.dto.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record RewardRequest( | ||
| @NotBlank | ||
| @Schema(description = "보상으로 지급 이미지 url", example = "https://www.example.com.png") | ||
| String rewardImageUrl | ||
| ) { | ||
| } |
18 changes: 18 additions & 0 deletions
18
...pus/campus/domain/manager/application/dto/response/StampRewardNeededUserListResponse.java
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.campus.campus.domain.manager.application.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record StampRewardNeededUserListResponse( | ||
| @Schema(description = "보상 지급이 필요한 사용자 ID", example = "1") | ||
| Long userId, | ||
|
|
||
| @Schema(description = "보상 지급이 필요한 사용자 이름", example = "한승현") | ||
| String nickname, | ||
|
|
||
| @Schema(description = "사용자의 스탬프 수", example = "10") | ||
| int stampCount, | ||
|
|
||
| @Schema(description = "사용자가 보상이 필요한지 여부", example = "true") | ||
| boolean rewardNeeded | ||
| ) { | ||
| } |
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 |
|---|---|---|
|
|
@@ -14,15 +14,23 @@ | |
| import com.campus.campus.domain.council.domain.repository.StudentCouncilRepository; | ||
| import com.campus.campus.domain.manager.application.dto.request.CouncilApproveOrDenyRequest; | ||
| import com.campus.campus.domain.manager.application.dto.request.ManagerLoginRequest; | ||
| import com.campus.campus.domain.manager.application.dto.request.RewardRequest; | ||
| import com.campus.campus.domain.manager.application.dto.response.CertifyRequestCouncilResponse; | ||
| import com.campus.campus.domain.manager.application.dto.response.CouncilApproveOrDenyResponse; | ||
| import com.campus.campus.domain.manager.application.dto.response.CertifyRequestCouncilListResponse; | ||
| import com.campus.campus.domain.manager.application.dto.response.ManagerLoginResponse; | ||
| import com.campus.campus.domain.manager.application.dto.response.StampRewardNeededUserListResponse; | ||
| import com.campus.campus.domain.manager.application.exception.ManagerNotFoundException; | ||
| import com.campus.campus.domain.manager.application.exception.PasswordNotCorrectException; | ||
| import com.campus.campus.domain.manager.application.mapper.ManagerMapper; | ||
| import com.campus.campus.domain.manager.domain.entity.Manager; | ||
| import com.campus.campus.domain.manager.domain.repository.ManagerRepository; | ||
| import com.campus.campus.domain.stamp.domain.entity.Reward; | ||
| import com.campus.campus.domain.stamp.domain.repository.RewardRepository; | ||
| import com.campus.campus.domain.stamp.domain.repository.StampRepository; | ||
| import com.campus.campus.domain.user.application.exception.UserNotFoundException; | ||
| import com.campus.campus.domain.user.domain.entity.User; | ||
| import com.campus.campus.domain.user.domain.repository.UserRepository; | ||
| import com.campus.campus.global.util.jwt.JwtProvider; | ||
| import com.campus.campus.global.util.jwt.application.service.RedisTokenService; | ||
|
|
||
|
|
@@ -34,6 +42,9 @@ | |
| public class ManagerService { | ||
| private final StudentCouncilRepository studentCouncilRepository; | ||
| private final ManagerRepository managerRepository; | ||
| private final UserRepository userRepository; | ||
| private final StampRepository stampRepository; | ||
| private final RewardRepository rewardRepository; | ||
| private final PasswordEncoder passwordEncoder; | ||
| private final JwtProvider jwtProvider; | ||
| private final RedisTokenService redisTokenService; | ||
|
|
@@ -96,6 +107,31 @@ public CertifyRequestCouncilResponse getCertifyRequestCouncil(Long councilId) { | |
| return managerMapper.toCertifyRequestCouncilResponse(studentCouncil); | ||
| } | ||
|
|
||
| public List<StampRewardNeededUserListResponse> getStampRewardNeededUserList() { | ||
| List<Object[]> rewardNeededUsers = userRepository.findRewardNeededUsersWithStampCount(); | ||
|
|
||
| return rewardNeededUsers.stream() | ||
| .map(rewardNeededUser -> { | ||
| User user = (User)rewardNeededUser[0]; | ||
| Long count = (Long)rewardNeededUser[1]; | ||
|
|
||
| return managerMapper.toStampRewardNeededUserListResponse(user, count.intValue()); | ||
| } | ||
| ).toList(); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void grantRewardToUser(Long userId, RewardRequest rewardRequest) { | ||
| User user = userRepository.findByIdAndDeletedAtIsNull(userId) | ||
| .orElseThrow(UserNotFoundException::new); | ||
|
|
||
| Reward reward = managerMapper.createReward(user, rewardRequest); | ||
|
|
||
| rewardRepository.save(reward); | ||
|
|
||
| user.updateRewardNeeded(false); | ||
| } | ||
|
Comment on lines
+121
to
+131
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. 보상 지급 전 현재 구현은 🛠️ 권장 수정 예시 `@Transactional`
public void grantRewardToUser(Long userId, RewardRequest rewardRequest) {
User user = userRepository.findByIdAndDeletedAtIsNull(userId)
.orElseThrow(UserNotFoundException::new);
+ if (!user.isRewardNeeded()) {
+ throw new IllegalStateException("해당 사용자는 보상 대상이 아닙니다.");
+ }
+
Reward reward = managerMapper.createReward(user, rewardRequest);
rewardRepository.save(reward);
user.updateRewardNeeded(false);
}🤖 Prompt for AI Agents |
||
|
|
||
| private void sendCouncilApprovedMail(String to) { | ||
| SimpleMailMessage message = new SimpleMailMessage(); | ||
| message.setTo(to); | ||
|
|
||
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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/campus/campus/domain/stamp/application/dto/response/RewardResponse.java
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.campus.campus.domain.stamp.application.dto.response; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record RewardResponse( | ||
| @Schema(description = "보상 id", example = "1") | ||
| Long rewardId, | ||
|
|
||
| @Schema(description = "보상 이미지 url", example = "https://www.example.com.png") | ||
| String rewardImageUrl, | ||
|
|
||
| @Schema(description = "지급일") | ||
| LocalDateTime rewardDate | ||
| ) { | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/campus/campus/domain/stamp/application/dto/response/StampInfoResponse.java
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.campus.campus.domain.stamp.application.dto.response; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record StampInfoResponse( | ||
| @Schema(description = "스탬프 개수", example = "3") | ||
| int stampCount, | ||
|
|
||
| @Schema(description = "스탬프에 해당하는 리뷰 목록") | ||
| List<StampReviewResponse> reviews | ||
| ) { | ||
| } |
17 changes: 17 additions & 0 deletions
17
...ain/java/com/campus/campus/domain/stamp/application/dto/response/StampReviewResponse.java
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.campus.campus.domain.stamp.application.dto.response; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record StampReviewResponse( | ||
| @Schema(description = "리뷰 id", example = "1") | ||
| Long reviewId, | ||
|
|
||
| @Schema(description = "리뷰 장소 이름", example = "투썸 플레이스") | ||
| String placeName, | ||
|
|
||
| @Schema(description = "리뷰 작성 시간", example = "2024-01-10T18:00:00") | ||
| LocalDateTime reviewCreatedAt | ||
| ) { | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/campus/campus/domain/stamp/application/mapper/StampMapper.java
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.campus.campus.domain.stamp.application.mapper; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.campus.campus.domain.review.domain.entity.Review; | ||
| import com.campus.campus.domain.stamp.application.dto.response.RewardResponse; | ||
| import com.campus.campus.domain.stamp.application.dto.response.StampReviewResponse; | ||
| import com.campus.campus.domain.stamp.domain.entity.Reward; | ||
| import com.campus.campus.domain.stamp.domain.entity.Stamp; | ||
| import com.campus.campus.domain.user.domain.entity.User; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class StampMapper { | ||
| public RewardResponse toRewardResponse(Reward reward) { | ||
| return new RewardResponse( | ||
| reward.getRewardId(), | ||
| reward.getRewardImageUrl(), | ||
| reward.getCreatedAt() | ||
| ); | ||
| } | ||
|
|
||
| public StampReviewResponse toStampReviewResponse(Stamp stamp) { | ||
| Review review = stamp.getReview(); | ||
|
|
||
| return new StampReviewResponse( | ||
| review.getId(), | ||
| review.getPlace().getPlaceName(), | ||
| review.getCreatedAt() | ||
| ); | ||
| } | ||
|
|
||
| public Stamp createStamp(User user, Review review) { | ||
| return Stamp.builder() | ||
| .user(user) | ||
| .review(review) | ||
| .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.
Uh oh!
There was an error while loading. Please reload this page.