Skip to content

Commit 26ab8a1

Browse files
authored
release: 1.6.2 (#176)
2 parents 86c38db + ca428c2 commit 26ab8a1

23 files changed

+401
-42
lines changed

docs/api/render/chage_persona_visible.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
``` json
1313
{
1414
"personaId": "123",
15-
"visible": true
15+
"visible": true,
16+
"type": "APP" // "APP", "DEFAULT"
1617
}
1718
```
1819

@@ -26,6 +27,7 @@
2627
"type": "GOBLIN_BAG",
2728
"level": "15",
2829
"visible": true,
30+
"appVisible": false,
2931
"dropRate": "10%"
3032
}
3133
```

docs/api/render/get_my_pets.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,83 +20,95 @@
2020
"type": "LITTLE_CHICK_SUNGLASSES",
2121
"level": "8",
2222
"visible": true,
23+
"appVisible": false,
2324
"dropRate": "10%"
2425
},
2526
{
2627
"id": "2",
2728
"type": "LITTLE_CHICK_SUNGLASSES",
2829
"level": "7",
2930
"visible": true,
31+
"appVisible": false,
3032
"dropRate": "0.7%"
3133
},
3234
{
3335
"id": "3",
3436
"type": "LITTLE_CHICK_SUNGLASSES",
3537
"level": "11",
3638
"visible": true,
39+
"appVisible": false,
3740
"dropRate": "33%"
3841
},
3942
{
4043
"id": "4",
4144
"type": "LITTLE_CHICK",
4245
"level": "11",
4346
"visible": true,
47+
"appVisible": false,
4448
"dropRate": "24%"
4549
},
4650
{
4751
"id": "5",
4852
"type": "GOBLIN_BAG",
4953
"level": "15",
5054
"visible": true,
55+
"appVisible": false,
5156
"dropRate": "10%"
5257
},
5358
{
5459
"id": "6",
5560
"type": "LITTLE_CHICK_SUNGLASSES",
5661
"level": "14",
5762
"visible": true,
63+
"appVisible": false,
5864
"dropRate": "10%"
5965
},
6066
{
6167
"id": "7",
6268
"type": "GOOSE",
6369
"level": "11",
6470
"visible": true,
71+
"appVisible": false,
6572
"dropRate": "10%"
6673
},
6774
{
6875
"id": "8",
6976
"type": "FISH_MAN",
7077
"level": "14",
7178
"visible": true,
79+
"appVisible": false,
7280
"dropRate": "10%"
7381
},
7482
{
7583
"id": "9",
7684
"type": "GOBLIN",
7785
"level": "16",
7886
"visible": true,
87+
"appVisible": false,
7988
"dropRate": "10%"
8089
},
8190
{
8291
"id": "10",
8392
"type": "LITTLE_CHICK_SUNGLASSES",
8493
"level": "20",
8594
"visible": true,
95+
"appVisible": false,
8696
"dropRate": "10%"
8797
},
8898
{
8999
"id": "11",
90100
"type": "LITTLE_CHICK",
91101
"level": "13",
92102
"visible": true,
103+
"appVisible": false,
93104
"dropRate": "10%"
94105
},
95106
{
96107
"id": "12",
97108
"type": "LITTLE_CHICK",
98109
"level": "12",
99110
"visible": true,
111+
"appVisible": false,
100112
"dropRate": "10%"
101113
}
102114
]

docs/api/render/get_user_info.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Get render user info
2+
3+
렌더 유저 정보를 조회합니다.
4+
5+
## Request
6+
### HTTP METHOD : `GET`
7+
### url : `https://render.gitanimals.org/users`
8+
9+
### RequestHeader
10+
- Authorization: `{token}`
11+
12+
## Response
13+
14+
200 OK
15+
16+
```json
17+
{
18+
"id": "1",
19+
"username": "devxb", // 사용자 이름
20+
"contribution": 12345,
21+
"personaCount": 12345,
22+
"visitor": 30, // 방문자 수
23+
"contributionsForNextPersona": { // 다음펫을 얻기위한 contributions양
24+
"current": 15, // 현재 값
25+
"max": 30 // 최댓 값
26+
}
27+
}
28+
```

src/main/kotlin/org/gitanimals/identity/app/AppleLoginFacade.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class AppleLoginFacade(
2727
entryPoint = EntryPoint.APPLE,
2828
profileImage = profileImage,
2929
contributionPerYears = mapOf(),
30+
authenticationId = username,
3031
)
3132
}
3233
}

