-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
80 additions
and
16 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
.../core/currencies/ChatCurrenciesService.kt → ...us/core/service/GroupCurrenciesService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/main/kotlin/me/madhead/tyzenhaus/core/service/GroupMembersService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package me.madhead.tyzenhaus.core.service | ||
|
||
import dev.inmo.tgbotapi.bot.RequestsExecutor | ||
import dev.inmo.tgbotapi.types.ChatId | ||
import dev.inmo.tgbotapi.types.UserId | ||
import me.madhead.tyzenhaus.core.telegram.updates.expense.getChatMemberSafe | ||
import me.madhead.tyzenhaus.entity.group.members.GroupMember | ||
import me.madhead.tyzenhaus.entity.group.members.GroupMembers | ||
import me.madhead.tyzenhaus.repository.GroupConfigRepository | ||
|
||
/** | ||
* Lists group members. | ||
*/ | ||
class GroupMembersService( | ||
private val groupConfigRepository: GroupConfigRepository, | ||
private val requestsExecutor: RequestsExecutor, | ||
) { | ||
/** | ||
* Lists members of the [group]. | ||
*/ | ||
suspend fun groupMembers(group: Long): GroupMembers? { | ||
val groupConfig = groupConfigRepository.get(group) ?: return null | ||
val chatMembers = groupConfig.members.map { requestsExecutor.getChatMemberSafe(ChatId(groupConfig.id), UserId(it)) } | ||
|
||
return GroupMembers( | ||
id = groupConfig.id, | ||
members = chatMembers.map { | ||
GroupMember( | ||
id = it.user.id.chatId, | ||
firstName = it.user.firstName, | ||
lastName = it.user.lastName, | ||
) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
entity/src/main/kotlin/me/madhead/tyzenhaus/entity/group/members/GroupMembers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.madhead.tyzenhaus.entity.group.members | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GroupMember( | ||
val id: Long, | ||
val firstName: String, | ||
val lastName: String, | ||
) | ||
|
||
@Serializable | ||
data class GroupMembers( | ||
val id: Long, | ||
val members: Collection<GroupMember> = emptySet(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
launcher/fly/src/main/kotlin/me/madhead/tyzenhaus/launcher/fly/koin/services.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package me.madhead.tyzenhaus.launcher.fly.koin | ||
|
||
import me.madhead.tyzenhaus.core.service.GroupCurrenciesService | ||
import me.madhead.tyzenhaus.core.service.GroupMembersService | ||
import org.koin.dsl.module | ||
|
||
val serviceModule = module { | ||
single { | ||
GroupCurrenciesService( | ||
balanceRepository = get(), | ||
) | ||
} | ||
|
||
single { | ||
GroupMembersService( | ||
requestsExecutor = get(), | ||
groupConfigRepository = get(), | ||
) | ||
} | ||
} |