Skip to content

Commit

Permalink
release: 0.8.0 (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Sep 23, 2024
2 parents 50d8ed0 + 26a5d36 commit 465a30a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
### line mode

line mode는 자신이 갖고있는 펫중 하나를 지정해서, 지정한 width, height범위에서 움직이게 해요.
line mode를 사용할때, markdown 방식으로 이미지를 요청하면, width, height를 설정할 수 없어서 펫이 보이지 않을 수 있으니, HTMl방식을
사용해주세요.
line mode는 자신이 가지고 있는 펫중 하나를 지정해서, 지정한 width, height범위에서 움직이게 해요.
line mode를 사용할때, markdown 방식으로 이미지를 요청하면, width, height를 설정할 수 없어서 펫이 보이지 않을 수 있으니, HTML방식을
사용해 주세요.

> [!TIP]
> **Img의 width와 height를 조절해서 펫의 이동영역을 조절할 수 있어요.**
Expand All @@ -74,11 +74,11 @@ _pet-id에 아무값도 입력하지 않으면, 첫번째 펫이 가져와져요
요청하면 확인할 수 있어요.
API 응답의 `$.personas.[].id` 에 해당하는 값을 pet-id에 입력하면 돼요.

lines모드에서는 펫 레벨 위에 총 contributions수를 보여줘요. 원하지 않을경우, 쿼리 파라미터로 `contribution-view=false`를 담아 요청하세요.
lines모드에서는 펫 레벨 위에 총 contributions수를 보여줘요. 원하지 않을 경우, 쿼리 파라미터로 `contribution-view=false`를 담아 요청하세요.

### farm mode

farm mode는 갖고있는 모든 동물과 추가적인 정보를 보여줘요.
farm mode는 가지고 있는 모든 동물과 추가적인 정보를 보여줘요.

<a href="https://github.com/devxb/gitanimals">
<img src = "https://render.gitanimals.org/farms/devxb" width="300"/>
Expand Down Expand Up @@ -107,8 +107,8 @@ farm mode는 갖고있는 모든 동물과 추가적인 정보를 보여줘요.

### Total contributions

Total contribtuions 는 깃허브에 가입 후 집계된 Contribtuions 의 총합 이에요.
_새로운 contribution은 반영은 최대 1시간이 소요될 수 있어요._
Total contribtuions는 깃허브에 가입 후 집계된 Contribtuions의 총합이에요.
_새로운 contribution 반영은 최대 1시간이 소요될 수 있어요._

### 등장 가능한 펫들

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotestExtensionSpringVersion=1.1.3
testContainerVersion=1.19.3

### Netx ###
netxVersion=0.4.6
netxVersion=0.4.7

### Sentry ###
sentryVersion=4.4.0
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/org/gitanimals/render/domain/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class User(
return persona
}

fun updateContribution(contribution: Int) {
fun updateContribution(contribution: Int): Int {
val currentYear = ZonedDateTime.now(ZoneId.of("UTC")).year
val currentYearContribution =
contributions.firstOrNull { it.year == currentYear }
Expand All @@ -115,6 +115,8 @@ class User(
lastPersonaGivePoint += newContribution
currentYearContribution.lastUpdatedContribution = Instant.now()
levelUpPersonas(newContribution)

return newContribution
}

private fun levelUpPersonas(newContribution: Int) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/org/gitanimals/render/domain/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class UserService(

@Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 10)
@Transactional
fun updateContributions(username: String, contribution: Int) {
fun updateContributions(username: String, contribution: Int): Int {
val user = getUserByName(username)
user.updateContribution(contribution)
val increasedContributionCount = user.updateContribution(contribution)
user.giveNewPersona()

return increasedContributionCount
}

fun isContributionUpdatedBeforeOneHour(name: String): Boolean =
Expand Down
19 changes: 14 additions & 5 deletions src/main/kotlin/org/gitanimals/render/saga/VisitedSagaHandlers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.gitanimals.render.saga
import org.gitanimals.render.app.ContributionApi
import org.gitanimals.render.domain.UserService
import org.gitanimals.render.domain.event.Visited
import org.gitanimals.render.saga.event.GavePoint
import org.rooftop.netx.api.*
import org.rooftop.netx.meta.SagaHandler
import java.time.ZoneId
Expand All @@ -14,17 +15,21 @@ class VisitedSagaHandlers(
private val contributionApi: ContributionApi,
) {

@SagaStartListener(event = Visited::class, successWith = SuccessWith.PUBLISH_COMMIT)
@SagaStartListener(event = Visited::class, successWith = SuccessWith.PUBLISH_JOIN)
fun increaseUserVisited(sagaStartEvent: SagaStartEvent) {
val visited = sagaStartEvent.decodeEvent(Visited::class)
val username = visited.username
userService.increaseVisit(username)
sagaStartEvent.setNextEvent(visited)
}

@SagaCommitListener(event = Visited::class, noRollbackFor = [NullPointerException::class])
fun updateUserContributions(sagaCommitEvent: SagaCommitEvent) {
val visited = sagaCommitEvent.decodeEvent(Visited::class)
@SagaJoinListener(
event = Visited::class,
successWith = SuccessWith.PUBLISH_COMMIT,
noRollbackFor = [NullPointerException::class]
)
fun updateUserContributions(sagaJoinEvent: SagaJoinEvent) {
val visited = sagaJoinEvent.decodeEvent(Visited::class)
val username = visited.username
if (!userService.isContributionUpdatedBeforeOneHour(username)) {
return
Expand All @@ -35,6 +40,10 @@ class VisitedSagaHandlers(
contributionApi.getContributionCount(username, listOf(currentYear))[currentYear]
?: throw NullPointerException("Empty contribution current year \"$currentYear\"")

userService.updateContributions(username, contribution)
val increaseContributionCount = userService.updateContributions(username, contribution)

sagaJoinEvent.setNextEvent(
GavePoint(username = username, point = (increaseContributionCount * 100).toLong())
)
}
}
6 changes: 6 additions & 0 deletions src/main/kotlin/org/gitanimals/render/saga/event/GavePoint.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.gitanimals.render.saga.event

data class GavePoint(
val username: String,
val point: Long,
)

0 comments on commit 465a30a

Please sign in to comment.