This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #14 자바코드 코틀린 전환 1. 자바코드 삭제 2. 코틀린으로 재작성 3. 기존 자바코드와 동일하게 동작하는 것 까지 확인 * #15 코드리뷰 피드백 반영 주요 내용 1. 싱글턴(object)로 작성 2. User Validation을 UserEntity로 delegate -> UserLoginServiceImpl에서 로직 제거 -> UserEntity에 custom setter 추가 -> UserEntity setter 테스트는 어디서 해야 될까? Co-authored-by: kms <kmmin78@gmail.com>
- Loading branch information
Showing
30 changed files
with
299 additions
and
272 deletions.
There are no files selected for viewing
7 changes: 0 additions & 7 deletions
7
app-core/src/main/java/kr/flab/wiki/core/login/business/UserLoginService.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
app-core/src/main/java/kr/flab/wiki/core/login/business/UserLoginServiceImpl.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
app-core/src/main/java/kr/flab/wiki/core/login/exception/LoginException.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
app-core/src/main/java/kr/flab/wiki/core/login/persistence/User.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
app-core/src/main/java/kr/flab/wiki/core/login/persistence/UserEntity.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app-core/src/main/java/kr/flab/wiki/core/login/repository/SessionRepository.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
app-core/src/main/java/kr/flab/wiki/core/login/repository/SessionRepositoryImpl.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
app-core/src/main/java/kr/flab/wiki/core/login/repository/UserLoginRepository.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
app-core/src/main/java/kr/flab/wiki/core/login/repository/UserLoginRepositoryImpl.java
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
app-core/src/main/kotlin/kr/flab/wiki/core/common/exception/ValidationException.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,3 @@ | ||
package kr.flab.wiki.core.common.exception | ||
|
||
open class ValidationException(msg : String) : Exception(msg) |
13 changes: 13 additions & 0 deletions
13
app-core/src/main/kotlin/kr/flab/wiki/core/login/LoginUtils.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,13 @@ | ||
package kr.flab.wiki.core.login | ||
|
||
import java.util.regex.Pattern | ||
|
||
object LoginUtils { | ||
// https://atin.tistory.com/425 | ||
private const val REGEX_EMAIL = "^[_a-z0-9-]+(.[_a-z0-9-]+)*@(?:\\w+\\.)+\\w+$" | ||
private val emailPattern: Pattern = Pattern.compile(REGEX_EMAIL) | ||
|
||
fun isValidEmail(email: String?): Boolean { | ||
return emailPattern.matcher(email).matches() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app-core/src/main/kotlin/kr/flab/wiki/core/login/business/UserLoginService.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 kr.flab.wiki.core.login.business | ||
|
||
import kr.flab.wiki.core.login.persistence.User | ||
|
||
interface UserLoginService { | ||
fun login(user : User) : User? | ||
} |
31 changes: 31 additions & 0 deletions
31
app-core/src/main/kotlin/kr/flab/wiki/core/login/business/UserLoginServiceImpl.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,31 @@ | ||
package kr.flab.wiki.core.login.business | ||
|
||
import kr.flab.wiki.core.login.LoginUtils | ||
import kr.flab.wiki.core.login.exception.UserValidationException | ||
import kr.flab.wiki.core.login.persistence.User | ||
import kr.flab.wiki.core.login.repository.SessionRepository | ||
import kr.flab.wiki.core.login.repository.UserLoginRepository | ||
|
||
class UserLoginServiceImpl( | ||
private val userLoginRepository: UserLoginRepository, | ||
private val sessionRepository: SessionRepository | ||
) : UserLoginService{ | ||
override fun login(user: User) : User? { | ||
|
||
val email : String = user.email | ||
val password : String = user.password | ||
|
||
val user : User? = userLoginRepository.findUserWithIdAndPassword(email, password) | ||
|
||
//매치되는 회원이 없을 경우 | ||
user ?: throw UserValidationException("There's No Matched Member!") | ||
|
||
//세션 저장 | ||
if (sessionRepository.setAttribute("userName", email) == null) { | ||
throw UserValidationException("Session creation failed!") | ||
} | ||
|
||
return user | ||
|
||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app-core/src/main/kotlin/kr/flab/wiki/core/login/exception/UserValidationException.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,5 @@ | ||
package kr.flab.wiki.core.login.exception | ||
|
||
import kr.flab.wiki.core.common.exception.ValidationException | ||
|
||
class UserValidationException(msg : String) : ValidationException(msg) |
8 changes: 8 additions & 0 deletions
8
app-core/src/main/kotlin/kr/flab/wiki/core/login/persistence/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,8 @@ | ||
package kr.flab.wiki.core.login.persistence | ||
|
||
interface User { | ||
//이름 | ||
val email : String | ||
//비밀번호 | ||
val password : String | ||
} |
24 changes: 24 additions & 0 deletions
24
app-core/src/main/kotlin/kr/flab/wiki/core/login/persistence/UserEntity.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,24 @@ | ||
package kr.flab.wiki.core.login.persistence | ||
|
||
import kr.flab.wiki.core.login.LoginUtils | ||
import kr.flab.wiki.core.login.exception.UserValidationException | ||
|
||
class UserEntity : User { | ||
override var email : String = "" | ||
set(value) { | ||
if(value.isEmpty()){ | ||
throw UserValidationException("Email is Empty!") | ||
} | ||
if (!LoginUtils.isValidEmail(value)) { | ||
throw UserValidationException("Not Email Type!") | ||
} | ||
field = value | ||
} | ||
override var password : String = "" | ||
set(value) { | ||
if (value.isEmpty()) { | ||
throw UserValidationException("Password is Empty!") | ||
} | ||
field = value | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app-core/src/main/kotlin/kr/flab/wiki/core/login/repository/SessionRepository.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 kr.flab.wiki.core.login.repository | ||
|
||
interface SessionRepository { | ||
/** | ||
* @설명 : 세션에 값을 저장하고, username 을 반환한다. | ||
* @return : username : String | ||
*/ | ||
fun setAttribute(key : String, username : String) : String? | ||
} |
7 changes: 7 additions & 0 deletions
7
app-core/src/main/kotlin/kr/flab/wiki/core/login/repository/SessionRepositoryImpl.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 kr.flab.wiki.core.login.repository | ||
|
||
class SessionRepositoryImpl : SessionRepository { | ||
override fun setAttribute(key: String, username: String): String? { | ||
return username | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app-core/src/main/kotlin/kr/flab/wiki/core/login/repository/UserLoginRepository.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,8 @@ | ||
package kr.flab.wiki.core.login.repository | ||
|
||
import kr.flab.wiki.core.login.persistence.User | ||
|
||
interface UserLoginRepository { | ||
fun isUserExists(email : String, password : String) : Boolean | ||
fun findUserWithIdAndPassword(email : String, password : String) : User? | ||
} |
23 changes: 23 additions & 0 deletions
23
app-core/src/main/kotlin/kr/flab/wiki/core/login/repository/UserLoginRepositoryImpl.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,23 @@ | ||
package kr.flab.wiki.core.login.repository | ||
|
||
import kr.flab.wiki.core.login.persistence.User | ||
import kr.flab.wiki.core.login.persistence.UserEntity | ||
|
||
class UserLoginRepositoryImpl : UserLoginRepository { | ||
private val database : HashMap<String, String> = HashMap() | ||
|
||
override fun isUserExists(email: String, password: String): Boolean { | ||
val originPassword : String = database[email] ?: return false | ||
return originPassword == password | ||
} | ||
|
||
override fun findUserWithIdAndPassword(email: String, password: String): User? { | ||
if(isUserExists(email, password)){ | ||
return UserEntity().apply { | ||
this.email = email | ||
this.password = password | ||
} | ||
} | ||
return null | ||
} | ||
} |
Oops, something went wrong.