src/main/kotlin/org/gitanimals/identity/app/GithubLoginFacade.kt

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,65 @@ class GithubLoginFacade(
1515
fun login(code: String): String {
1616
val oauthUserResponse = oauth2Api.getOauthUsername(oauth2Api.getToken(code))
1717

18-
val user = when (userService.existsUser(oauthUserResponse.username, EntryPoint.GITHUB)) {
19-
true -> userService.getUserByNameAndEntryPoint(
20-
oauthUserResponse.username,
21-
EntryPoint.GITHUB,
22-
)
23-
24-
else -> {
25-
val contributedYears =
26-
contributionApi.getAllContributionYearsWithToken(oauthUserResponse.username)
27-
val contributionCountPerYears =
28-
contributionApi.getContributionCountWithToken(
18+
val user = when (userService.existsByEntryPointAndAuthenticationId(
19+
entryPoint = EntryPoint.GITHUB,
20+
authenticationId = oauthUserResponse.id,
21+
)) {
22+
true -> {
23+
runCatching {
24+
userService.getUserByNameAndEntryPoint(
2925
oauthUserResponse.username,
30-
contributedYears
26+
EntryPoint.GITHUB,
27+
)
28+
}.getOrElse {
29+
if (it is IllegalArgumentException) {
30+
userService.updateUsernameByEntryPointAndAuthenticationId(
31+
username = oauthUserResponse.username,
32+
entryPoint = EntryPoint.GITHUB,
33+
authenticationId = oauthUserResponse.id,
34+
)
35+
return@getOrElse userService.getUserByNameAndEntryPoint(
36+
oauthUserResponse.username,
37+
EntryPoint.GITHUB,
38+
)
39+
}
40+
throw it
41+
}
42+
}
43+
44+
false -> {
45+
if (userService.existsUser(
46+
username = oauthUserResponse.username,
47+
entryPoint = EntryPoint.GITHUB,
48+
)
49+
) {
50+
userService.updateUserAuthInfoByUsername(
51+
username = oauthUserResponse.username,
52+
entryPoint = EntryPoint.GITHUB,
53+
authenticationId = oauthUserResponse.id,
3154
)
3255

33-
userService.newUser(
34-
username = oauthUserResponse.username,
35-
entryPoint = EntryPoint.GITHUB,
36-
profileImage = oauthUserResponse.profileImage,
37-
contributionPerYears = contributionCountPerYears,
38-
)
56+
userService.getUserByNameAndEntryPoint(
57+
username = oauthUserResponse.username,
58+
entryPoint = EntryPoint.GITHUB,
59+
)
60+
} else {
61+
val contributedYears =
62+
contributionApi.getAllContributionYearsWithToken(oauthUserResponse.username)
63+
val contributionCountPerYears =
64+
contributionApi.getContributionCountWithToken(
65+
oauthUserResponse.username,
66+
contributedYears,
67+
)
68+
69+
userService.newUser(
70+
username = oauthUserResponse.username,
71+
entryPoint = EntryPoint.GITHUB,
72+
authenticationId = oauthUserResponse.id,
73+
profileImage = oauthUserResponse.profileImage,
74+
contributionPerYears = contributionCountPerYears,
75+
)
76+
}
3977
}
4078
}
4179

src/main/kotlin/org/gitanimals/identity/app/Oauth2Api.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface Oauth2Api {
88

99
class OAuthUserResponse(
1010
val username: String,
11+
val id: String,
1112
val profileImage: String,
1213
)
1314
}

src/main/kotlin/org/gitanimals/identity/controller/UserController.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.gitanimals.identity.controller
22

33
import org.gitanimals.identity.app.Token
44
import org.gitanimals.identity.app.UserFacade
5+
import org.gitanimals.identity.controller.request.UsernameUpdateRequest
56
import org.gitanimals.identity.controller.response.UserResponse
67
import org.gitanimals.identity.domain.EntryPoint
78
import org.gitanimals.identity.domain.UserService
@@ -101,4 +102,18 @@ class UserController(
101102
) {
102103
userService.increasePointByUsername(username, entryPoint, idempotencyKey, point)
103104
}
105+
106+
@ResponseStatus(HttpStatus.OK)
107+
@PatchMapping("/internals/users")
108+
fun updateUserByAuthInfo(
109+
@RequestParam("entry-point") entryPoint: EntryPoint,
110+
@RequestParam("authentication-id") authenticationId: String,
111+
@RequestBody request: UsernameUpdateRequest,
112+
) {
113+
userService.updateUsernameByEntryPointAndAuthenticationId(
114+
username = request.changedName,
115+
entryPoint = entryPoint,
116+
authenticationId = authenticationId,
117+
)
118+
}
104119
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.gitanimals.identity.controller.request
2+
3+
data class UsernameUpdateRequest(
4+
val changedName: String,
5+
)

src/main/kotlin/org/gitanimals/identity/controller/response/UserResponse.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ data class UserResponse(
1616
fun from(user: User): UserResponse {
1717
return UserResponse(
1818
id = user.id.toString(),
19-
username = user.name,
19+
username = user.getName(),
2020
points = user.getPoints().toString(),
2121
profileImage = user.profileImage,
22-
entryPoint = user.entryPoint,
22+
entryPoint = user.getEntryPoint(),
2323
)
2424
}
2525
}

src/main/kotlin/org/gitanimals/identity/domain/User.kt

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import org.gitanimals.identity.core.AggregateRoot
55
import org.gitanimals.identity.core.IdGenerator
66
import org.gitanimals.identity.core.instant
77
import org.gitanimals.identity.core.toZonedDateTime
8+
import org.slf4j.LoggerFactory
89
import kotlin.math.max
910
import kotlin.math.min
1011

1112
@AggregateRoot
1213
@Table(
1314
name = "users", indexes = [
14-
Index(columnList = "username", unique = true)
15+
Index(columnList = "username", unique = true),
16+
Index(columnList = "entry_point, authentication_id", unique = true),
1517
]
1618
)
1719
@Entity(name = "users")
@@ -21,7 +23,7 @@ class User(
2123
val id: Long,
2224

2325
@Column(name = "username", nullable = false)
24-
val name: String,
26+
private var name: String,
2527

2628
@Column(name = "points", nullable = false)
2729
private var points: Long,
@@ -36,17 +38,34 @@ class User(
3638

3739
@Column(name = "profile_image", nullable = false)
3840
val profileImage: String,
39-
40-
@Enumerated(EnumType.STRING)
41-
@Column(name = "entry_point", columnDefinition = "VARCHAR(50) DEFAULT 'GITHUB'")
42-
val entryPoint: EntryPoint,
41+
42+
@Embedded
43+
private val authInfo: UserAuthInfo,
4344

4445
@Version
4546
private val version: Long? = null,
4647
) : AbstractTime() {
4748

49+
fun getName(): String = name
50+
4851
fun getPoints(): Long = points
4952

53+
fun getEntryPoint(): EntryPoint = authInfo.entryPoint
54+
55+
fun findAuthenticationId(): String? = authInfo.authenticationId
56+
57+
fun setAuthenticationId(authenticationId: String) {
58+
if (authInfo.authenticationId != null) {
59+
check(authInfo.authenticationId == authenticationId) {
60+
val message =
61+
"Different authenticationId input. saved authenticationId: \"${authInfo.authenticationId}\", input authenticationId: \"$authenticationId\""
62+
logger.error(message)
63+
message
64+
}
65+
}
66+
authInfo.authenticationId = authenticationId
67+
}
68+
5069
fun givePoint(point: Long, reason: String) {
5170
val current = instant().toZonedDateTime()
5271
pointHistories.removeAll { it.createdAt.toZonedDateTime().isBefore(current) }
@@ -74,23 +93,30 @@ class User(
7493
this.points += point
7594
}
7695

96+
fun updateUsername(username: String) {
97+
this.name = username
98+
}
99+
77100
companion object {
78-
private val JOIN_POINT_THRESHOLD = 100_000L
79-
private val PER_DAY_GIVE_POINT_THRESHOLD = 20000L
101+
private val logger = LoggerFactory.getLogger(User::class.simpleName)
102+
103+
private const val JOIN_POINT_THRESHOLD = 100_000L
104+
private const val PER_DAY_GIVE_POINT_THRESHOLD = 20000L
80105

81106
fun newUser(
82107
name: String,
83108
points: Long,
84109
profileImage: String,
85110
entryPoint: EntryPoint,
111+
authenticationId: String,
86112
): User {
87113
return User(
88114
id = IdGenerator.generate(),
89115
name = name,
90116
points = min(points, JOIN_POINT_THRESHOLD),
91117
pointHistories = mutableListOf(),
92118
profileImage = profileImage,
93-
entryPoint = entryPoint,
119+
authInfo = UserAuthInfo(entryPoint, authenticationId),
94120
)
95121
}
96122
}

0 commit comments

Comments
 (0)