Skip to content

Commit

Permalink
Merge pull request #190 from Team-HMH/develop
Browse files Browse the repository at this point in the history
develop -> main
  • Loading branch information
jumining authored Aug 19, 2024
2 parents 430484d + 6409927 commit 0121176
Show file tree
Hide file tree
Showing 60 changed files with 1,104 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService;
import sopt.org.hmh.domain.user.domain.User;
import sopt.org.hmh.domain.user.service.UserService;
import sopt.org.hmh.global.auth.jwt.TokenService;
import sopt.org.hmh.global.auth.jwt.service.TokenService;

@Service
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package sopt.org.hmh.domain.app.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest;
import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest;
import sopt.org.hmh.global.auth.jwt.JwtConstants;
import sopt.org.hmh.global.common.response.BaseResponse;
import sopt.org.hmh.global.common.response.EmptyJsonResponse;

@Tag(name = "챌린지 관련 API")
@SecurityRequirement(name = JwtConstants.AUTHORIZATION)
public interface ChallengeAppApi {

@Operation(
summary = "스크린타임 설정할 앱을 추가하는 API",
responses = {
@ApiResponse(
responseCode = "200",
description = "챌린지 정보 조회에 성공했습니다."),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.",
content = @Content)})
ResponseEntity<BaseResponse<EmptyJsonResponse>> orderAddApps(
@Parameter(hidden = true) Long userId,
@RequestHeader("OS") String os,
@RequestBody ChallengeAppArrayRequest requests);

