Skip to content

Commit

Permalink
Expose group currencies API
Browse files Browse the repository at this point in the history
  • Loading branch information
madhead committed Oct 20, 2023
1 parent bfc2b6d commit f537e54
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ class GroupCurrenciesService(
/**
* Lists currencies used in transactions of the [group].
*/
fun groupCurrencies(group: Long): List<String> {
fun groupCurrencies(group: Long): List<String>? {
return balanceRepository
.get(group)
?.balance
?.keys
?.takeUnless { it.isEmpty() }
?.toList()
?: listOf("USD", "EUR", "RUB")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ class AmountReplyUpdateProcessor(
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyMarkup = dev.inmo.tgbotapi.types.buttons.ReplyKeyboardMarkup(
keyboard = groupCurrenciesService
.groupCurrencies(update.groupId)
keyboard = (groupCurrenciesService.groupCurrencies(update.groupId) ?: listOf("USD", "EUR", "RUB"))
.map { listOf(SimpleKeyboardButton(it)) },
resizeKeyboard = true,
oneTimeKeyboard = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.ktor.server.routing.Route
import io.ktor.server.routing.get
import io.ktor.server.routing.localPort
import io.ktor.server.routing.route
import me.madhead.tyzenhaus.core.service.GroupCurrenciesService
import me.madhead.tyzenhaus.core.service.GroupMembersService
import me.madhead.tyzenhaus.launcher.fly.security.APITokenPrincipal
import org.koin.ktor.ext.inject
Expand All @@ -20,18 +21,28 @@ import org.koin.ktor.ext.inject
fun Route.miniAppAPI() {
val config by inject<ApplicationConfig>()
val groupMembersService by inject<GroupMembersService>()
val groupCurrenciesService by inject<GroupCurrenciesService>()

localPort(config.property("deployment.port").getString().toInt()) {
route("/app/api") {
authenticate("api") {
get("/group/members") {
val principal = call.principal<APITokenPrincipal>()!!
val members = groupMembersService.groupMembers(principal.groupId)
authenticate("api") {
route("/app/api") {
route("group") {
get("members") {
val principal = call.principal<APITokenPrincipal>()!!
val members = groupMembersService.groupMembers(principal.groupId)

if (members != null) {
call.respond(members)
} else {
call.respond(HttpStatusCode.NotFound)
if (members != null) {
call.respond(members)
} else {
call.respond(HttpStatusCode.NotFound)
}
}

get("currencies") {
val principal = call.principal<APITokenPrincipal>()!!
val currencies = groupCurrenciesService.groupCurrencies(principal.groupId) ?: emptyList()

call.respond(currencies)
}
}
}
Expand Down

0 comments on commit f537e54

Please sign in to comment.