Skip to content

Commit

Permalink
release: 0.0.9 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Apr 12, 2024
2 parents 8391702 + ec2bf46 commit c5652a2
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 67 deletions.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

rootProject.name = 'gitanimals-render'
rootProject.name = 'gitanimals'

4 changes: 2 additions & 2 deletions src/main/kotlin/org/gitanimals/render/domain/Persona.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class Persona(

@Embedded
val level: Level,
) : AbstractTime() {

@JsonIgnore
@JoinColumn(name = "user_id")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
lateinit var user: User
var user: User? = null,
) : AbstractTime() {

constructor(
type: PersonaType,
Expand Down
107 changes: 54 additions & 53 deletions src/main/kotlin/org/gitanimals/render/domain/Svgs.kt
Original file line number Diff line number Diff line change
@@ -1,175 +1,176 @@
package org.gitanimals.render.domain

import org.springframework.core.io.ClassPathResource
import org.springframework.util.ClassUtils
import java.nio.charset.Charset

val whiteFieldSvg: String = ClassPathResource("classpath:persona/field/white-field.svg")
val whiteFieldSvg: String = ClassPathResource("persona/field/white-field.svg")
.getContentAsString(Charset.defaultCharset())

val snowyFieldSvg: String = ClassPathResource("classpath:persona/field/snowy-field.svg")
val snowyFieldSvg: String = ClassPathResource("persona/field/snowy-field.svg")
.getContentAsString(Charset.defaultCharset())

val gooseSvg: String = ClassPathResource("classpath:persona/animal/goose.svg")
val gooseSvg: String = ClassPathResource("persona/animal/goose.svg")
.getContentAsString(Charset.defaultCharset())

val gooseSunglassesSvg: String = ClassPathResource("classpath:persona/animal/goose-sunglasses.svg")
val gooseSunglassesSvg: String = ClassPathResource("persona/animal/goose-sunglasses.svg")
.getContentAsString(Charset.defaultCharset())

val gooseKotlinSvg: String = ClassPathResource("classpath:persona/animal/goose-kotlin.svg")
val gooseKotlinSvg: String = ClassPathResource("persona/animal/goose-kotlin.svg")
.getContentAsString(Charset.defaultCharset())

val gooseJavaSvg: String = ClassPathResource("classpath:persona/animal/goose-java.svg")
val gooseJavaSvg: String = ClassPathResource("persona/animal/goose-java.svg")
.getContentAsString(Charset.defaultCharset())

val gooseJsSvg: String = ClassPathResource("classpath:persona/animal/goose-js.svg")
val gooseJsSvg: String = ClassPathResource("persona/animal/goose-js.svg")
.getContentAsString(Charset.defaultCharset())

val gooseNodeSvg: String = ClassPathResource("classpath:persona/animal/goose-node.svg")
val gooseNodeSvg: String = ClassPathResource("persona/animal/goose-node.svg")
.getContentAsString(Charset.defaultCharset())

val gooseSwiftSvg: String = ClassPathResource("classpath:persona/animal/goose-swift.svg")
val gooseSwiftSvg: String = ClassPathResource("persona/animal/goose-swift.svg")
.getContentAsString(Charset.defaultCharset())

val gooseLinuxSvg: String = ClassPathResource("classpath:persona/animal/goose-linux.svg")
val gooseLinuxSvg: String = ClassPathResource("persona/animal/goose-linux.svg")
.getContentAsString(Charset.defaultCharset())

val gooseSpringSvg: String = ClassPathResource("classpath:persona/animal/goose-spring.svg")
val gooseSpringSvg: String = ClassPathResource("persona/animal/goose-spring.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickSvg: String = ClassPathResource("classpath:persona/animal/little-chick.svg")
val littleChickSvg: String = ClassPathResource("persona/animal/little-chick.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickSunglassesSvg: String = ClassPathResource("classpath:persona/animal/little-chick-sunglasses.svg")
val littleChickSunglassesSvg: String = ClassPathResource("persona/animal/little-chick-sunglasses.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickKotlinSvg: String = ClassPathResource("classpath:persona/animal/little-chick-kotlin.svg")
val littleChickKotlinSvg: String = ClassPathResource("persona/animal/little-chick-kotlin.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickJavaSvg: String = ClassPathResource("classpath:persona/animal/little-chick-java.svg")
val littleChickJavaSvg: String = ClassPathResource("persona/animal/little-chick-java.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickJsSvg: String = ClassPathResource("classpath:persona/animal/little-chick-js.svg")
val littleChickJsSvg: String = ClassPathResource("persona/animal/little-chick-js.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickNodeSvg: String = ClassPathResource("classpath:persona/animal/little-chick-node.svg")
val littleChickNodeSvg: String = ClassPathResource("persona/animal/little-chick-node.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickSwiftSvg: String = ClassPathResource("classpath:persona/animal/little-chick-swift.svg")
val littleChickSwiftSvg: String = ClassPathResource("persona/animal/little-chick-swift.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickLinuxSvg: String = ClassPathResource("classpath:persona/animal/little-chick-linux.svg")
val littleChickLinuxSvg: String = ClassPathResource("persona/animal/little-chick-linux.svg")
.getContentAsString(Charset.defaultCharset())

val littleChickSpringSvg: String = ClassPathResource("classpath:persona/animal/little-chick-spring.svg")
val littleChickSpringSvg: String = ClassPathResource("persona/animal/little-chick-spring.svg")
.getContentAsString(Charset.defaultCharset())

val penguinSvg: String = ClassPathResource("classpath:persona/animal/penguin.svg")
val penguinSvg: String = ClassPathResource("persona/animal/penguin.svg")
.getContentAsString(Charset.defaultCharset())

val penguinSunglassesSvg: String = ClassPathResource("classpath:persona/animal/penguin-sunglasses.svg")
val penguinSunglassesSvg: String = ClassPathResource("persona/animal/penguin-sunglasses.svg")
.getContentAsString(Charset.defaultCharset())

val penguinKotlinSvg: String = ClassPathResource("classpath:persona/animal/penguin-kotlin.svg")
val penguinKotlinSvg: String = ClassPathResource("persona/animal/penguin-kotlin.svg")
.getContentAsString(Charset.defaultCharset())

val penguinJavaSvg: String = ClassPathResource("classpath:persona/animal/penguin-java.svg")
val penguinJavaSvg: String = ClassPathResource("persona/animal/penguin-java.svg")
.getContentAsString(Charset.defaultCharset())

val penguinJsSvg: String = ClassPathResource("classpath:persona/animal/penguin-js.svg")
val penguinJsSvg: String = ClassPathResource("persona/animal/penguin-js.svg")
.getContentAsString(Charset.defaultCharset())

val penguinNodeSvg: String = ClassPathResource("classpath:persona/animal/penguin-node.svg")
val penguinNodeSvg: String = ClassPathResource("persona/animal/penguin-node.svg")
.getContentAsString(Charset.defaultCharset())

val penguinSwiftSvg: String = ClassPathResource("classpath:persona/animal/penguin-swift.svg")
val penguinSwiftSvg: String = ClassPathResource("persona/animal/penguin-swift.svg")
.getContentAsString(Charset.defaultCharset())

val penguinLinuxSvg: String = ClassPathResource("classpath:persona/animal/penguin-linux.svg")
val penguinLinuxSvg: String = ClassPathResource("persona/animal/penguin-linux.svg")
.getContentAsString(Charset.defaultCharset())

val penguinSpringSvg: String = ClassPathResource("classpath:persona/animal/penguin-spring.svg")
val penguinSpringSvg: String = ClassPathResource("persona/animal/penguin-spring.svg")
.getContentAsString(Charset.defaultCharset())

val pigSvg: String = ClassPathResource("classpath:persona/animal/pig.svg")
val pigSvg: String = ClassPathResource("persona/animal/pig.svg")
.getContentAsString(Charset.defaultCharset())

val pigSunglassesSvg: String = ClassPathResource("classpath:persona/animal/pig-sunglasses.svg")
val pigSunglassesSvg: String = ClassPathResource("persona/animal/pig-sunglasses.svg")
.getContentAsString(Charset.defaultCharset())

val pigKotlinSvg: String = ClassPathResource("classpath:persona/animal/pig-kotlin.svg")
val pigKotlinSvg: String = ClassPathResource("persona/animal/pig-kotlin.svg")
.getContentAsString(Charset.defaultCharset())

val pigJavaSvg: String = ClassPathResource("classpath:persona/animal/pig-java.svg")
val pigJavaSvg: String = ClassPathResource("persona/animal/pig-java.svg")
.getContentAsString(Charset.defaultCharset())

val pigJsSvg: String = ClassPathResource("classpath:persona/animal/pig-js.svg")
val pigJsSvg: String = ClassPathResource("persona/animal/pig-js.svg")
.getContentAsString(Charset.defaultCharset())

val pigNodeSvg: String = ClassPathResource("classpath:persona/animal/pig-node.svg")
val pigNodeSvg: String = ClassPathResource("persona/animal/pig-node.svg")
.getContentAsString(Charset.defaultCharset())

val pigSwiftSvg: String = ClassPathResource("classpath:persona/animal/pig-swift.svg")
val pigSwiftSvg: String = ClassPathResource("persona/animal/pig-swift.svg")
.getContentAsString(Charset.defaultCharset())

val pigLinuxSvg: String = ClassPathResource("classpath:persona/animal/pig-linux.svg")
val pigLinuxSvg: String = ClassPathResource("persona/animal/pig-linux.svg")
.getContentAsString(Charset.defaultCharset())

val pigSpringSvg: String = ClassPathResource("classpath:persona/animal/pig-spring.svg")
val pigSpringSvg: String = ClassPathResource("persona/animal/pig-spring.svg")
.getContentAsString(Charset.defaultCharset())

val slimeRedSvg: String = ClassPathResource("classpath:persona/animal/slime-red.svg")
val slimeRedSvg: String = ClassPathResource("persona/animal/slime-red.svg")
.getContentAsString(Charset.defaultCharset())

val slimeRedKotlinSvg: String = ClassPathResource("classpath:persona/animal/slime-red-kotlin.svg")
val slimeRedKotlinSvg: String = ClassPathResource("persona/animal/slime-red-kotlin.svg")
.getContentAsString(Charset.defaultCharset())

val slimeRedJavaSvg: String = ClassPathResource("classpath:persona/animal/slime-red-java.svg")
val slimeRedJavaSvg: String = ClassPathResource("persona/animal/slime-red-java.svg")
.getContentAsString(Charset.defaultCharset())

val slimeRedJsSvg: String = ClassPathResource("classpath:persona/animal/slime-red-js.svg")
val slimeRedJsSvg: String = ClassPathResource("persona/animal/slime-red-js.svg")
.getContentAsString(Charset.defaultCharset())

val slimeRedNodeSvg: String = ClassPathResource("classpath:persona/animal/slime-red-node.svg")
val slimeRedNodeSvg: String = ClassPathResource("persona/animal/slime-red-node.svg")
.getContentAsString(Charset.defaultCharset())

val slimeRedSwiftSvg: String = ClassPathResource("classpath:persona/animal/slime-red-swift.svg")
val slimeRedSwiftSvg: String = ClassPathResource("persona/animal/slime-red-swift.svg")
.getContentAsString(Charset.defaultCharset())

val slimeRedLinuxSvg: String = ClassPathResource("classpath:persona/animal/slime-red-linux.svg")
val slimeRedLinuxSvg: String = ClassPathResource("persona/animal/slime-red-linux.svg")
.getContentAsString(Charset.defaultCharset())

val slimeBlueSvg: String = ClassPathResource("classpath:persona/animal/slime-blue.svg")
val slimeBlueSvg: String = ClassPathResource("persona/animal/slime-blue.svg")
.getContentAsString(Charset.defaultCharset())

val slimeGreenSvg: String = ClassPathResource("classpath:persona/animal/slime-green.svg")
val slimeGreenSvg: String = ClassPathResource("persona/animal/slime-green.svg")
.getContentAsString(Charset.defaultCharset())

val largeTextSvgs = lazy {
val map = mutableMapOf<String, String>()
for (i in 'A'..'Z') {
val path = "classpath:persona/text/large/$i.svg"
val path = "persona/text/large/$i.svg"
map[i.toString()] = ClassPathResource(path)
.getContentAsString(Charset.defaultCharset())
}
for (i in 'a'..'z') {
val path = "classpath:persona/text/large/_$i.svg"
val path = "persona/text/large/_$i.svg"
map[i.toString()] = ClassPathResource(path)
.getContentAsString(Charset.defaultCharset())
}
for (i in 0..9) {
val path = "classpath:persona/text/large/$i.svg"
val path = "persona/text/large/$i.svg"
map[i.toString()] = ClassPathResource(path)
.getContentAsString(Charset.defaultCharset())
}
map["-"] = ClassPathResource("classpath:persona/text/large/hyphens.svg")
map["-"] = ClassPathResource("persona/text/large/hyphens.svg")
.getContentAsString(Charset.defaultCharset())
map
}.value

val mediumNumberSvgs = lazy {
val list = mutableListOf<String>()
for (i in 0..9) {
val path = "classpath:persona/text/medium/$i.svg"
val path = "persona/text/medium/$i.svg"
list.add(
ClassPathResource(path)
.getContentAsString(Charset.defaultCharset())
Expand All @@ -181,7 +182,7 @@ val mediumNumberSvgs = lazy {
val numberSvgs = lazy {
val list = mutableListOf<String>()
for (i in 0..9) {
val path = "classpath:persona/text/small/$i.svg"
val path = "persona/text/small/$i.svg"
list.add(
ClassPathResource(path)
.getContentAsString(Charset.defaultCharset())
Expand Down
14 changes: 10 additions & 4 deletions src/main/kotlin/org/gitanimals/render/domain/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package org.gitanimals.render.domain
import jakarta.persistence.*
import org.gitanimals.render.core.AggregateRoot
import org.gitanimals.render.domain.value.Contribution
import org.gitanimals.render.domain.value.Level
import org.hibernate.annotations.BatchSize
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random

@AggregateRoot
@Entity(name = "user")
Expand Down Expand Up @@ -76,8 +76,13 @@ class User(

private fun levelUpPersonas(newContribution: Int) {
repeat(newContribution) {
val persona = personas[Random.nextInt(0, personas.size)]
persona.level.value++
runCatching {
val persona = personas.random()
persona.level.value++
}.onFailure {
it.printStackTrace()
throw it
}
}
}

Expand All @@ -88,7 +93,8 @@ class User(
if (personas.size >= MAX_PERSONA_COUNT) {
return
}
personas.add(Persona(PersonaType.random(), 0))
val newPersona = Persona(type = PersonaType.random(), level = Level(0), user = this)
personas.add(newPersona)
}

fun increaseVisitCount() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/gitanimals/render/domain/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class UserService(
@Retryable(retryFor = [OptimisticLockingFailureException::class], maxAttempts = 10)
@Transactional
fun updateContributions(username: String, contribution: Int) {
getUserByName(username).updateContribution(contribution)
getUserByName(username)
.updateContribution(contribution)
}

fun isContributionUpdatedBeforeOneHour(name: String): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import jakarta.persistence.Embeddable
import java.time.Instant

@Embeddable
class Contribution(
data class Contribution(
@Column(name = "year", nullable = false)
val year: Int,
@Column(name = "contribution", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ class GithubContributionApi(
private const val YEAR_FIX = "*{year}"

private val contributionYearQuery: String =
ClassPathResource("classpath:github-graphql/contribution-year.graphql")
ClassPathResource("github-graphql/contribution-year.graphql")
.getContentAsString(Charset.defaultCharset())

private val contributionCountByYearQuery =
ClassPathResource("classpath:github-graphql/contribution-count-by-year.graphql")
ClassPathResource("github-graphql/contribution-count-by-year.graphql")
.getContentAsString(Charset.defaultCharset())
}
}
6 changes: 3 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
server.name=gitanimals-render
server.port=8080

spring.datasource.url=
spring.datasource.url=jdbc:mysql://localhost:3306/gitanimalsrender
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Expand All @@ -11,8 +11,8 @@ spring.jpa.hibernate.ddl-auto=update
spring.jpa.open-in-view=false

netx.mode=redis
netx.host=
netx.port=
netx.host=localhost
netx.port=6379
netx.group=render
netx.node-id=1
netx.node-name=render-1
Expand Down

0 comments on commit c5652a2

Please sign in to comment.