This repository has been archived by the owner on Nov 21, 2023. It is now read-only.
-
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
17 changed files
with
270 additions
and
22 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
submodules/commons/src/main/kotlin/com/sns/commons/utils/IfBoolean.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,15 @@ | ||
package com.sns.commons.utils | ||
|
||
inline fun Boolean?.ifTrue(block: Boolean.() -> Unit): Boolean? { | ||
if (this == true) { | ||
block() | ||
} | ||
return this | ||
} | ||
|
||
inline fun Boolean?.ifFalse(block: Boolean.() -> Unit): Boolean? { | ||
if (this == true) { | ||
block() | ||
} | ||
return this | ||
} |
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
34 changes: 34 additions & 0 deletions
34
user-api/src/main/kotlin/com/sns/user/component/user/application/UserCommandService.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,34 @@ | ||
package com.sns.user.component.user.application | ||
|
||
import com.sns.user.component.user.domains.User | ||
import com.sns.user.component.user.repositories.UserRepository | ||
import com.sns.user.core.exceptions.NoAuthorityException | ||
import org.springframework.context.ApplicationEventPublisher | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.security.crypto.password.PasswordEncoder | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class UserCommandService( | ||
private val userRepository: UserRepository, | ||
private val passwordEncoder: PasswordEncoder, | ||
private val eventPublisher: ApplicationEventPublisher | ||
) { | ||
|
||
fun create(name: String, password: String, email: String): User { | ||
val user = User.create(email, passwordEncoder.encode(password), name, email) { | ||
eventPublisher.publishEvent(it) | ||
} | ||
userRepository.save(user) | ||
return user | ||
} | ||
|
||
fun activate(userId: String) { | ||
val user = userRepository.findByIdOrNull(userId) ?: throw NoAuthorityException() | ||
|
||
user.activate() { | ||
eventPublisher.publishEvent(it) | ||
} | ||
userRepository.save(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
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
12 changes: 12 additions & 0 deletions
12
user-api/src/main/kotlin/com/sns/user/component/user/events/UserActivatedEvent.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,12 @@ | ||
package com.sns.user.component.user.events | ||
|
||
import com.sns.commons.DomainEvent | ||
import com.sns.user.component.user.domains.User | ||
import com.sns.user.core.config.IntegrationConfig | ||
|
||
class UserActivatedEvent(val user: User) : DomainEvent { | ||
override val eventId: String | ||
get() = "$channel-$user.id-${System.currentTimeMillis()}" | ||
|
||
override val channel = IntegrationConfig.Channels.USER_STATUS | ||
} |
12 changes: 12 additions & 0 deletions
12
user-api/src/main/kotlin/com/sns/user/component/user/events/UserCreatedEvent.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,12 @@ | ||
package com.sns.user.component.user.events | ||
|
||
import com.sns.commons.DomainEvent | ||
import com.sns.user.component.user.domains.User | ||
import com.sns.user.core.config.IntegrationConfig | ||
|
||
class UserCreatedEvent(val user: User) : DomainEvent { | ||
override val eventId: String | ||
get() = "$channel-$user.id-${System.currentTimeMillis()}" | ||
|
||
override val channel = IntegrationConfig.Channels.USER_STATUS | ||
} |
19 changes: 19 additions & 0 deletions
19
user-api/src/main/kotlin/com/sns/user/component/user/listeners/UserStatusListener.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,19 @@ | ||
package com.sns.user.component.user.listeners | ||
|
||
import com.sns.commons.annotation.CustomEventListener | ||
import com.sns.user.component.authcode.application.AuthCodeCommand | ||
import com.sns.user.component.user.events.UserActivatedEvent | ||
import com.sns.user.component.user.events.UserCreatedEvent | ||
|
||
@CustomEventListener | ||
class UserStatusListener(val authCodeCommand: AuthCodeCommand) { | ||
// 인증 전, 기초 가입만 마친 상태 | ||
fun onCreated(createdEvent: UserCreatedEvent) { | ||
val user = createdEvent.user | ||
authCodeCommand.create(user.id) | ||
} | ||
|
||
fun onActivated(activatedEvent: UserActivatedEvent) { | ||
// TODO 타임라인생성, 프로필생성,, | ||
} | ||
} |
18 changes: 16 additions & 2 deletions
18
user-api/src/main/kotlin/com/sns/user/component/user/repositories/DefaultUserRepository.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,9 +1,23 @@ | ||
package com.sns.user.component.user.repositories | ||
|
||
import com.sns.user.component.user.domains.User | ||
import org.springframework.jdbc.core.JdbcTemplate | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class DefaultUserRepository( | ||
userCrudRepository: UserCrudRepository | ||
userCrudRepository: UserCrudRepository, | ||
private val jdbcTemplate: JdbcTemplate | ||
) : UserRepository, | ||
UserCrudRepository by userCrudRepository | ||
UserCrudRepository by userCrudRepository { | ||
|
||
override fun findByInfoEmailAddressOrNull(email: String): User? = jdbcTemplate.queryForObject( | ||
""" | ||
SELECT `id`,`password`,`name`,info_email_address,created_at,updated_at,`status` | ||
FROM `user` | ||
WHERE info_email_address = ? | ||
LIMIT 1 | ||
""".trimIndent(), | ||
User.MAPPER, email, | ||
) | ||
} |
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
11 changes: 8 additions & 3 deletions
11
user-api/src/main/kotlin/com/sns/user/endpoints/user/requests/SignUpRequest.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
Oops, something went wrong.