Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store user's firstname and lastname in DB
- Loading branch information
1 parent
c5027e2
commit c4decca
Showing
9 changed files
with
64 additions
and
28 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
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
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
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
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/de/code_freak/codefreak/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,20 @@ | ||
package de.code_freak.codefreak.service | ||
|
||
import de.code_freak.codefreak.entity.User | ||
import de.code_freak.codefreak.repository.UserRepository | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.stereotype.Service | ||
import javax.transaction.Transactional | ||
|
||
@Service | ||
class UserService : BaseService() { | ||
@Autowired | ||
private lateinit var userRepository: UserRepository | ||
|
||
@Transactional | ||
fun getOrCreateUser(username: String, patch: User.() -> Unit): User { | ||
val user = userRepository.findByUsernameIgnoreCase(username).orElseGet { userRepository.save(User(username)) } | ||
user.patch() | ||
return 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
14 changes: 14 additions & 0 deletions
14
src/main/resources/db/changelogs/20191025095704-user-firstname-and-lastname.yaml
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 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: 1571990279058-1 | ||
author: hkasch | ||
changes: | ||
- addColumn: | ||
columns: | ||
- column: | ||
name: first_name | ||
type: varchar(255) | ||
- column: | ||
name: last_name | ||
type: varchar(255) | ||
tableName: user |