-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from soma-baekgu/BG-139-persist-user
[BG-139]: 유저 영속화 (4h / 1h)
- Loading branch information
Showing
17 changed files
with
266 additions
and
41 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 |
---|---|---|
|
@@ -38,3 +38,5 @@ out/ | |
|
||
### Kotlin ### | ||
.kotlin | ||
|
||
.Ds_Store |
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,35 @@ | ||
|
||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
group = "com.backgu.amaker" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(project(":domain")) | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
implementation("org.springframework.boot:spring-boot-starter-security") | ||
implementation("org.springframework.boot:spring-boot-starter-oauth2-client") | ||
|
||
testImplementation(kotlin("test")) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
kotlin { | ||
jvmToolchain(17) | ||
} | ||
|
||
tasks.getByName<Jar>("bootJar") { | ||
enabled = false | ||
} | ||
|
||
tasks.getByName<Jar>("jar") { | ||
enabled = true | ||
} |
6 changes: 4 additions & 2 deletions
6
.../com/backgu/amaker/AMakerBeApplication.kt → ...com/backgu/amaker/AMakerApiApplication.kt
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.backgu.amaker | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.autoconfigure.domain.EntityScan | ||
import org.springframework.boot.runApplication | ||
|
||
@SpringBootApplication | ||
class AMakerBeApplication | ||
@EntityScan(basePackages = ["com.backgu.amaker"]) | ||
class AMakerApiApplication | ||
|
||
fun main(args: Array<String>) { | ||
runApplication<AMakerBeApplication>(*args) | ||
runApplication<AMakerApiApplication>(*args) | ||
} |
7 changes: 7 additions & 0 deletions
7
api/src/main/kotlin/com/backgu/amaker/user/dto/UserRequest.kt
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,7 @@ | ||
package com.backgu.amaker.user.dto | ||
|
||
class UserRequest( | ||
val name: String, | ||
val email: String, | ||
val picture: String, | ||
) |
9 changes: 9 additions & 0 deletions
9
api/src/main/kotlin/com/backgu/amaker/user/repository/UserRepository.kt
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,9 @@ | ||
package com.backgu.amaker.user.repository | ||
|
||
import com.backgu.amaker.user.domain.User | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.util.UUID | ||
|
||
interface UserRepository : JpaRepository<User, UUID> { | ||
fun findByEmail(email: String): User? | ||
} |
25 changes: 25 additions & 0 deletions
25
api/src/main/kotlin/com/backgu/amaker/user/service/UserService.kt
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.backgu.amaker.user.service | ||
|
||
import com.backgu.amaker.user.domain.User | ||
import com.backgu.amaker.user.dto.UserRequest | ||
import com.backgu.amaker.user.repository.UserRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.util.UUID | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class UserService( | ||
val userRepository: UserRepository, | ||
) { | ||
@Transactional | ||
fun saveUser(request: UserRequest): UUID = | ||
userRepository | ||
.save( | ||
User( | ||
name = request.name, | ||
email = request.email, | ||
picture = request.picture, | ||
), | ||
).id | ||
} |
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,16 @@ | ||
|
||
|
||
spring: | ||
application: | ||
name: a-maker | ||
|
||
datasource: | ||
url: jdbc:mysql://localhost:3306/amaker | ||
username: ${DB_USERNAME} | ||
password: ${DB_PASSWORD} | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
|
||
jpa: | ||
database: mysql | ||
hibernate: | ||
ddl-auto: create |
14 changes: 14 additions & 0 deletions
14
api/src/test/kotlin/com/backgu/amaker/user/fixture/UserFixture.kt
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,14 @@ | ||
package com.backgu.amaker.user.fixture | ||
|
||
import com.backgu.amaker.user.dto.UserRequest | ||
|
||
class UserFixture { | ||
companion object { | ||
fun createUserRequest() = | ||
UserRequest( | ||
name = "name", | ||
email = "email", | ||
picture = "picture", | ||
) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
api/src/test/kotlin/com/backgu/amaker/user/service/UserServiceTest.kt
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,27 @@ | ||
package com.backgu.amaker.user.service | ||
|
||
import com.backgu.amaker.user.fixture.UserFixture | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
|
||
@SpringBootTest | ||
class UserServiceTest { | ||
@Autowired | ||
private lateinit var userService: UserService | ||
|
||
@Test | ||
@DisplayName("사용자 저장 테스트") | ||
fun saveUser() { | ||
// given | ||
val request = UserFixture.createUserRequest() | ||
|
||
// when | ||
val result = userService.saveUser(request) | ||
|
||
// then | ||
assertThat(result).isNotNull() | ||
} | ||
} |
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,16 @@ | ||
|
||
|
||
spring: | ||
application: | ||
name: a-maker | ||
|
||
datasource: | ||
username: sa | ||
password: | ||
driver-class-name: org.h2.Driver | ||
url: jdbc:h2:mem:test;MODE=MySQL | ||
|
||
jpa: | ||
database: mysql | ||
hibernate: | ||
ddl-auto: create |
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 |
---|---|---|
@@ -1,37 +1,53 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
id("org.springframework.boot") version "3.3.0" | ||
id("io.spring.dependency-management") version "1.1.5" | ||
id("org.springframework.boot") version "3.3.0" apply false | ||
id("io.spring.dependency-management") version "1.1.5" apply false | ||
id("org.jlleitschuh.gradle.ktlint") version "12.1.1" | ||
kotlin("jvm") version "1.9.24" | ||
kotlin("plugin.spring") version "1.9.24" | ||
kotlin("plugin.jpa") version "1.9.24" apply false | ||
kotlin("plugin.spring") version "1.9.24" apply false | ||
} | ||
|
||
group = "com.baek9" | ||
version = "0.0.1-SNAPSHOT" | ||
allprojects { | ||
group = "com.backgu.amaker" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
repositories { | ||
mavenCentral() | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter") | ||
implementation("org.jetbrains.kotlin:kotlin-reflect") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") | ||
testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
} | ||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
freeCompilerArgs = listOf("-Xjsr305=strict") | ||
jvmTarget = "17" | ||
} | ||
} | ||
|
||
kotlin { | ||
compilerOptions { | ||
freeCompilerArgs.addAll("-Xjsr305=strict") | ||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
|
||
apply(plugin = "org.jlleitschuh.gradle.ktlint") | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
subprojects { | ||
apply(plugin = "org.springframework.boot") | ||
apply(plugin = "io.spring.dependency-management") | ||
apply(plugin = "org.jetbrains.kotlin.jvm") | ||
apply(plugin = "org.jetbrains.kotlin.plugin.spring") | ||
apply(plugin = "org.jetbrains.kotlin.plugin.jpa") | ||
|
||
dependencies { | ||
implementation("org.jetbrains.kotlin:kotlin-reflect") | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
implementation("org.springframework.boot:spring-boot-starter") | ||
implementation("org.springframework.boot:spring-boot-starter-data-jpa") | ||
implementation("io.github.oshai:kotlin-logging-jvm:5.1.1") | ||
implementation("com.mysql:mysql-connector-j:8.4.0") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") | ||
testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
testRuntimeOnly("com.h2database:h2") | ||
} | ||
} |
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,30 @@ | ||
|
||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
group = "com.backgu.amaker" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation(kotlin("test")) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
kotlin { | ||
jvmToolchain(17) | ||
} | ||
|
||
tasks.getByName<Jar>("bootJar") { | ||
enabled = false | ||
} | ||
|
||
tasks.getByName<Jar>("jar") { | ||
enabled = true | ||
} |
10 changes: 10 additions & 0 deletions
10
domain/src/main/kotlin/com/backgu/amaker/user/domain/Role.kt
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,10 @@ | ||
package com.backgu.amaker.user.domain | ||
|
||
enum class Role( | ||
var key: String, | ||
var value: String, | ||
) { | ||
USER("ROLE_USER", "User"), | ||
MANAGER("ROLE_MANAGER", "Manager"), | ||
ADMIN("ROLE_ADMIN", "Admin"), | ||
} |
25 changes: 25 additions & 0 deletions
25
domain/src/main/kotlin/com/backgu/amaker/user/domain/User.kt
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.backgu.amaker.user.domain | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.EnumType | ||
import jakarta.persistence.Enumerated | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import java.util.UUID | ||
|
||
@Entity | ||
@Table(name = "users") | ||
class User( | ||
@Id | ||
var id: UUID = UUID.randomUUID(), | ||
@Column(nullable = false) | ||
var name: String, | ||
@Column(nullable = false) | ||
val email: String, | ||
@Column(nullable = false) | ||
var picture: String, | ||
@Enumerated(EnumType.STRING) | ||
@Column(nullable = false) | ||
val role: Role = Role.USER, | ||
) |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
plugins { | ||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" | ||
} | ||
rootProject.name = "A-Maker-BE" | ||
include("domain") | ||
include("api") |
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/test/kotlin/com/backgu/amaker/AMakerBeApplicationTests.kt
This file was deleted.
Oops, something went wrong.