-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from averak/feature/136-friend-get-list-v1
Friend.ListV1を実装
- Loading branch information
Showing
33 changed files
with
5,536 additions
and
95 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/adapter/src/main/kotlin/net/averak/gsync/adapter/handler/player_api/FriendHandler.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,23 @@ | ||
package net.averak.gsync.adapter.handler.player_api | ||
|
||
import net.averak.gsync.adapter.handler.player_api.pbconv.FriendConverter | ||
import net.averak.gsync.infrastructure.grpc.player_api.Request | ||
import net.averak.gsync.schema.protobuf.player_api.FriendListV1 | ||
import net.averak.gsync.schema.protobuf.player_api.IFriendHandler | ||
import net.averak.gsync.usecase.FriendUsecase | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class FriendHandler( | ||
private val friendUsecase: FriendUsecase, | ||
) : IFriendHandler { | ||
|
||
override fun listV1(request: Request<FriendListV1.Request>): FriendListV1.Response { | ||
val result = friendUsecase.list(request.gctx, request.mustPrincipal().playerID) | ||
return FriendListV1.Response.newBuilder() | ||
.addAllFriends(result.friends.map { FriendConverter.toPb(it) }) | ||
.addAllSentFriendRequests(result.sentFriendRequests.map { FriendConverter.toPb(it) }) | ||
.addAllReceivedFriendRequests(result.receivedFriendRequests.map { FriendConverter.toPb(it) }) | ||
.build() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ter/src/main/kotlin/net/averak/gsync/adapter/handler/player_api/pbconv/FriendConverter.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,26 @@ | ||
package net.averak.gsync.adapter.handler.player_api.pbconv | ||
|
||
import net.averak.gsync.domain.model.Friend | ||
import net.averak.gsync.domain.model.FriendRequest | ||
|
||
class FriendConverter { | ||
|
||
companion object { | ||
|
||
@JvmStatic | ||
fun toPb(friend: Friend): net.averak.gsync.schema.protobuf.resource.friend.Friend { | ||
return net.averak.gsync.schema.protobuf.resource.friend.Friend.newBuilder() | ||
.setPlayerId(friend.friendPlayerID.toString()) | ||
.setBecomeFriendAt(LocalDateTimeConverter.toPb(friend.becomeFriendAt)) | ||
.setProfile(PlayerProfileConverter.toPb(friend.profile)).build() | ||
} | ||
|
||
@JvmStatic | ||
fun toPb(friendRequest: FriendRequest): net.averak.gsync.schema.protobuf.resource.friend.FriendRequest { | ||
return net.averak.gsync.schema.protobuf.resource.friend.FriendRequest.newBuilder() | ||
.setSenderPlayerId(friendRequest.playerID.toString()) | ||
.setReceiverPlayerId(friendRequest.receiverPlayerID.toString()) | ||
.setSentAt(LocalDateTimeConverter.toPb(friendRequest.sentAt)).build() | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../main/kotlin/net/averak/gsync/adapter/handler/player_api/pbconv/PlayerProfileConverter.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,17 @@ | ||
package net.averak.gsync.adapter.handler.player_api.pbconv | ||
|
||
import net.averak.gsync.domain.model.PlayerProfile | ||
|
||
class PlayerProfileConverter { | ||
|
||
companion object { | ||
|
||
@JvmStatic | ||
fun toPb(profile: PlayerProfile): net.averak.gsync.schema.protobuf.resource.player.PlayerProfile { | ||
return net.averak.gsync.schema.protobuf.resource.player.PlayerProfile.newBuilder() | ||
.setNickname(profile.nickname) | ||
.setIconId(profile.iconID) | ||
.build() | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...rc/test/groovy/net/averak/gsync/adapter/handler/player_api/FriendHandler_ListV1_IT.groovy
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,64 @@ | ||
package net.averak.gsync.adapter.handler.player_api | ||
|
||
import net.averak.gsync.core.game_context.GameContext | ||
import net.averak.gsync.domain.model.FriendRequest | ||
import net.averak.gsync.domain.model.Friendship | ||
import net.averak.gsync.schema.protobuf.player_api.FriendListV1 | ||
import net.averak.gsync.testkit.AbstractDatabaseSpec | ||
import net.averak.gsync.testkit.Faker | ||
import net.averak.gsync.testkit.fixture.builder.player.PlayerDataBuilder | ||
|
||
import java.time.LocalDateTime | ||
|
||
class FriendHandler_ListV1_IT extends AbstractDatabaseSpec { | ||
|
||
def "正常系"() { | ||
given: | ||
final gctx = Faker.fake(GameContext) | ||
playerUp.setup( | ||
gctx, | ||
new PlayerDataBuilder(Faker.uuidv5("p1")).build(), | ||
new PlayerDataBuilder(Faker.uuidv5("p2")).build(), | ||
new PlayerDataBuilder(Faker.uuidv5("p3")).build(), | ||
new PlayerDataBuilder(Faker.uuidv5("p4")).build(), | ||
new PlayerDataBuilder(Faker.uuidv5("p5")).build(), | ||
) | ||
playerUp.setup( | ||
gctx, | ||
new PlayerDataBuilder(Faker.uuidv5("p1")) | ||
.friendships( | ||
new Friendship(Faker.uuidv5("p1"), Faker.uuidv5("p2"), LocalDateTime.now()), | ||
new Friendship(Faker.uuidv5("p1"), Faker.uuidv5("p3"), LocalDateTime.now()), | ||
) | ||
.friendRequests( | ||
new FriendRequest(Faker.uuidv5("p1"), Faker.uuidv5("p4"), LocalDateTime.now()), | ||
) | ||
.build(), | ||
new PlayerDataBuilder(Faker.uuidv5("p5")) | ||
.friendRequests( | ||
new FriendRequest(Faker.uuidv5("p5"), Faker.uuidv5("p1"), LocalDateTime.now()), | ||
) | ||
.build(), | ||
) | ||
|
||
when: | ||
final response = grpcTester.invoke( | ||
grpcTester.friend.&listV1, | ||
FriendListV1.Request.newBuilder().build(), | ||
) { | ||
it.session(Faker.uuidv5("p1"), Faker.uuidv5("g1")) | ||
it.spoofingMasterVersion(gctx.masterVersion) | ||
} | ||
|
||
then: | ||
with(response.message.friendsList) { | ||
it*.playerId == [Faker.uuidv5("p2").toString(), Faker.uuidv5("p3").toString()] | ||
} | ||
with(response.message.sentFriendRequestsList) { | ||
it*.receiverPlayerId == [Faker.uuidv5("p4").toString()] | ||
} | ||
with(response.message.receivedFriendRequestsList) { | ||
it*.senderPlayerId == [Faker.uuidv5("p5").toString()] | ||
} | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
app/usecase/src/main/kotlin/net/averak/gsync/usecase/FriendUsecase.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,35 @@ | ||
package net.averak.gsync.usecase | ||
|
||
import net.averak.gsync.core.game_context.GameContext | ||
import net.averak.gsync.domain.model.Friend | ||
import net.averak.gsync.domain.model.FriendRequest | ||
import net.averak.gsync.domain.repository.IFriendRepository | ||
import net.averak.gsync.usecase.transaction.ITransaction | ||
import org.springframework.stereotype.Service | ||
import java.util.* | ||
|
||
@Service | ||
class FriendUsecase( | ||
private val transaction: ITransaction, | ||
private val friendRepository: IFriendRepository, | ||
) { | ||
|
||
fun list(gctx: GameContext, playerID: UUID): ListResult { | ||
return transaction.roTx { | ||
val friends = friendRepository.getFriends(gctx, playerID) | ||
val sentFriendRequests = friendRepository.getSentFriendRequests(gctx, playerID) | ||
val receivedFriendRequests = friendRepository.getReceivedFriendRequests(gctx, playerID) | ||
return@roTx ListResult( | ||
friends = friends, | ||
sentFriendRequests = sentFriendRequests, | ||
receivedFriendRequests = receivedFriendRequests, | ||
) | ||
} | ||
} | ||
|
||
data class ListResult( | ||
val friends: List<Friend>, | ||
val sentFriendRequests: List<FriendRequest>, | ||
val receivedFriendRequests: List<FriendRequest>, | ||
) | ||
} |
Oops, something went wrong.