Skip to content

Commit

Permalink
feat - #68 앱 삭제 시 이번 남은 챌린지 기간에도 일괄적으로 삭제되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jumining committed Jan 17, 2024
1 parent e102a87 commit 541cacf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ResponseEntity<ApiResponse<?>> orderRemoveApp(
@RequestHeader("OS") final String os,
@RequestBody final AppDeleteRequest request
) {
appService.removeApp(userId, request, os);
appService.removeAppAndUpdateRemainingDailyChallenge(userId, request, os);
return ResponseEntity
.status(AppSuccess.DELETE_APP_SUCCESS.getHttpStatus())
.body(ApiResponse.success(AppSuccess.DELETE_APP_SUCCESS, new EmptyJsonResponse()));
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/sopt/org/HMH/domain/app/service/AppService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sopt.org.HMH.domain.app.service;

import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sopt.org.HMH.domain.app.domain.App;
Expand All @@ -12,7 +11,6 @@
import sopt.org.HMH.domain.dailychallenge.service.DailyChallengeService;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -23,20 +21,24 @@ public class AppService {
private final DailyChallengeService dailyChallengeService;

@Transactional
public void removeApp(Long userId, AppDeleteRequest request, String os) {
App app = appRepository.findByDailyChallengeIdAndAppCodeAndOs(
dailyChallengeService.getTodayDailyChallengeByUserId(userId).getId(),
request.appCode(),
os);
public void addAppsAndUpdateRemainingDailyChallenge(Long userId, List<AppGoalTimeRequest> requests, String os) {
dailyChallengeService.getRemainingDailyChallengesByUserId(userId).stream()
.forEach(dailyChallenge -> addApps(dailyChallenge, requests, os));
}

appRepository.deleteById(app.getId());
@Transactional
public void removeAppAndUpdateRemainingDailyChallenge(Long userId, AppDeleteRequest request, String os) {
dailyChallengeService.getRemainingDailyChallengesByUserId(userId).stream()
.forEach(dailyChallenge -> removeApp(dailyChallenge, request, os));
}


@Transactional
public List<List<App>> addAppsAndUpdateRemainingDailyChallenge(Long userId, List<AppGoalTimeRequest> requests, String os) {
return dailyChallengeService.getRemainingDailyChallengesByUserId(userId).stream()
.map((dailyChallenge -> addApps(dailyChallenge, requests, os)))
.collect(Collectors.toList());
public void removeApp(DailyChallenge dailyChallenge, AppDeleteRequest request, String os) {
appRepository.delete(appRepository.findByDailyChallengeIdAndAppCodeAndOs(
dailyChallenge.getId(),
request.appCode(),
os));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public class UserService {
private final ChallengeService challengeService;
private final TokenService tokenService;
private final AppleOAuthProvider appleOAuthProvider;
private final DailyChallengeService dailyChallengeService;
private final AppService appService;

@Transactional
public LoginResponse login(String socialAccessToken, SocialPlatformRequest request) {
Expand Down

0 comments on commit 541cacf

Please sign in to comment.