-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: identity #5
Open
ratafa
wants to merge
12
commits into
main
Choose a base branch
from
feat/identity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dde67f7
feat: IdentityRepository ์ ์
ratafa 49383f5
feat: IdentityDto Reponse ์ ์
ratafa 6bd4e27
refactor: IdentityRepository ๋ณ์๋ช
๋ณ
ratafa a96fefd
feat: IdentityService์ getIdentityList ์ ์
ratafa 901a425
feat: repository IdentityList ์
๋ฐ์ดํธ ํจ์ ์ถ
ratafa d3b08e5
feat: identity ๋ฐฐ์ด์ response dto๋ก ์ฒ๋ฆฌํ ๋ฉ์๋ ์ถ๊ฐ
ratafa 7657066
feat: Service ๋ ์ด์ด์์ ๋ํ ์ ๋ถ ์ค์ ๊ธฐ๋ฅ ๊ตฌํ
ratafa de4e7c2
feat: Controller ๋ ์ด์ด ๊ธฐ๋ฅ ๊ตฌ
ratafa 850a041
feat: ๋ ํฌ์งํ ๋ฆฌ์์ ์ ์ id๋ก identity ์ฐพ๋ ๊ธฐ๋ฅ ๊ตฌํ
ratafa 18c920a
feat: ์๋น์ค ๋ ์ด์ updateActiveIdentityList ์ธ์ ์ถ
ratafa c9b3bc6
feat: ์ปจํธ๋กค๋ฌ selectRepresentativeIdentity ์๋ต๊ฐ ๋ณ๊ฒฝ
ratafa a8060c5
feat: ํ
์คํธ ์ฝ๋ ์ถ๊ฐ
ratafa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.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,38 @@ | ||
package uoslife.springaccount.app.identity.controller | ||
|
||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal | ||
import org.springframework.security.core.userdetails.UserDetails | ||
import org.springframework.web.bind.annotation.* | ||
import uoslife.springaccount.app.identity.dto.response.IdentityDto | ||
import uoslife.springaccount.app.identity.service.IdentityService | ||
|
||
|
||
@RestController | ||
@RequestMapping("/v2/identities") | ||
class IdentityController(private val identityService: IdentityService) { | ||
@GetMapping | ||
fun getMyIdentities( | ||
@AuthenticationPrincipal userDetails: UserDetails | ||
): ResponseEntity<List<IdentityDto.IdentityResponse>> { | ||
val userId = userDetails.username.toLong(); | ||
|
||
return ResponseEntity.ok(identityService.getIdentityList(userId)) | ||
} | ||
|
||
@PatchMapping("/{identityId}") | ||
fun selectRepresentativeIdentity(@AuthenticationPrincipal userDetails: UserDetails, @PathVariable identityId: String | ||
) :ResponseEntity<List<IdentityDto.IdentityResponse>> { | ||
val userId = userDetails.username.toLong(); | ||
|
||
val result = identityService.selectRepresentativeIdentityFromList(userId) | ||
|
||
return ResponseEntity.ok(result) | ||
//TODO: identityList๊ฐ 1๊ฐ์ธ ๊ฒฝ์ฐ, ์๋ต๊ฐ ๋ฐํ์ ๋ํ ๊ณ ๋ฏผ ํ์. | ||
// return if (result == null) { | ||
// ResponseEntity.ok("์์ ํ ํ์๊ฐ ์์ต๋๋ค."); | ||
// } else { | ||
// ResponseEntity.ok(result) | ||
// } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ain/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.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,17 @@ | ||
package uoslife.springaccount.app.identity.domain.repository.jpa | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Modifying | ||
import org.springframework.data.jpa.repository.Query | ||
import uoslife.springaccount.app.identity.domain.entity.Identity | ||
|
||
interface IdentityRepository : JpaRepository<Identity, String> { | ||
fun findIdentitiesByUserId(userId: Long): List<Identity>? | ||
|
||
fun findByUserId(userId: Long): List<Identity>? | ||
|
||
// ์ถํ queryDsl๋ก ๋ณ๊ฒฝ ์์ . | ||
@Modifying | ||
@Query("UPDATE Identity i SET i.isActive = CASE WHEN i.id = :identityId THEN true ELSE false END WHERE i.user.id = :userId") | ||
fun updateActiveIdentityList(identityId: String, userId: Long) | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.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,33 @@ | ||
package uoslife.springaccount.app.identity.dto.response | ||
|
||
import uoslife.springaccount.app.identity.domain.entity.Identity | ||
|
||
class IdentityDto { | ||
data class IdentityResponse ( | ||
val type: String, | ||
val status: String, | ||
val idNumber: String, | ||
val university: String? = null, | ||
val department: String? = null, | ||
val major: String? = null, // null ๊ฐ๋ฅ์ฑ ๊ณ ๋ ค | ||
val isActive: Boolean | ||
) | ||
|
||
companion object { | ||
fun toResponse(identity : Identity) : IdentityResponse{ | ||
return IdentityResponse( | ||
type = identity.type, | ||
status = identity.status, | ||
idNumber = identity.idNumber, | ||
university = identity.university, | ||
department = identity.department, | ||
major = identity.major, | ||
isActive = identity.isActive, | ||
) | ||
} | ||
|
||
fun toResponseIdentityList (identityList: List<Identity>?): List<IdentityDto.IdentityResponse>? { | ||
return identityList?.map { toResponse(it) } | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.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,37 @@ | ||
package uoslife.springaccount.app.identity.service | ||
|
||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import uoslife.springaccount.app.identity.domain.entity.Identity | ||
import uoslife.springaccount.app.identity.domain.repository.jpa.IdentityRepository | ||
import uoslife.springaccount.app.identity.dto.response.IdentityDto | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class IdentityService( | ||
private val identityRepository : IdentityRepository, | ||
) { | ||
|
||
// ์ ์ ์ ์ ๋ถ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ต๋๋ค. | ||
// ๋ฆฌ๋น๋ ์ด์ ์ ์๋์ ์ ์ ์ธ ๊ฒฝ์ฐ, ๋ณต์ ์ ๋ถ์ด ์กด์ฌํ ์ ์์ต๋๋ค. | ||
fun getIdentityList(userId: Long):List<IdentityDto.IdentityResponse>? { | ||
val identityList = identityRepository.findByUserId(userId); | ||
|
||
return IdentityDto.toResponseIdentityList(identityList); | ||
} | ||
|
||
// ์ฌ๋ฌ ์ ๋ถ ์ค ๋ํ ์ ๋ถ ์ค์ ํฉ๋๋ค. | ||
fun selectRepresentativeIdentityFromList(userId: Long) :List<IdentityDto.IdentityResponse>?{ | ||
val identityList = identityRepository.findByUserId(userId); | ||
|
||
// ์ ๋ถ์ ๊ฐ์๊ฐ 1๊ฐ์ธ ๊ฒฝ์ฐ ์ ๋ฐ์ดํธ ๋ก์ง์ ์คํํ์ง ์์ต๋๋ค. | ||
if (identityList?.size == 1) return null; | ||
|
||
// ์ฌ๋ฌ ์ ๋ถ ์ค ๋ํ ์ ๋ถ์ผ๋ก ์ค์ ํ๋ ๋ก์ง์ ๋๋ค. | ||
identityList?.forEach { identity: Identity -> | ||
identityRepository.updateActiveIdentityList(identity.id, userId) | ||
} | ||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IdentityRepository ๋ด๋ถ์ ๋ํ ์ ๋ถ์ ์ค์ ํ๋ ํจ์๋ฅผ ์ ์ํด์ ๋น์ฆ๋์ค ๋ก์ง๊ณผ ๋ถ๋ฆฌํ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
||
|
||
return IdentityDto.toResponseIdentityList(identityList); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/test/kotlin/uoslife/springaccount/app/identity/common/IdentityTest.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,101 @@ | ||
package uoslife.springaccount.app.identity.common | ||
|
||
import io.mockk.MockKAnnotations | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.redisson.api.RedissonClient | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import uoslife.springaccount.app.identity.domain.entity.Identity | ||
import uoslife.springaccount.app.identity.domain.repository.jpa.IdentityRepository | ||
import uoslife.springaccount.app.identity.service.IdentityService | ||
import uoslife.springaccount.app.user.domain.entity.User | ||
|
||
@SpringBootTest | ||
abstract class IdentityTest { | ||
|
||
val identityService = mockk<IdentityService>() | ||
val identityRepository = mockk<IdentityRepository>() | ||
val redissonClient = mockk<RedissonClient>() | ||
// @MockK | ||
// protected lateinit var identityService: IdentityService | ||
// | ||
// @MockK | ||
// protected lateinit var identityRepository: IdentityRepository | ||
|
||
protected val userDummyData1 = User( | ||
name = "๊น์์ฐฌ", | ||
phoneNumber = "010-2064-6347", | ||
email = "[email protected]", | ||
nickname = "kyc", | ||
birthday = "1999-12-03", | ||
avatarUrl = null, | ||
) | ||
|
||
protected val identityDummyData1 = Identity( | ||
user = userDummyData1, | ||
type = "Student", | ||
status = "Active", | ||
idNumber = "123456789", | ||
university = "Seoul National University", | ||
universityCode = "SNU", | ||
department = "Computer Science", | ||
departmentCode = "CS", | ||
major = null, | ||
majorCode = null, | ||
isActive = false | ||
) | ||
|
||
protected val identityDummyData2 = Identity( | ||
user = userDummyData1, | ||
type = "Alumnus", | ||
status = "Inactive", | ||
idNumber = "987654321", | ||
university = "Korea University", | ||
universityCode = "KU", | ||
department = "Business Administration", | ||
departmentCode = "BA", | ||
major = "Marketing", | ||
majorCode = "MK", | ||
isActive = false | ||
) | ||
|
||
protected val identityDummyData3 = Identity( | ||
user = userDummyData1, | ||
type = "Student", | ||
status = "Active", | ||
idNumber = "111223344", | ||
university = "Yonsei University", | ||
universityCode = "YU", | ||
department = "Electrical Engineering", | ||
departmentCode = "EE", | ||
major = "Robotics", | ||
majorCode = "RO", | ||
isActive = false | ||
) | ||
|
||
companion object { | ||
@BeforeAll | ||
@JvmStatic | ||
fun init() { | ||
MockKAnnotations.init(this) | ||
} | ||
} | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
// Mocking repository์ ๋์ ์ ์ | ||
every { userDummyData1.id?.let { identityRepository.findIdentitiesByUserId(it) } } returns listOf(identityDummyData1, identityDummyData2, identityDummyData3) | ||
|
||
// every { userService.findUser(any()) } answers { | ||
// val userId = firstArg<UUID>() | ||
// if (userId == user1.id) { | ||
// user1 | ||
// } else { | ||
// user2 | ||
// } | ||
// } | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/kotlin/uoslife/springaccount/app/identity/service/getIdentityListTest.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,29 @@ | ||
package uoslife.springaccount.app.identity.service | ||
|
||
import io.mockk.every | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import uoslife.springaccount.app.identity.common.IdentityTest | ||
|
||
class getIdentityListTest : IdentityTest() { | ||
|
||
@Test | ||
fun `getIdentityList should return identity list for given userId`() { | ||
// Given | ||
init(); | ||
val userId = userDummyData1.id ?: throw IllegalArgumentException("User ID cannot be null") | ||
|
||
// When | ||
val result = identityService.getIdentityList(userId) | ||
|
||
// Then | ||
assertEquals(3, result?.size) // ๋๋ฏธ ๋ฐ์ดํฐ์์ 3๊ฐ์ ์ ๋ถ ์ ๋ณด๊ฐ ์์ด์ผ ํฉ๋๋ค. | ||
assertEquals(identityDummyData1.type, result?.get(0)?.type) | ||
assertEquals(identityDummyData2.type, result?.get(1)?.type) | ||
assertEquals(identityDummyData3.type, result?.get(2)?.type) | ||
|
||
// identityRepository์ ๋ฉ์๋๊ฐ ํธ์ถ๋์๋์ง ํ์ธ | ||
verify { identityRepository.findIdentitiesByUserId(userId) } | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ถ์ด ํ๋์ธ ๊ฒฝ์ฐ ์์ธ๋ฅผ ๋์ง๋ ๊ฒ๋ ํ๋์ ๋ฐฉ๋ฒ์ด ๋ ๊ฒ ๊ฐ์ต๋๋ค.