Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
[#40] 코드 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
chanhyeong committed Nov 22, 2021
1 parent dd88573 commit d6bf0a1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlin.random.Random
import java.sql.ResultSet
import java.time.Instant
import javax.validation.constraints.NotBlank
import org.springframework.jdbc.core.DataClassRowMapper
import org.springframework.jdbc.core.RowMapper

data class AuthCode(
Expand All @@ -26,7 +27,7 @@ data class AuthCode(
private const val CODE_LENGTH = 10;
private val charPool: List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9')
fun createSignUp(userId: String) = AuthCode(purpose = Purpose.SIGN_UP, userId = userId)
val MAPPER: RowMapper<AuthCode> = AuthCodeRowMapper()
val MAPPER: RowMapper<AuthCode> = DataClassRowMapper(AuthCode::class.java)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.sns.commons.DomainEvent
import com.sns.user.component.user.dtos.FriendRequestedEvent
import com.sns.user.component.user.events.UserStatusChangedEvent
import com.sns.user.core.exceptions.AlreadyExistException
import java.sql.ResultSet
import java.time.Instant
import javax.validation.constraints.Max
import javax.validation.constraints.NotBlank
Expand All @@ -14,6 +13,7 @@ import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.annotation.Transient
import org.springframework.data.domain.Persistable
import org.springframework.data.relational.core.mapping.MappedCollection
import org.springframework.jdbc.core.DataClassRowMapper
import org.springframework.jdbc.core.RowMapper

data class User(
Expand Down Expand Up @@ -87,7 +87,7 @@ data class User(
}

companion object {
val MAPPER: RowMapper<User> = UserRowMapper()
val MAPPER: RowMapper<User> = DataClassRowMapper(User::class.java)

fun create(
id: String,
Expand All @@ -112,21 +112,6 @@ data class User(
}
}

// purpose enum 매핑이 안되서 수동으로 작성함. 확인필요.
class UserRowMapper : RowMapper<User> {
override fun mapRow(rs: ResultSet, rowNum: Int): User? {
return User(
id = rs.getString("id"),
password = rs.getString("password"),
name = rs.getString("name"),
infoEmailAddress = rs.getString("info_email_address"),
status = Status.valueOf(rs.getString("status")),
createdAt = Instant.ofEpochMilli(rs.getTimestamp("created_at").time),
updatedAt = Instant.ofEpochMilli(rs.getTimestamp("updated_at").time),
)
}
}

enum class Status {
CREATED,
ACTIVATED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@ import com.sns.commons.DomainEvent
import com.sns.user.component.user.domains.User
import com.sns.user.core.config.IntegrationConfig

class UserStatusChangedEvent(val user: User) : DomainEvent {
override val eventId: String
get() = "$channel-$user.id-${System.currentTimeMillis()}"

override val channel = IntegrationConfig.Channels.USER_STATUS
}
class UserStatusChangedEvent(val user: User) : DomainEvent(IntegrationConfig.Channels.USER_STATUS, user.id)
8 changes: 4 additions & 4 deletions user-api/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ server:
logging:
level:
root: info
org: trace
# springframework:
# jdbc:
# core: debug
org:
springframework:
jdbc:
core: debug
pattern:
console: "%d{HH:mm:ss} [%t][%-5level] %msg \\(%F:%L\\)%n"
spring:
Expand Down

0 comments on commit d6bf0a1

Please sign in to comment.