-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] #627 솝탬프 조회 API 변경 #628
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
Changes from 14 commits
caef44c
6e3f2f9
7cdacaf
5a35c23
eae87d9
1e08aa6
8cb7c9c
f10774b
899af04
4ffb09a
41006ca
4869e7b
0c348ee
ae1be7d
8fbfbdf
d13bef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,47 +2,53 @@ | |
|
|
||
| import java.util.List; | ||
|
|
||
| import java.util.Objects; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import lombok.val; | ||
| import org.sopt.app.application.mission.MissionInfo.Level; | ||
| import org.sopt.app.application.mission.MissionService; | ||
| import org.sopt.app.application.soptamp.*; | ||
| import org.sopt.app.application.stamp.ClapService; | ||
| import org.sopt.app.application.stamp.StampInfo; | ||
| import org.sopt.app.application.stamp.StampInfo.Stamp; | ||
| import org.sopt.app.application.stamp.StampInfo.StampView; | ||
| import org.sopt.app.application.stamp.StampService; | ||
| import org.sopt.app.domain.entity.soptamp.Mission; | ||
| import org.sopt.app.presentation.rank.*; | ||
| import org.sopt.app.presentation.stamp.StampRequest; | ||
| import org.sopt.app.presentation.stamp.StampRequest.RegisterStampRequest; | ||
| import org.sopt.app.presentation.stamp.StampResponse; | ||
| import org.sopt.app.presentation.stamp.StampResponse.SoptampReportResponse; | ||
| import org.sopt.app.presentation.stamp.StampResponseMapper; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @Transactional(readOnly = true) | ||
| @RequiredArgsConstructor | ||
| public class SoptampFacade { | ||
|
|
||
| private final StampService stampService; | ||
| private final MissionService missionService; | ||
| private final SoptampUserService soptampUserService; | ||
| private final RankResponseMapper rankResponseMapper; | ||
| private final SoptampUserFinder soptampUserFinder; | ||
| private final ClapService clapService; | ||
|
|
||
| private final RankResponseMapper rankResponseMapper; | ||
|
|
||
| @Value("${makers.app.soptamp.report.url}") | ||
| private String formUrl; | ||
|
|
||
| @Transactional | ||
| public Stamp uploadStamp(Long userId, RegisterStampRequest registerStampRequest){ | ||
| public StampInfo.StampView uploadStamp(Long userId, RegisterStampRequest registerStampRequest){ | ||
| stampService.checkDuplicateStamp(userId, registerStampRequest.getMissionId()); | ||
| Stamp result = stampService.uploadStamp(registerStampRequest, userId); | ||
| Level mission = missionService.getMissionById(registerStampRequest.getMissionId()); | ||
| soptampUserService.addPointByLevel(userId, mission.getLevel()); | ||
| return result; | ||
|
|
||
| return StampInfo.StampView.of(result, 0, true); | ||
| } | ||
|
|
||
| @Transactional | ||
|
|
@@ -70,9 +76,15 @@ public SoptampUserInfo editSoptampUserProfileMessage(Long userId, String newProf | |
| return soptampUserService.editProfileMessage(userId, newProfileMessage); | ||
| } | ||
|
|
||
| public Stamp getStampInfo(Long missionId, String nickname){ | ||
| val userId = soptampUserFinder.findByNickname(nickname).getUserId(); | ||
| return stampService.findStamp(missionId, userId); | ||
| public StampInfo.StampView getStampInfo(Long requestUserId, Long missionId, String nickname){ | ||
| val soptampUserId = soptampUserFinder.findByNickname(nickname).getUserId(); | ||
| val stamp = stampService.findStamp(missionId, soptampUserId); | ||
| val requestUserClapCount = clapService.getUserClapCount(requestUserId, stamp.getId()); | ||
|
|
||
| stampService.increaseViewCountById(stamp.getId()); | ||
|
|
||
| return StampInfo.StampView.of( | ||
| stamp, requestUserClapCount, Objects.equals(requestUserId, soptampUserId)); | ||
|
Comment on lines
+81
to
+87
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. 여기서 응답 매핑에 들어가는 stamp가 viewCount ++ 되기 전이라서 응답의 viewCount에 내 조회가 포함된 viewCount가 들어가지 않네요! 정합성이 엄청 중요한 필드는 아니니 증가 후 재조회할 필요까진 없을 것 같지만, 응답에서 viewCount + 1해서 내려주면 좋을 것 같아요! 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. 원래 응답 Dto가 중복으로 사용되는 부분들이 있어서 이렇게 + 1 을 해주기 좀 애매하다고 생각했는데, 아예 view 라는 네이밍으로 조회 시 사용하는 Dto를 분리해버리고 viewCount 가 + 1 된 값으로 응답하도록 반영하겠습니다! |
||
| } | ||
|
|
||
| public RankResponse.Detail findSoptampUserAndCompletedMissionByNickname(String nickname) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,9 @@ | |
| import java.util.Optional; | ||
| import org.sopt.app.domain.entity.soptamp.Stamp; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Modifying; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| public interface StampRepository extends JpaRepository<Stamp, Long>, StampRepositoryCustom { | ||
|
|
||
|
|
@@ -15,4 +18,11 @@ public interface StampRepository extends JpaRepository<Stamp, Long>, StampReposi | |
|
|
||
| Optional<Stamp> findByIdAndUserId(Long id, Long userId); | ||
|
|
||
| @Modifying | ||
|
||
| @Query(""" | ||
| update Stamp s set s.viewCount = s.viewCount + 1 | ||
| where s.id = :stampId | ||
| """) | ||
| void increaseViewCount(@Param("stampId") Long stampId); | ||
|
|
||
| } | ||
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.
SoptampFacade에 단 리뷰처럼 여기서 +1 한 값 내려주도록 하면 좋을 듯합니다!