Skip to content

Commit

Permalink
release: 0.1.0 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Apr 12, 2024
2 parents c5652a2 + 8b5db3a commit d25bfa7
Show file tree
Hide file tree
Showing 52 changed files with 5,428 additions and 5,073 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/org/gitanimals/render/app/AnimationFacade.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gitanimals.render.app

import jakarta.annotation.PostConstruct
import org.gitanimals.render.domain.AnimationMode
import org.gitanimals.render.domain.User
import org.gitanimals.render.domain.UserService
import org.gitanimals.render.domain.event.Visited
Expand All @@ -17,18 +18,19 @@ class AnimationFacade(

private lateinit var registerNewUserOrchestrator: Orchestrator<String, User>

fun getSvgAnimationByUsername(username: String): String {
fun getSvgAnimation(username: String, mode: String): String {
val animationMode = AnimationMode.valueOf(mode.uppercase())
return when (userService.existsByName(username)) {
true -> {
val svgAnimation = userService.getSvgAnimationByUsername(username)
val svgAnimation = userService.getSvgAnimationByUsername(username, animationMode)
sagaManager.startSync(Visited(username))
svgAnimation
}

false -> {
registerNewUserOrchestrator.sagaSync(10000, username)

userService.getSvgAnimationByUsername(username)
userService.getSvgAnimationByUsername(username, animationMode)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.gitanimals.render.app.AnimationFacade
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
Expand All @@ -16,10 +17,11 @@ class AnimationController(
@GetMapping(value = ["/{username}"], produces = ["image/svg+xml"])
fun getSvgAnimation(
@PathVariable("username") username: String,
@RequestParam(name = "mode", defaultValue = "FARM") mode: String,
response: HttpServletResponse
): String {
response.noCache()
return animationFacade.getSvgAnimationByUsername(username)
return animationFacade.getSvgAnimation(username, mode)
}

fun HttpServletResponse.noCache(): HttpServletResponse {
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/org/gitanimals/render/domain/AnimationMode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.gitanimals.render.domain

enum class AnimationMode(
private val func: (User) -> String,
) {

FARM({ it.createFarmAnimation() }),
LINE({ it.createLineAnimation() }),
;
fun createAnimation(user: User): String = func.invoke(user)
}
Loading

0 comments on commit d25bfa7

Please sign in to comment.