Skip to content

Commit

Permalink
refactor: lobby http sdk wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nurjalal committed Oct 15, 2021
1 parent 22a772a commit 04293c9
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 651 deletions.
6 changes: 3 additions & 3 deletions samples/sample-apps/cmd/addFriends.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"encoding/json"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/factory"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/service"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/service/lobby"
"github.com/AccelByte/sample-apps/pkg/repository"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -18,8 +18,8 @@ var addFriendCmd = &cobra.Command{
Short: "Add multiple friend",
Long: `Add multiple friend`,
RunE: func(cmd *cobra.Command, args []string) error {
friendService := &service.FriendService{
LobbyClient: factory.NewLobbyClient(&repository.ConfigRepositoryImpl{}),
friendService := &lobby.FriendsService{
Client: factory.NewLobbyClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
userId := cmd.Flag("userId").Value.String()
Expand Down
6 changes: 3 additions & 3 deletions samples/sample-apps/cmd/getFriends.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"encoding/json"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/factory"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/service"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/service/lobby"
"github.com/AccelByte/sample-apps/pkg/repository"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -18,8 +18,8 @@ var getFriendsCmd = &cobra.Command{
Short: "Get list of friends",
Long: `Get list of friends`,
RunE: func(cmd *cobra.Command, args []string) error {
friendService := &service.FriendService{
LobbyClient: factory.NewLobbyClient(&repository.ConfigRepositoryImpl{}),
friendService := &lobby.FriendsService{
Client: factory.NewLobbyClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
userId := cmd.Flag("userId").Value.String()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package lobby

import (
"encoding/json"
Expand All @@ -10,22 +10,17 @@ import (
"github.com/sirupsen/logrus"
)

type LobbyChatService struct {
LobbyClient *lobbyclient.JusticeLobbyService
type ChatService struct {
Client *lobbyclient.JusticeLobbyService
TokenRepository repository.TokenRepository
}

func (l *LobbyChatService) AdminChatHistory(friendID, namespace, userID string) ([]*lobbyclientmodels.ModelChatMessageResponse, error) {
token, err := l.TokenRepository.GetToken()
func (c *ChatService) AdminChatHistory(input *chat.AdminChatHistoryParams) ([]*lobbyclientmodels.ModelChatMessageResponse, error) {
token, err := c.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &chat.AdminChatHistoryParams{
FriendID: friendID,
Namespace: namespace,
UserID: userID,
}
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := l.LobbyClient.Chat.AdminChatHistory(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := c.Client.Chat.AdminChatHistory(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down Expand Up @@ -58,16 +53,12 @@ func (l *LobbyChatService) AdminChatHistory(friendID, namespace, userID string)
return ok.GetPayload(), nil
}

func (l *LobbyChatService) GetPersonalChatHistoryV1Public(friendID, namespace string) ([]*lobbyclientmodels.ModelChatMessageResponse, error) {
token, err := l.TokenRepository.GetToken()
func (c *ChatService) GetPersonalChatHistoryV1Public(input *chat.GetPersonalChatHistoryV1PublicParams) ([]*lobbyclientmodels.ModelChatMessageResponse, error) {
token, err := c.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &chat.GetPersonalChatHistoryV1PublicParams{
FriendID: friendID,
Namespace: namespace,
}
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := l.LobbyClient.Chat.GetPersonalChatHistoryV1Public(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := c.Client.Chat.GetPersonalChatHistoryV1Public(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down Expand Up @@ -100,17 +91,12 @@ func (l *LobbyChatService) GetPersonalChatHistoryV1Public(friendID, namespace st
return ok.GetPayload(), nil
}

func (l *LobbyChatService) PersonalChatHistory(friendID, namespace, userID string) ([]*lobbyclientmodels.ModelChatMessageResponse, error) {
token, err := l.TokenRepository.GetToken()
func (c *ChatService) PersonalChatHistory(input *chat.PersonalChatHistoryParams) ([]*lobbyclientmodels.ModelChatMessageResponse, error) {
token, err := c.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &chat.PersonalChatHistoryParams{
FriendID: friendID,
Namespace: namespace,
UserID: userID,
}
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := l.LobbyClient.Chat.PersonalChatHistory(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := c.Client.Chat.PersonalChatHistory(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package lobby

import (
"encoding/json"
Expand All @@ -10,18 +10,18 @@ import (
"github.com/sirupsen/logrus"
)

type LobbyConfigService struct {
LobbyClient *lobbyclient.JusticeLobbyService
type ConfigService struct {
Client *lobbyclient.JusticeLobbyService
TokenRepository repository.TokenRepository
}

func (l *LobbyConfigService) AdminGetAllConfigV1() (*lobbyclientmodels.ModelsConfigList, error) {
token, err := l.TokenRepository.GetToken()
func (c *ConfigService) AdminGetAllConfigV1() (*lobbyclientmodels.ModelsConfigList, error) {
token, err := c.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &config.AdminGetAllConfigV1Params{}
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := l.LobbyClient.Config.AdminGetAllConfigV1(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := c.Client.Config.AdminGetAllConfigV1(params, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down Expand Up @@ -54,15 +54,12 @@ func (l *LobbyConfigService) AdminGetAllConfigV1() (*lobbyclientmodels.ModelsCon
return ok.GetPayload(), nil
}

func (l *LobbyConfigService) AdminGetConfigV1(namespace string) (*lobbyclientmodels.ModelsConfigReq, error) {
token, err := l.TokenRepository.GetToken()
func (c *ConfigService) AdminGetConfigV1(input *config.AdminGetConfigV1Params) (*lobbyclientmodels.ModelsConfigReq, error) {
token, err := c.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &config.AdminGetConfigV1Params{
Namespace: namespace,
}
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := l.LobbyClient.Config.AdminGetConfigV1(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, forbidden, notFound, internalServerError, err := c.Client.Config.AdminGetConfigV1(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down Expand Up @@ -95,16 +92,12 @@ func (l *LobbyConfigService) AdminGetConfigV1(namespace string) (*lobbyclientmod
return ok.GetPayload(), nil
}

func (l *LobbyConfigService) AdminUpdateConfigV1(body *lobbyclientmodels.ModelsConfigReq, namespace string) (*lobbyclientmodels.ModelsConfigReq, error) {
token, err := l.TokenRepository.GetToken()
func (c *ConfigService) AdminUpdateConfigV1(input *config.AdminUpdateConfigV1Params) (*lobbyclientmodels.ModelsConfigReq, error) {
token, err := c.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &config.AdminUpdateConfigV1Params{
Body: body,
Namespace: namespace,
}
ok, badRequest, unauthorized, forbidden, notFound, preconditionFailed, internalServerError, err := l.LobbyClient.Config.AdminUpdateConfigV1(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, forbidden, notFound, preconditionFailed, internalServerError, err := c.Client.Config.AdminUpdateConfigV1(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down
Loading

0 comments on commit 04293c9

Please sign in to comment.