Skip to content

Commit

Permalink
Merge pull request #227 from Team-Smeme/refactor_#186_unan
Browse files Browse the repository at this point in the history
[REFACTOR] Swagger Interface로 분리 작업
  • Loading branch information
unanchoi authored Mar 12, 2024
2 parents 1f5a926 + e77b535 commit 565b614
Show file tree
Hide file tree
Showing 30 changed files with 208 additions and 48 deletions.
60 changes: 60 additions & 0 deletions smeem-api/src/main/java/com/smeem/api/auth/api/AuthApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.smeem.api.auth.api;

import com.smeem.api.auth.api.dto.request.SignInRequest;
import com.smeem.api.common.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
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 java.security.Principal;

import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER;

@Tag(name = "[Auth] 인증 관련 API (V2)")
public interface AuthApi {

@Operation(summary = "소셜 로그인 API")
@Parameter(name = "Authorization", description = "Bearer ${Social Platform Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "소셜로그인 성공"),
@ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> signIn(@RequestHeader("Authorization") final String socialAccessToken, @RequestBody SignInRequest request);

@Operation(summary = "토큰 재발급 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Refresh Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "토큰 재발급 성공"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> reissueToken(Principal principal);


@Operation(summary = "사용자 로그아웃 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "로그아웃 성공"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> signOut(Principal principal);


@Operation(summary = "회원 탈퇴 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원 탈퇴 성공"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> withDrawl(Principal principal);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.smeem.api.auth.controller;
package com.smeem.api.auth.api;

import com.smeem.api.auth.controller.dto.request.SignInRequest;
import com.smeem.api.auth.controller.dto.response.SignInResponse;
import com.smeem.api.auth.controller.dto.response.token.TokenResponse;
import com.smeem.api.auth.api.dto.request.SignInRequest;
import com.smeem.api.auth.api.dto.response.SignInResponse;
import com.smeem.api.auth.api.dto.response.token.TokenResponse;
import com.smeem.api.auth.service.AuthService;
import com.smeem.api.auth.service.TokenService;
import com.smeem.api.auth.service.dto.request.SignInServiceRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.auth.controller.dto.request;
package com.smeem.api.auth.api.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.smeem.domain.member.model.SocialType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.auth.controller.dto.response;
package com.smeem.api.auth.api.dto.response;


import com.smeem.api.auth.service.dto.response.SignInServiceResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.auth.controller.dto.response.token;
package com.smeem.api.auth.api.dto.response.token;

import com.smeem.api.auth.service.dto.response.TokenServiceResponse;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.smeem.api.auth.service.dto.request;

import com.smeem.api.auth.controller.dto.request.SignInRequest;
import com.smeem.api.auth.api.dto.request.SignInRequest;
import com.smeem.domain.member.model.SocialType;
import lombok.Builder;

Expand Down
28 changes: 28 additions & 0 deletions smeem-api/src/main/java/com/smeem/api/badge/api/BadgeApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.smeem.api.badge.api;

import com.smeem.api.common.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;

import java.security.Principal;

import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER;


@Tag(name = "[Badge] 뱃지 관련 API (V2)")
public interface BadgeApi {

@Operation(summary = "뱃지 목록 조회 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "뱃지 리스트 조회 성공"),
@ApiResponse(responseCode = "4011", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> getBadges(Principal principal);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.smeem.api.badge.controller;
package com.smeem.api.badge.api;

import com.smeem.api.badge.controller.dto.response.BadgeListResponse;
import com.smeem.api.badge.api.dto.response.BadgeListResponse;
import com.smeem.api.badge.service.BadgeService;
import com.smeem.api.common.ApiResponseUtil;
import com.smeem.api.common.BaseResponse;
Expand All @@ -19,10 +19,11 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/members/badges")
public class BadgeController {
public class BadgeController implements BadgeApi {

private final BadgeService badgeService;

@Override
@GetMapping
public ResponseEntity<BaseResponse<?>> getBadges(Principal principal) {
val response = BadgeListResponse.from(badgeService.getBadges(Util.getMemberId(principal)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.badge.controller.dto.response;
package com.smeem.api.badge.api.dto.response;

import com.smeem.api.badge.service.dto.response.AcquiredBadgeServiceResponse;
import com.smeem.domain.badge.model.BadgeType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.smeem.api.badge.controller.dto.response;
package com.smeem.api.badge.api.dto.response;

import com.smeem.api.badge.service.dto.response.BadgeBaseServiceResponse;
import com.smeem.domain.badge.model.BadgeType;
import lombok.AccessLevel;
import lombok.Builder;

import static lombok.AccessLevel.PRIVATE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.badge.controller.dto.response;
package com.smeem.api.badge.api.dto.response;

import com.smeem.api.badge.service.dto.response.BadgeListServiceResponse;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.badge.controller.dto.response;
package com.smeem.api.badge.api.dto.response;

import com.smeem.api.badge.service.dto.response.BadgeServiceResponse;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.smeem.api.badge.controller.dto.response;
package com.smeem.api.badge.api.dto.response;

import com.smeem.api.badge.service.dto.response.BadgeBaseServiceResponse;
import com.smeem.api.badge.service.dto.response.BadgeTypeServiceResponse;
import com.smeem.domain.badge.model.Badge;
import com.smeem.domain.badge.model.BadgeType;
import com.smeem.domain.member.model.MemberBadge;
import lombok.Builder;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.smeem.api.diary.api.dto.response;

import com.smeem.api.badge.controller.dto.response.AcquiredBadgeResponse;
import com.smeem.api.badge.api.dto.response.AcquiredBadgeResponse;
import com.smeem.api.diary.service.dto.response.DiaryCreateServiceResponse;
import lombok.Builder;

Expand Down
71 changes: 71 additions & 0 deletions smeem-api/src/main/java/com/smeem/api/member/api/MemberApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.smeem.api.member.api;

import com.smeem.api.common.BaseResponse;
import com.smeem.api.member.api.dto.request.MemberPlanUpdateRequest;
import com.smeem.api.member.api.dto.request.MemberPushUpdateRequest;
import com.smeem.api.member.api.dto.request.MemberUpdateRequest;
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.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.security.Principal;

import static io.swagger.v3.oas.annotations.enums.ParameterIn.HEADER;

@Tag(name = "[Member] 사용자 관련 API (V2)")
public interface MemberApi {
@Operation(summary = "사용자 프로필 업데이트 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원 정보 조회 성공"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"),
@ApiResponse(responseCode = "500", description = "서버 오류")
})
ResponseEntity<BaseResponse<?>> updateProfile(Principal principal, @RequestBody MemberUpdateRequest request);


@Operation(summary = "사용자 프로필 조회 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원 정보 조회 성공"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> getProfile(Principal principal);

@Operation(summary = "사용자 학습 계획 수정 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원 학습 계획 업데이트 성공"),
@ApiResponse(responseCode = "4xx", description = "유효하지 않은 요청"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequest request);

@Operation(summary = "사용자 닉네임 중복체크 수정 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "닉네임 중복 검사 성공"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name);

@Operation(summary = "사용자 학습 계획 수정 API")
@Parameter(name = "Authorization", description = "Bearer ${Smeme Access Token}", in = HEADER, required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원 푸시알람 동의여부 업데이트 성공"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 토큰입니다"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
ResponseEntity<BaseResponse<?>> updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequest request);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.smeem.api.member.controller;
package com.smeem.api.member.api;

import com.smeem.api.common.ApiResponseUtil;
import com.smeem.api.common.BaseResponse;
import com.smeem.api.member.controller.dto.request.MemberPlanUpdateRequest;
import com.smeem.api.member.controller.dto.request.MemberPushUpdateRequest;
import com.smeem.api.member.controller.dto.request.MemberUpdateRequest;
import com.smeem.api.member.controller.dto.response.MemberGetResponse;
import com.smeem.api.member.controller.dto.response.MemberNameResponse;
import com.smeem.api.member.controller.dto.response.MemberUpdateResponse;
import com.smeem.api.member.api.dto.request.MemberPlanUpdateRequest;
import com.smeem.api.member.api.dto.request.MemberPushUpdateRequest;
import com.smeem.api.member.api.dto.request.MemberUpdateRequest;
import com.smeem.api.member.api.dto.response.MemberGetResponse;
import com.smeem.api.member.api.dto.response.MemberNameResponse;
import com.smeem.api.member.api.dto.response.MemberUpdateResponse;
import com.smeem.api.member.service.MemberService;
import com.smeem.api.member.service.dto.request.MemberPushUpdateServiceRequest;
import com.smeem.api.member.service.dto.request.MemberUpdatePlanServiceRequest;
Expand All @@ -27,10 +27,11 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/members")
public class MemberController {
public class MemberController implements MemberApi {

private final MemberService memberService;

@Override
@PatchMapping
public ResponseEntity<BaseResponse<?>> updateProfile(Principal principal, @RequestBody MemberUpdateRequest request) {
val response = MemberUpdateResponse.from(memberService.updateUserProfile(
Expand All @@ -39,24 +40,28 @@ public ResponseEntity<BaseResponse<?>> updateProfile(Principal principal, @Reque
return ApiResponseUtil.success(SUCCESS_UPDATE_USERNAME, response);
}

@Override
@GetMapping("/me")
public ResponseEntity<BaseResponse<?>> getProfile(Principal principal) {
val response = MemberGetResponse.from(memberService.getMemberProfile(Util.getMemberId(principal)));
return ApiResponseUtil.success(SUCCESS_GET_USER, response);
}

@Override
@PatchMapping("/plan")
public ResponseEntity<BaseResponse<?>> updateUserPlan(Principal principal, @Valid @RequestBody MemberPlanUpdateRequest request) {
memberService.updateLearningPlan(Util.getMemberId(principal), MemberUpdatePlanServiceRequest.of(request));
return ApiResponseUtil.success(SUCCESS_UPDATE_USER_PLAN);
}

@Override
@GetMapping("/nickname/check")
public ResponseEntity<BaseResponse<?>> checkDuplicatedName(@Parameter(description = "유저 닉네임") @RequestParam String name) {
public ResponseEntity<BaseResponse<?>> checkDuplicatedName(@Parameter(description = "유저 닉네임", required = true) @RequestParam String name) {
val response = MemberNameResponse.from(memberService.checkDuplicatedName(name));
return ApiResponseUtil.success(SUCCESS_CHECK_DUPLICATED_NAME, response);
}

@Override
@PatchMapping("/push")
public ResponseEntity<BaseResponse<?>> updateUserPush(Principal principal, @RequestBody MemberPushUpdateRequest request) {
memberService.updateHasAlarm(Util.getMemberId(principal), MemberPushUpdateServiceRequest.of(request));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.member.controller.dto;
package com.smeem.api.member.api.dto;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.member.controller.dto;
package com.smeem.api.member.api.dto;

import jakarta.validation.Constraint;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.member.controller.dto.request;
package com.smeem.api.member.api.dto.request;


import com.smeem.domain.goal.model.GoalType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.member.controller.dto.request;
package com.smeem.api.member.api.dto.request;

public record MemberPushUpdateRequest(
boolean hasAlarm
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.smeem.api.member.controller.dto.request;
package com.smeem.api.member.api.dto.request;


import com.smeem.api.member.controller.dto.ValidUsername;
import com.smeem.api.member.api.dto.ValidUsername;

public record MemberUpdateRequest(
@ValidUsername
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.api.member.controller.dto.request;
package com.smeem.api.member.api.dto.request;


public record TrainingTimeRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.smeem.api.member.controller.dto.response;
package com.smeem.api.member.api.dto.response;


import com.smeem.api.badge.controller.dto.response.BadgeResponse;
import com.smeem.api.badge.api.dto.response.BadgeResponse;
import com.smeem.api.member.service.dto.response.MemberGetServiceResponse;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.smeem.api.member.controller.dto.response;
package com.smeem.api.member.api.dto.response;

import com.smeem.api.member.service.dto.response.MemberNameServiceResponse;
import lombok.AccessLevel;
import lombok.Builder;

import static lombok.AccessLevel.PRIVATE;
Expand Down
Loading

0 comments on commit 565b614

Please sign in to comment.