Skip to content

Commit

Permalink
Merge pull request #250 from Team-Sopetit/develop
Browse files Browse the repository at this point in the history
[CHORE] 실서버 배포
  • Loading branch information
thguss authored May 2, 2024
2 parents e82773b + 2207a96 commit 7bb07f8
Show file tree
Hide file tree
Showing 238 changed files with 5,665 additions and 5,400 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
- name: 빌드
run: |
chmod +x gradlew
./gradlew build -x test
./gradlew build test
working-directory: ${{ env.working-directory }}
shell: bash
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@
- P3: 웬만하면 반영해 주세요 (Comment)
- P4: 반영해도 좋고 넘어가도 좋습니다 (Approve)
- P5: 그냥 사소한 의견입니다 (Approve)

### 🚀 Test Code Convention

1. given, when, then을 사용한다.
2. 테스트 메서드명은 다음과 같이 작성한다. -> 메서드명_테스트하고자하는상태_예상되는결과 (ex. giveCotton_CottonCountIs0_NotEnoughCotton)
3. 설마 이런 거까지 생각해야하나싶은 거까지 작성한다. (ex. 솜뭉치를 여러 개 줄 수 있다.)
4. 다수의 값을 다룰 때는 @ParameterizedTest를 활용한다.

### 👩‍👧‍👧 Our Team

Expand Down
38 changes: 1 addition & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import org.hidetake.gradle.swagger.generator.GenerateSwaggerUI

plugins {
id 'java'
id 'org.springframework.boot' version '3.2.1'
id 'io.spring.dependency-management' version '1.1.4'

// restdocs-swagger
id 'com.epages.restdocs-api-spec' version '0.18.2'
id 'org.hidetake.swagger.generator' version '2.18.2'
}

swaggerSources {
sample {
setInputFile(file("${project.buildDir}/api-spec/openapi3.yaml"))
}
}

group = 'com.soptie'
Expand Down Expand Up @@ -55,10 +43,8 @@ dependencies {
// gson
implementation 'com.google.code.gson:gson:2.8.6'

// restdocs-swagger
// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
testImplementation 'com.epages:restdocs-api-spec-mockmvc:0.18.2'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'

// queryDSL
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
Expand All @@ -73,25 +59,3 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

tasks.withType(GenerateSwaggerUI).configureEach {
dependsOn 'openapi3'
copy {
from "build/resources/main/static/docs"
into "src/main/resources/static/docs/"
}
}

bootJar {
dependsOn(':openapi3')
}

openapi3 {
server = "http://localhost:8080"
title = "소프티 API"
description = "소프티 API 명세서"
version = "0.0.1"
outputFileNamePrefix = 'open-api-3.0.1'
format = 'json'
outputDirectory = 'build/resources/main/static/docs'
}
135 changes: 135 additions & 0 deletions src/main/java/com/soptie/server/auth/controller/AuthApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.soptie.server.auth.controller;

import java.security.Principal;

import com.soptie.server.auth.controller.dto.response.SignInResponse;
import com.soptie.server.auth.controller.dto.response.TokenGetResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

import com.soptie.server.auth.controller.dto.request.SignInRequest;
import com.soptie.server.auth.service.dto.response.TokenGetServiceResponse;
import com.soptie.server.common.dto.BaseResponse;
import com.soptie.server.common.dto.ErrorResponse;
import com.soptie.server.common.dto.SuccessResponse;

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.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "auth", description = "인증 API")
public interface AuthApi {

@Operation(
summary = "소셜 로그인",
description = "소셜 로그인을 진행한다.",
responses = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
}
)
ResponseEntity<SuccessResponse<SignInResponse>> signIn(
@RequestHeader("Authorization") String socialAccessToken,
@RequestBody SignInRequest request
);

@Operation(
summary = "토큰 재발급",
description = "리프레시 토큰을 이용해 액세스 토큰을 재발급 받는다.",
responses = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "404",
description = "유효하지 않은 회원",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
}
)
ResponseEntity<SuccessResponse<TokenGetResponse>> reissueToken(
@RequestHeader("Authorization") String refreshToken
);

@Operation(
summary = "로그 아웃",
description = "로그 아웃을 한다.",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공",
content = @Content(schema = @Schema(implementation = SuccessResponse.class))
),
@ApiResponse(
responseCode = "404",
description = "유효하지 않은 회원",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
}
)
ResponseEntity<BaseResponse> signOut(@Parameter(hidden = true) Principal principal);

@Operation(
summary = "회원 탈퇴",
description = "회원 탈퇴를 진행한다.",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공",
content = @Content(schema = @Schema(implementation = SuccessResponse.class))
),
@ApiResponse(
responseCode = "404",
description = "유효하지 않은 회원",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
}
)
ResponseEntity<BaseResponse> withdrawal(@Parameter(hidden = true) Principal principal);
}
33 changes: 22 additions & 11 deletions src/main/java/com/soptie/server/auth/controller/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.soptie.server.auth.controller;

