-
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.
- Loading branch information
Showing
11 changed files
with
124 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
18 changes: 18 additions & 0 deletions
18
spring-boot-demo/api/src/main/java/ml/sun/controller/UserController.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,18 @@ | ||
package ml.sun.controller | ||
|
||
import ml.sun.service.user.IUserService | ||
import ml.sun.service.user.vo.UserInfoVO | ||
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 | ||
|
||
@RestController | ||
@RequestMapping("user") | ||
class UserController(private val service: IUserService) { | ||
@PostMapping("login") | ||
fun login(username: String, password: String) = service.login(username, password) | ||
|
||
@PostMapping("register") | ||
fun register(@RequestBody userInfo: UserInfoVO) = service.register(userInfo) | ||
} |
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,6 +1,8 @@ | ||
spring: | ||
profiles: | ||
active: ${profileActive:dev} | ||
config: | ||
import: application-service.yml | ||
|
||
logging: | ||
file: | ||
|
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
9 changes: 9 additions & 0 deletions
9
spring-boot-demo/service/src/main/java/ml/sun/service/user/IUserService.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 ml.sun.service.user | ||
|
||
import ml.sun.service.user.vo.UserInfoVO | ||
|
||
interface IUserService { | ||
fun login(username: String, password: String): String | ||
|
||
fun register(vo: UserInfoVO): String | ||
} |
26 changes: 26 additions & 0 deletions
26
spring-boot-demo/service/src/main/java/ml/sun/service/user/impl/UserServiceImpl.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,26 @@ | ||
package ml.sun.service.user.impl | ||
|
||
import ml.sun.service.user.IUserService | ||
import ml.sun.service.user.repository.UserInfoEntity | ||
import ml.sun.service.user.repository.UserRepository | ||
import ml.sun.service.user.vo.UserInfoVO | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class UserServiceImpl(private val repository: UserRepository) : IUserService { | ||
override fun login(username: String, password: String): String = | ||
when (repository.findByUsernameAndPassword(username, password)) { | ||
null -> "username / password ERROR" | ||
else -> "login success" | ||
} | ||
|
||
override fun register(vo: UserInfoVO): String { | ||
if (checkUserExists(vo.username)) { | ||
return "user already registered" | ||
} | ||
repository.save(UserInfoEntity(vo)) | ||
return "register success" | ||
} | ||
|
||
fun checkUserExists(username: String): Boolean = repository.findByUsername(username) != null | ||
} |
21 changes: 21 additions & 0 deletions
21
spring-boot-demo/service/src/main/java/ml/sun/service/user/repository/UserInfoEntity.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,21 @@ | ||
package ml.sun.service.user.repository | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import ml.sun.service.user.vo.UserInfoVO | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
@Table(name = "user_info") | ||
data class UserInfoEntity( | ||
@Id @GeneratedValue var id: Int, | ||
@Column var username: String, | ||
@Column var password: String, | ||
@Column var createDate: LocalDateTime, | ||
@Column var email: String | ||
) { | ||
constructor(vo: UserInfoVO) : this(0, vo.username, vo.password, LocalDateTime.now(), vo.email) | ||
} |
9 changes: 9 additions & 0 deletions
9
spring-boot-demo/service/src/main/java/ml/sun/service/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 ml.sun.service.user.repository | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface UserRepository : JpaRepository<UserInfoEntity, Int> { | ||
fun findByUsername(username: String): UserInfoEntity? | ||
|
||
fun findByUsernameAndPassword(username: String, password: String): UserInfoEntity? | ||
} |
7 changes: 7 additions & 0 deletions
7
spring-boot-demo/service/src/main/java/ml/sun/service/user/vo/UserInfoVO.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 ml.sun.service.user.vo | ||
|
||
import ml.sun.service.user.repository.UserInfoEntity | ||
|
||
data class UserInfoVO(val username: String, val password: String, val email: String) { | ||
constructor(entity: UserInfoEntity) : this(entity.username, entity.password, entity.email) | ||
} |
15 changes: 15 additions & 0 deletions
15
spring-boot-demo/service/src/main/resources/application-service.yml
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,15 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:h2:mem:design | ||
driver-class-name: org.h2.Driver | ||
username: design | ||
password: design | ||
h2: | ||
console: | ||
enabled: true | ||
jpa: | ||
properties: | ||
hibernate: | ||
hbm2ddl: | ||
auto: update | ||
show-sql: true |