Skip to content

Commit

Permalink
feat - #9 챌린지 생성 api resonse data 형태 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jumining committed Jan 8, 2024
1 parent da5188c commit cd81fbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sopt.org.HMH.domain.challenge.dto.response;

public record CreatedChallengeResponse(
Long challengeId
) {
public static CreatedChallengeResponse of(Long challengeId) {
return new CreatedChallengeResponse(challengeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sopt.org.HMH.domain.app.service.AppService;
import sopt.org.HMH.domain.challenge.domain.Challenge;
import sopt.org.HMH.domain.challenge.dto.request.ChallengeRequest;
import sopt.org.HMH.domain.challenge.dto.response.CreatedChallengeResponse;
import sopt.org.HMH.domain.challenge.repository.ChallengeRepository;
import sopt.org.HMH.domain.dayChallenge.service.DayChallengeService;
import sopt.org.HMH.domain.user.User;
Expand All @@ -23,12 +24,12 @@ public class ChallengeService {
private final AppService appService;
private final UserService userService;

public Long addChallenge(Long userId, ChallengeRequest request) {
public CreatedChallengeResponse addChallenge(Long userId, ChallengeRequest request) {
User user = userService.getUserId(userId);
Challenge challenge = challengeRepository.save(new Challenge(user, request.period()));
Long dayChallengeId = dayChallengeService.addDayChallenge(challenge, request.goalTime());
List<App> apps = appService.addApp(dayChallengeId, request.apps());
appService.addApp(dayChallengeId, request.apps());

return challenge.getId();
return CreatedChallengeResponse.of(challenge.getId());
}
}

0 comments on commit cd81fbc

Please sign in to comment.