import com.soptie.server.auth.dto.SignInRequest;
import com.soptie.server.auth.controller.dto.request.SignInRequest;
import com.soptie.server.auth.controller.dto.response.SignInResponse;
import com.soptie.server.auth.controller.dto.response.TokenGetResponse;
import com.soptie.server.auth.service.dto.request.SignInServiceRequest;
import com.soptie.server.auth.service.dto.request.TokenGetServiceRequest;
import com.soptie.server.auth.service.AuthService;
import com.soptie.server.common.dto.Response;
import com.soptie.server.common.dto.BaseResponse;
import com.soptie.server.common.dto.SuccessResponse;

import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.http.ResponseEntity;
Expand All @@ -11,36 +17,41 @@
import java.security.Principal;

import static com.soptie.server.auth.message.SuccessMessage.*;
import static com.soptie.server.common.dto.Response.success;
import static com.soptie.server.common.dto.SuccessResponse.*;

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

private final AuthService authService;

@PostMapping
public ResponseEntity<Response> signIn(@RequestHeader("Authorization") String socialAccessToken, @RequestBody SignInRequest request) {
val response = authService.signIn(socialAccessToken, request);
public ResponseEntity<SuccessResponse<SignInResponse>> signIn(
@RequestHeader("Authorization") String socialAccessToken,
@RequestBody SignInRequest request
) {
val response = SignInResponse.of(authService.signIn(SignInServiceRequest.of(socialAccessToken, request)));
return ResponseEntity.ok(success(SUCCESS_SIGN_IN.getMessage(), response));
}

@PostMapping("/token")
public ResponseEntity<Response> reissueToken(@RequestHeader("Authorization") String refreshToken) {
val response = authService.reissueToken(refreshToken);
public ResponseEntity<SuccessResponse<TokenGetResponse>> reissueToken(
@RequestHeader("Authorization") String refreshToken
) {
val response = TokenGetResponse.of(authService.reissueToken(TokenGetServiceRequest.of(refreshToken)));
return ResponseEntity.ok(success(SUCCESS_RECREATE_TOKEN.getMessage(), response));
}

@PostMapping("/logout")
public ResponseEntity<Response> signOut(Principal principal) {
public ResponseEntity<BaseResponse> signOut(Principal principal) {
val memberId = Long.parseLong(principal.getName());
authService.signOut(memberId);
return ResponseEntity.ok(success(SUCCESS_SIGN_OUT.getMessage()));
}

@DeleteMapping
public ResponseEntity<Response> withdrawal(Principal principal) {
public ResponseEntity<BaseResponse> withdrawal(Principal principal) {
val memberId = Long.parseLong(principal.getName());
authService.withdraw(memberId);
return ResponseEntity.ok(success(SUCCESS_WITHDRAWAL.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.soptie.server.auth.dto;
package com.soptie.server.auth.controller.dto.request;

import com.soptie.server.member.entity.SocialType;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.soptie.server.auth.controller.dto.response;

import com.soptie.server.auth.service.dto.response.SignInServiceResponse;
import lombok.Builder;
import lombok.NonNull;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record SignInResponse(
@NonNull String accessToken,
@NonNull String refreshToken,
boolean isMemberDollExist
) {

public static SignInResponse of(SignInServiceResponse response) {
return SignInResponse.builder()
.accessToken(response.accessToken())
.refreshToken(response.refreshToken())
.isMemberDollExist(response.isMemberDollExist())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.soptie.server.auth.controller.dto.response;

import com.soptie.server.auth.service.dto.response.TokenGetServiceResponse;
import lombok.Builder;
import lombok.NonNull;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record TokenGetResponse(
@NonNull String accessToken
) {

public static TokenGetResponse of(TokenGetServiceResponse response) {
return TokenGetResponse.builder()
.accessToken(response.accessToken())
.build();
}
}
16 changes: 0 additions & 16 deletions src/main/java/com/soptie/server/auth/dto/TokenResponse.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.soptie.server.auth.jwt;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.soptie.server.common.dto.Response;
import com.soptie.server.common.dto.ErrorResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -30,6 +30,6 @@ private void setResponse(HttpServletResponse response) throws IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType(APPLICATION_JSON_VALUE);
response.setStatus(SC_UNAUTHORIZED);
response.getWriter().println(objectMapper.writeValueAsString(Response.fail(INVALID_TOKEN.getMessage())));
response.getWriter().println(objectMapper.writeValueAsString(ErrorResponse.of(INVALID_TOKEN.getMessage())));
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/soptie/server/auth/service/AuthService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.soptie.server.auth.service;

import com.soptie.server.auth.dto.SignInRequest;
import com.soptie.server.auth.dto.SignInResponse;
import com.soptie.server.auth.dto.TokenResponse;
import com.soptie.server.auth.service.dto.request.SignInServiceRequest;
import com.soptie.server.auth.service.dto.request.TokenGetServiceRequest;
import com.soptie.server.auth.service.dto.response.SignInServiceResponse;
import com.soptie.server.auth.service.dto.response.TokenGetServiceResponse;

public interface AuthService {

SignInResponse signIn(String socialAccessToken, SignInRequest request);
SignInServiceResponse signIn(SignInServiceRequest request);
void signOut(long memberId);
void withdraw(long memberId);
TokenResponse reissueToken(String refreshToken);
TokenGetServiceResponse reissueToken(TokenGetServiceRequest request);
}
Loading

0 comments on commit 7bb07f8

Please sign in to comment.