Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/main/java/org/runimo/runimo/auth/test/TestAuthController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.runimo.runimo.auth.test;

import lombok.RequiredArgsConstructor;
import org.runimo.runimo.common.response.SuccessResponse;
import org.runimo.runimo.user.enums.UserHttpResponseCode;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Profile({"test", "dev"})
@RestController
@RequestMapping("/api/v1/auth/test")
@RequiredArgsConstructor
public class TestAuthController {

private final TestAuthService testAuthService;

@PostMapping("/login")
public ResponseEntity<SuccessResponse<TestAuthResponse>> login(
@RequestBody TestAuthRequest request
) {
TestAuthResponse response = testAuthService.login(request.userId());

return ResponseEntity.ok(
SuccessResponse.of(
UserHttpResponseCode.LOGIN_SUCCESS,
response
)
);
}

@PostMapping("/signup")
public ResponseEntity<SuccessResponse<TestAuthResponse>> signUp() {
TestAuthResponse response = testAuthService.signUp();
return ResponseEntity.ok(
SuccessResponse.of(
UserHttpResponseCode.SIGNUP_SUCCESS,
response
)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.runimo.runimo.auth.test;

public record TestAuthRequest(
Long userId
) {

}
11 changes: 11 additions & 0 deletions src/main/java/org/runimo/runimo/auth/test/TestAuthResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.runimo.runimo.auth.test;

import io.swagger.v3.oas.annotations.media.Schema;
import org.runimo.runimo.auth.service.dto.TokenPair;

@Schema(description = "테스트용 인증 응답 DTO")
public record TestAuthResponse(
TokenPair tokens
) {

}
53 changes: 53 additions & 0 deletions src/main/java/org/runimo/runimo/auth/test/TestAuthService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.runimo.runimo.auth.test;

import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.runimo.runimo.auth.exceptions.SignUpException;
import org.runimo.runimo.auth.jwt.JwtTokenFactory;
import org.runimo.runimo.rewards.service.eggs.EggGrantService;
import org.runimo.runimo.user.domain.Gender;
import org.runimo.runimo.user.domain.User;
import org.runimo.runimo.user.enums.UserHttpResponseCode;
import org.runimo.runimo.user.repository.UserRepository;
import org.runimo.runimo.user.service.UserCreator;
import org.runimo.runimo.user.service.UserItemCreator;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Profile({"test", "dev"})
@Service
@RequiredArgsConstructor
public class TestAuthService {

private final UserRepository userRepository;
private final JwtTokenFactory jwtTokenFactory;
private final UserCreator userCreator;
private final UserItemCreator userItemCreator;
private final EggGrantService eggGrantService;


@Transactional
public TestAuthResponse login(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> SignUpException.of(UserHttpResponseCode.LOGIN_FAIL_NOT_SIGN_IN));
return new TestAuthResponse(jwtTokenFactory.generateTokenPair(user));
}

@Transactional
public TestAuthResponse signUp() {
User testUser = User.builder()
.nickname("test-user-" + UUID.randomUUID())
.gender(Gender.UNKNOWN)
.totalTimeInSeconds(0L)
.totalDistanceInMeters(0L)
.build();
userRepository.save(testUser);

userCreator.createLovePoint(testUser.getId());
userItemCreator.createAll(testUser.getId());
eggGrantService.grantGreetingEggToUser(testUser);

return new TestAuthResponse(jwtTokenFactory.generateTokenPair(testUser));
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/runimo/runimo/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import java.util.Collections;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Value("${runimo.server.ui.path}")
private String serverUiPath;

@Bean
public OpenAPI customOpenAPI() {

Server server = new Server();
server.setUrl("https://toy.hyeonjae.dev");
server.setUrl(serverUiPath);

return new OpenAPI()
.info(new Info()
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ runimo:
security:
secret-key: ${AES_KEY}
iv: ${AES_IV}
server:
ui:
path: ${SWAGGER_UI_SERVER:http://localhost:8080}

spring:
servlet:
Expand Down
10 changes: 5 additions & 5 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ runimo:
security:
secret-key: ${AES_KEY}
iv: ${AES_IV}
server:
ui:
path: ${SWAGGER_UI_SERVER:http://localhost:8080}

spring:
config:
import:
- optional:file:${ENV_PATH:.}/.env.${SPRING_PROFILES_ACTIVE:test}[.properties]
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL
url: jdbc:h2:mem:testdb;MODE=MYSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
jpa:
hibernate:
ddl-auto: none
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
open-in-view: false
show-sql: true
defer-datasource-initialization: true
Expand All @@ -36,7 +36,7 @@ spring:
init:
mode: always
schema-locations: classpath*:sql/schema.sql
data-locations: classpath*:sql/data.sql
data-locations:

security:
oauth2:
Expand Down