-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Re-4aliens/develop
2024-01-16 [Release Note]
- Loading branch information
Showing
8 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM openjdk:17-ea-11-jdk-slim | ||
VOLUME /tmp | ||
COPY build/libs/backend-0.0.1-SNAPSHOT.jar FriendShip.jar | ||
ENTRYPOINT ["java", "-jar", "FriendShip.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
= Spring REST Docs | ||
:toc: left | ||
:toclevels: 2 | ||
:sectlinks: | ||
|
||
[[resources-post]] | ||
== Post | ||
|
||
[[resources-post-create]] | ||
=== Post 생성 | ||
|
||
==== HTTP request | ||
|
||
include::{snippets}/auth-login/http-request.adoc[] | ||
|
||
==== HTTP response | ||
|
||
include::{snippets}/auth-login/http-response.adoc[] |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/aliens/backend/auth/controller/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.aliens.backend.auth.controller; | ||
|
||
import com.aliens.backend.auth.service.AuthService; | ||
import com.aliens.backend.auth.controller.dto.AuthToken; | ||
import com.aliens.backend.auth.controller.dto.LoginRequest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
|
||
@RequestMapping("/authentication") | ||
@RestController | ||
public class AuthController { | ||
|
||
private final AuthService authService; | ||
|
||
public AuthController(final AuthService authService) { | ||
this.authService = authService; | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<AuthToken> login(@RequestBody final LoginRequest loginRequest) { | ||
AuthToken authToken = authService.login(loginRequest); | ||
return ResponseEntity.ok(authToken); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/aliens/backend/auth/controller/dto/AuthToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.aliens.backend.auth.controller.dto; | ||
|
||
public record AuthToken(String accessToken, String refreshToken) { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/aliens/backend/auth/controller/dto/LoginRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.aliens.backend.auth.controller.dto; | ||
|
||
public record LoginRequest(String email, String password) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/aliens/backend/auth/service/AuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.aliens.backend.auth.service; | ||
|
||
import com.aliens.backend.auth.controller.dto.AuthToken; | ||
import com.aliens.backend.auth.controller.dto.LoginRequest; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AuthService { | ||
public AuthToken login(LoginRequest loginRequest) { | ||
return new AuthToken("accessToken", "refreshToken"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.aliens.backend.docs; | ||
|
||
import com.aliens.backend.auth.controller.dto.AuthToken; | ||
import com.aliens.backend.auth.controller.dto.LoginRequest; | ||
import com.aliens.backend.auth.service.AuthService; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@AutoConfigureMockMvc | ||
@AutoConfigureRestDocs | ||
@SpringBootTest | ||
class AuthDocTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private AuthService authService; | ||
|
||
@Test | ||
void login() throws Exception { | ||
final LoginRequest request = new LoginRequest("email","password"); | ||
final AuthToken response = new AuthToken("accessToken", "refreshToken"); | ||
when(authService.login(any())).thenReturn(response); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
this.mockMvc.perform(post("/authentication") | ||
.content(objectMapper.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andDo(document("auth-login", | ||
requestFields( | ||
fieldWithPath("email").description("이메일"), | ||
fieldWithPath("password").description("비밀번호") | ||
) | ||
)); | ||
} | ||
} |