@Operation(
summary = "스크린타임 설정한 앱을 삭제하는 API",
responses = {
@ApiResponse(
responseCode = "200",
description = "챌린지 정보 조회에 성공했습니다."),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.",
content = @Content)})
ResponseEntity<BaseResponse<EmptyJsonResponse>> orderRemoveApp(
@Parameter(hidden = true) Long userId,
@RequestHeader("OS") String os,
@RequestBody AppRemoveRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package sopt.org.hmh.domain.app.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sopt.org.hmh.domain.app.domain.exception.AppSuccess;
import sopt.org.hmh.domain.app.dto.request.AppRemoveRequest;
import sopt.org.hmh.domain.app.dto.request.ChallengeAppArrayRequest;
import sopt.org.hmh.domain.challenge.service.ChallengeFacade;
import sopt.org.hmh.global.auth.UserId;
import sopt.org.hmh.global.common.constant.CustomHeaderType;
import sopt.org.hmh.global.common.response.BaseResponse;
import sopt.org.hmh.global.common.response.EmptyJsonResponse;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/challenge/app")
public class ChallengeAppController implements ChallengeAppApi {

private final ChallengeFacade challengeFacade;

@Override
@PostMapping
public ResponseEntity<BaseResponse<EmptyJsonResponse>> orderAddApps(
@UserId final Long userId,
@RequestHeader(CustomHeaderType.OS) final String os,
@RequestBody @Valid final ChallengeAppArrayRequest requests) {
challengeFacade.addAppsToCurrentChallenge(userId, requests.apps(), os);

return ResponseEntity
.status(AppSuccess.ADD_APP_SUCCESS.getHttpStatus())
.body(BaseResponse.success(AppSuccess.ADD_APP_SUCCESS, new EmptyJsonResponse()));

}

@Override
@DeleteMapping
public ResponseEntity<BaseResponse<EmptyJsonResponse>> orderRemoveApp(
@UserId final Long userId,
@RequestHeader(CustomHeaderType.OS) final String os,
@RequestBody @Valid final AppRemoveRequest request) {
challengeFacade.removeAppFromCurrentChallenge(userId, request.appCode(), os);

return ResponseEntity
.status(AppSuccess.REMOVE_APP_SUCCESS.getHttpStatus())
.body(BaseResponse.success(AppSuccess.REMOVE_APP_SUCCESS, new EmptyJsonResponse()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void addHistoryApp(
}

private List<HistoryApp> supplementAdditionalInfo(List<ChallengeApp> currentChallengeApps,
List<HistoryAppRequest> apps, DailyChallenge dailyChallenge, String os) {
List<HistoryAppRequest> apps, DailyChallenge dailyChallenge, String os) {
return apps.stream().map(app -> HistoryApp.builder()
.goalTime(this.getGoalTime(currentChallengeApps, app.appCode()))
.appCode(app.appCode())
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/sopt/org/hmh/domain/auth/controller/AuthApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import org.springframework.web.bind.annotation.RequestHeader;
import sopt.org.hmh.domain.auth.dto.request.SocialPlatformRequest;
import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest;
import sopt.org.hmh.global.auth.UserId;
import sopt.org.hmh.domain.auth.dto.response.LoginResponse;
import sopt.org.hmh.domain.auth.dto.response.ReissueResponse;
import sopt.org.hmh.global.auth.jwt.JwtConstants;
import sopt.org.hmh.global.common.response.BaseResponse;

Expand All @@ -18,20 +19,28 @@
public interface AuthApi {

@Operation(summary = "소셜 로그인")
ResponseEntity<BaseResponse<?>> orderLogin(
ResponseEntity<BaseResponse<LoginResponse>> orderLogin(
@Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken,
@RequestBody final SocialPlatformRequest request
);

@Operation(summary = "회원 가입")
ResponseEntity<BaseResponse<?>> orderSignup(
ResponseEntity<BaseResponse<LoginResponse>> orderSignupDeprecated(
@Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken,
@RequestHeader("OS") final String os,
@RequestBody final SocialSignUpRequest request
);

@Operation(summary = "회원 가입 V2")
ResponseEntity<BaseResponse<LoginResponse>> orderSignup(
@Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken,
@RequestHeader("OS") final String os,
@RequestHeader("Time-Zone") final String timeZone,
@RequestBody final SocialSignUpRequest request
);

@Operation(summary = "토큰 재발급")
ResponseEntity<BaseResponse<?>> orderReissue(
ResponseEntity<BaseResponse<ReissueResponse>> orderReissue(
@Parameter(hidden = true) @RequestHeader(JwtConstants.AUTHORIZATION) final String refreshToken
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sopt.org.hmh.domain.auth.dto.response.LoginResponse;
import sopt.org.hmh.domain.auth.dto.response.ReissueResponse;
import sopt.org.hmh.domain.auth.exception.AuthSuccess;
import sopt.org.hmh.domain.auth.dto.request.SocialPlatformRequest;
import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest;
import sopt.org.hmh.domain.auth.service.AuthFacade;
import sopt.org.hmh.global.auth.jwt.JwtConstants;
import sopt.org.hmh.global.auth.social.SocialAccessTokenResponse;
import sopt.org.hmh.global.common.constant.CustomHeaderType;
import sopt.org.hmh.global.common.response.BaseResponse;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/user")
@RequestMapping("/api")
public class AuthController implements AuthApi {

private final AuthFacade authFacade;

@PostMapping("/login")
@PostMapping("/v1/user/login")
@Override
public ResponseEntity<BaseResponse<?>> orderLogin(
@RequestHeader("Authorization") final String socialAccessToken,
public ResponseEntity<BaseResponse<LoginResponse>> orderLogin(
@RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken,
@RequestBody final SocialPlatformRequest request
) {
return ResponseEntity
Expand All @@ -38,25 +42,42 @@ public ResponseEntity<BaseResponse<?>> orderLogin(
));
}

@PostMapping("/signup")
@Override
public ResponseEntity<BaseResponse<?>> orderSignup(
@RequestHeader("Authorization") final String socialAccessToken,
@RequestHeader("OS") final String os,
@Deprecated
@PostMapping("/v1/user/signup")
public ResponseEntity<BaseResponse<LoginResponse>> orderSignupDeprecated(
@RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken,
@RequestHeader(CustomHeaderType.OS) final String os,
@RequestBody @Valid final SocialSignUpRequest request
) {
return ResponseEntity
.status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus())
.body(BaseResponse.success(
AuthSuccess.SIGNUP_SUCCESS,
authFacade.signup(request, socialAccessToken, os)
authFacade.signup(request, socialAccessToken, os, "Asia/Seoul")
));
}

@PostMapping("/reissue")
@Override
public ResponseEntity<BaseResponse<?>> orderReissue(
@RequestHeader("Authorization") final String refreshToken
@PostMapping("/v2/user/signup")
public ResponseEntity<BaseResponse<LoginResponse>> orderSignup(
@RequestHeader(JwtConstants.AUTHORIZATION) final String socialAccessToken,
@RequestHeader(CustomHeaderType.OS) final String os,
@RequestHeader(CustomHeaderType.TIME_ZONE) final String timeZone,
@RequestBody @Valid final SocialSignUpRequest request
) {
return ResponseEntity
.status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus())
.body(BaseResponse.success(
AuthSuccess.SIGNUP_SUCCESS,
authFacade.signup(request, socialAccessToken, os, timeZone)
));
}

@Override
@PostMapping("/v1/user/reissue")
public ResponseEntity<BaseResponse<ReissueResponse>> orderReissue(
@RequestHeader(JwtConstants.AUTHORIZATION) final String refreshToken
) {
return ResponseEntity
.status(AuthSuccess.REISSUE_SUCCESS.getHttpStatus())
Expand All @@ -66,7 +87,7 @@ public ResponseEntity<BaseResponse<?>> orderReissue(
));
}

@GetMapping("/social/token/kakao")
@GetMapping("/v1/user/social/token/kakao")
public ResponseEntity<BaseResponse<SocialAccessTokenResponse>> orderGetKakaoAccessToken(
@RequestParam("code") final String code
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import sopt.org.hmh.domain.challenge.dto.request.ChallengeRequest;
import sopt.org.hmh.domain.challenge.dto.request.ChallengeSignUpRequest;
import sopt.org.hmh.domain.user.domain.OnboardingInfo;
import sopt.org.hmh.domain.user.domain.OnboardingProblem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sopt.org.hmh.domain.auth.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import sopt.org.hmh.global.auth.jwt.TokenResponse;
import sopt.org.hmh.global.auth.jwt.dto.TokenResponse;

public record LoginResponse(
Long userId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sopt.org.hmh.domain.auth.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import sopt.org.hmh.global.auth.jwt.TokenResponse;
import sopt.org.hmh.global.auth.jwt.dto.TokenResponse;

public record ReissueResponse(
@JsonProperty(value = "token")
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sopt.org.hmh.domain.auth.dto.response.ReissueResponse;
import sopt.org.hmh.domain.challenge.dto.request.NewChallengeOrder;
import sopt.org.hmh.domain.challenge.service.ChallengeFacade;
import sopt.org.hmh.domain.user.domain.User;
import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest;
import sopt.org.hmh.domain.auth.dto.response.LoginResponse;
import sopt.org.hmh.domain.user.service.UserService;
import sopt.org.hmh.global.auth.jwt.TokenService;
import sopt.org.hmh.global.auth.jwt.service.TokenService;
import sopt.org.hmh.global.auth.jwt.exception.JwtError;
import sopt.org.hmh.global.auth.jwt.exception.JwtException;
import sopt.org.hmh.global.auth.social.SocialPlatform;
Expand All @@ -36,7 +37,7 @@ public LoginResponse login(String socialAccessToken, SocialPlatform socialPlatfo
}

@Transactional
public LoginResponse signup(SocialSignUpRequest request, String socialAccessToken, String os) {
public LoginResponse signup(SocialSignUpRequest request, String socialAccessToken, String os, String timeZone) {
SocialPlatform socialPlatform = request.socialPlatform();
String socialId = this.getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken);

Expand All @@ -45,7 +46,10 @@ public LoginResponse signup(SocialSignUpRequest request, String socialAccessToke

userService.registerOnboardingInfo(request, newUserId);

challengeFacade.startFirstChallengeWithChallengeSignUpRequest(request.challenge(), newUser , os);
challengeFacade.startNewChallenge(NewChallengeOrder.createFirstChallengeOrder(
request.challenge().toChallengeRequest(), request.challenge().apps(),
newUserId, os, timeZone
));

return performLogin(newUser, socialAccessToken, socialPlatform);
}
Expand Down
Loading

0 comments on commit 0121176

Please sign in to comment.