diff --git a/build.gradle b/build.gradle index d6013612..8e742041 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-hateoas' implementation 'org.projectlombok:lombok:1.18.30' implementation 'org.springframework.boot:spring-boot-starter-webflux' @@ -40,6 +41,7 @@ dependencies { developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' + testImplementation 'com.h2database:h2' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' implementation 'org.postgresql:postgresql:42.6.0' diff --git a/settings.gradle b/settings.gradle index c5ceee6b..2f059bea 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,11 @@ +pluginManagement { + repositories { + gradlePluginPortal() + } +} + +plugins { + id("org.gradle.toolchains.foojay-resolver") version "1.0.0" +} + rootProject.name = 'CLUE-Backend' diff --git a/src/main/java/hello/cluebackend/domain/user/presentation/TestController.java b/src/main/java/hello/cluebackend/domain/user/presentation/TestController.java index 7db44c26..e5fd6ea9 100644 --- a/src/main/java/hello/cluebackend/domain/user/presentation/TestController.java +++ b/src/main/java/hello/cluebackend/domain/user/presentation/TestController.java @@ -1,5 +1,10 @@ package hello.cluebackend.domain.user.presentation; +import org.springframework.hateoas.EntityModel; +import org.springframework.hateoas.Link; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; + import hello.cluebackend.global.config.JWTUtil; import hello.cluebackend.global.security.jwt.RefreshTokenService; import jakarta.servlet.http.HttpServletResponse; @@ -19,11 +24,16 @@ public class TestController { private final JWTUtil jwtUtil; @PostMapping("/test") - public ResponseEntity issueToken(@RequestParam UUID userId, @RequestParam String username, @RequestParam String role, HttpServletResponse response) { + public ResponseEntity> issueToken(@RequestParam UUID userId, @RequestParam String username, @RequestParam String role, HttpServletResponse response) { String access = jwtUtil.createJwt("access", userId, username, role, 100 * 60 * 60 * 1000L); + EntityModel entityModel = EntityModel.of("JWT access token and refresh token issued for dev use."); + + Link selfLink = linkTo(TestController.class).slash("test").withSelfRel(); + entityModel.add(selfLink); + return ResponseEntity.ok() .header("Authorization", "Bearer " + access) - .body("JWT access token and refresh token issued for dev use."); + .body(entityModel); } } \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 00000000..7336ae2f --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,12 @@ +spring: + datasource: + url: jdbc:postgresql://localhost:5432/testdb + username: testuser + password: testpass + driver-class-name: org.postgresql.Driver + jpa: + hibernate: + ddl-auto: create-drop # 테스트 끝나면 테이블 삭제 + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect \ No newline at end of file