diff --git a/services-api/pkg/service/cloudSaveService.go b/services-api/pkg/service/cloudSaveService.go deleted file mode 100644 index d1282c5dc..000000000 --- a/services-api/pkg/service/cloudSaveService.go +++ /dev/null @@ -1,915 +0,0 @@ -package service - -import ( - "encoding/json" - "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/admin_game_record" - "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/admin_player_record" - "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/concurrent_record" - - "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient" - "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/public_game_record" - "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/public_player_record" - "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclientmodels" - "github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository" - "github.com/go-openapi/runtime/client" - "github.com/sirupsen/logrus" -) - -type CloudSaveService struct { - CloudSaveServiceClient *cloudsaveclient.JusticeCloudsaveService - TokenRepository repository.TokenRepository -} - -// AdminDeleteGameRecordHandlerV1 is used to purge all records under the given key -func (couldSaveService *CloudSaveService) AdminDeleteGameRecordHandlerV1(key, namespace string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_game_record.AdminDeleteGameRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminGameRecord.AdminDeleteGameRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// AdminGetGameRecordHandlerV1 is used to retrieve a record value by its key -func (couldSaveService *CloudSaveService) AdminGetGameRecordHandlerV1(key, namespace string) (*cloudsaveclientmodels.ModelsGameRecord, error) { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return nil, err - } - param := &admin_game_record.AdminGetGameRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - } - ok, unauthorized, notFound, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminGameRecord.AdminGetGameRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, unauthorized - } - if notFound != nil { - errorMsg, _ := json.Marshal(*notFound.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, notFound - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, internalServerError - } - if err != nil { - logrus.Error(err) - return nil, err - } - return ok.GetPayload(), nil -} - -// AdminPostGameRecordHandlerV1 is used to save namespace level record -func (couldSaveService *CloudSaveService) AdminPostGameRecordHandlerV1(body cloudsaveclientmodels.ModelsGameRecordRequest, key, namespace string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_game_record.AdminPostGameRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminGameRecord.AdminPostGameRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// AdminPutGameRecordHandlerV1 is used to save or replace game record -func (couldSaveService *CloudSaveService) AdminPutGameRecordHandlerV1(body cloudsaveclientmodels.ModelsGameRecordRequest, key, namespace string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_game_record.AdminPutGameRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminGameRecord.AdminPutGameRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// ListGameRecordsHandlerV1 is used to retrieve a record value by its key -func (couldSaveService *CloudSaveService) ListGameRecordsHandlerV1(namespace string, limit, offset int64) (*cloudsaveclientmodels.ModelsListGameRecordKeys, error) { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return nil, err - } - param := &admin_game_record.ListGameRecordsHandlerV1Params{ - Limit: limit, - Namespace: namespace, - Offset: offset, - } - ok, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminGameRecord.ListGameRecordsHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, internalServerError - } - if err != nil { - logrus.Error(err) - return nil, err - } - return ok.GetPayload(), nil -} - -// AdminDeletePlayerPublicRecordHandlerV1 is used to delete player public record based on its key -func (couldSaveService *CloudSaveService) AdminDeletePlayerPublicRecordHandlerV1(key, namespace, userId string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_player_record.AdminDeletePlayerPublicRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, notFound, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.AdminDeletePlayerPublicRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if notFound != nil { - errorMsg, _ := json.Marshal(*notFound.GetPayload()) - logrus.Error(string(errorMsg)) - return notFound - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// AdminDeletePlayerRecordHandlerV1 is used to purge player record based on its key -func (couldSaveService *CloudSaveService) AdminDeletePlayerRecordHandlerV1(key, namespace, userId string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_player_record.AdminDeletePlayerRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.AdminDeletePlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// AdminGetPlayerPublicRecordHandlerV1 is used to retrieve a record value by its key -func (couldSaveService *CloudSaveService) AdminGetPlayerPublicRecordHandlerV1(key, namespace, userId string) (*cloudsaveclientmodels.ModelsPlayerRecord, error) { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return nil, err - } - param := &admin_player_record.AdminGetPlayerPublicRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - UserID: userId, - } - ok, unauthorized, notFound, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.AdminGetPlayerPublicRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, unauthorized - } - if notFound != nil { - errorMsg, _ := json.Marshal(*notFound.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, notFound - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, internalServerError - } - if err != nil { - logrus.Error(err) - return nil, err - } - return ok.GetPayload(), nil -} - -// AdminGetPlayerRecordHandlerV1 is used to retrieve a record value by its key -func (couldSaveService *CloudSaveService) AdminGetPlayerRecordHandlerV1(key, namespace, userId string) (*cloudsaveclientmodels.ModelsPlayerRecord, error) { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return nil, err - } - param := &admin_player_record.AdminGetPlayerRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - UserID: userId, - } - ok, unauthorized, notFound, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.AdminGetPlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, unauthorized - } - if notFound != nil { - errorMsg, _ := json.Marshal(*notFound.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, notFound - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, internalServerError - } - if err != nil { - logrus.Error(err) - return nil, err - } - return ok.GetPayload(), nil -} - -// AdminPostPlayerPublicRecordHandlerV1 is used to save user level record -func (couldSaveService *CloudSaveService) AdminPostPlayerPublicRecordHandlerV1(body cloudsaveclientmodels.ModelsPlayerRecordRequest, key, namespace, userId string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_player_record.AdminPostPlayerPublicRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, badRequest, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.AdminPostPlayerPublicRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if badRequest != nil { - errorMsg, _ := json.Marshal(*badRequest.GetPayload()) - logrus.Error(string(errorMsg)) - return badRequest - } - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// AdminPostPlayerRecordHandlerV1 is used to save user level record -func (couldSaveService *CloudSaveService) AdminPostPlayerRecordHandlerV1(body cloudsaveclientmodels.ModelsPlayerRecordRequest, key, namespace, userId string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_player_record.AdminPostPlayerRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.AdminPostPlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// AdminPutPlayerPublicRecordHandlerV1 is used to create or replace player record -func (couldSaveService *CloudSaveService) AdminPutPlayerPublicRecordHandlerV1(body cloudsaveclientmodels.ModelsPlayerRecordRequest, key, namespace, userId string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_player_record.AdminPutPlayerPublicRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, badRequest, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.AdminPutPlayerPublicRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if badRequest != nil { - errorMsg, _ := json.Marshal(*badRequest.GetPayload()) - logrus.Error(string(errorMsg)) - return badRequest - } - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// AdminPutPlayerRecordHandlerV1 is used to create or replace player record -func (couldSaveService *CloudSaveService) AdminPutPlayerRecordHandlerV1(body cloudsaveclientmodels.ModelsPlayerRecordRequest, key, namespace, userId string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &admin_player_record.AdminPutPlayerRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.AdminPutPlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// ListPlayerRecordHandlerV1 is used to retrieve list of public player records -func (couldSaveService *CloudSaveService) ListPlayerRecordHandlerV1(namespace string, query *string, limit, offset *int64) (*cloudsaveclientmodels.ModelsListPlayerRecordKeys, error) { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return nil, err - } - param := &admin_player_record.ListPlayerRecordHandlerV1Params{ - Limit: limit, - Namespace: namespace, - Offset: offset, - Query: query, - } - ok, badRequest, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.AdminPlayerRecord.ListPlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if badRequest != nil { - errorMsg, _ := json.Marshal(*badRequest.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, badRequest - } - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, internalServerError - } - if err != nil { - logrus.Error(err) - return nil, err - } - return ok.GetPayload(), nil -} - -// PutGameRecordConcurrentHandlerV1 is used to create or replace player record -func (couldSaveService *CloudSaveService) PutGameRecordConcurrentHandlerV1(body *cloudsaveclientmodels.ModelsConcurrentRecordRequest, key, namespace string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &concurrent_record.PutGameRecordConcurrentHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - } - _, badRequest, unauthorized, preconditionFailed, internalServerError, err := couldSaveService.CloudSaveServiceClient.ConcurrentRecord.PutGameRecordConcurrentHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if badRequest != nil { - errorMsg, _ := json.Marshal(*badRequest.GetPayload()) - logrus.Error(string(errorMsg)) - return badRequest - } - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if preconditionFailed != nil { - errorMsg, _ := json.Marshal(*preconditionFailed.GetPayload()) - logrus.Error(string(errorMsg)) - return preconditionFailed - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// PutPlayerPublicRecordConcurrentHandlerV1 is used to create or replace player record -func (couldSaveService *CloudSaveService) PutPlayerPublicRecordConcurrentHandlerV1(body *cloudsaveclientmodels.ModelsConcurrentRecordRequest, key, namespace, userId string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &concurrent_record.PutPlayerPublicRecordConcurrentHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, badRequest, unauthorized, preconditionFailed, internalServerError, err := couldSaveService.CloudSaveServiceClient.ConcurrentRecord.PutPlayerPublicRecordConcurrentHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if badRequest != nil { - errorMsg, _ := json.Marshal(*badRequest.GetPayload()) - logrus.Error(string(errorMsg)) - return badRequest - } - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if preconditionFailed != nil { - errorMsg, _ := json.Marshal(*preconditionFailed.GetPayload()) - logrus.Error(string(errorMsg)) - return preconditionFailed - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// PostGameRecordHandlerV1 is used for create or append game record -func (couldSaveService *CloudSaveService) PostGameRecordHandlerV1(body cloudsaveclientmodels.ModelsGameRecordRequest, key, namespace string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_game_record.PostGameRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - } - _, badRequest, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicGameRecord.PostGameRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if badRequest != nil { - errorMsg, _ := json.Marshal(*badRequest.GetPayload()) - logrus.Error(string(errorMsg)) - return badRequest - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// GetGameRecordHandlerV1 is used to get game record -func (couldSaveService *CloudSaveService) GetGameRecordHandlerV1(key, namespace string) (*cloudsaveclientmodels.ModelsGameRecord, error) { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return nil, err - } - param := &public_game_record.GetGameRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - } - ok, unauthorized, notFound, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicGameRecord.GetGameRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, unauthorized - } - if notFound != nil { - errorMsg, _ := json.Marshal(*notFound.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, notFound - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, internalServerError - } - if err != nil { - logrus.Error(err) - return nil, err - } - return ok.GetPayload(), nil -} - -// DeleteGameRecordHandlerV1 is used to delete game record -func (couldSaveService *CloudSaveService) DeleteGameRecordHandlerV1(key, namespace string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_game_record.DeleteGameRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicGameRecord.DeleteGameRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// PutGameRecordHandlerV1 is used for create or append game record -func (couldSaveService *CloudSaveService) PutGameRecordHandlerV1(body cloudsaveclientmodels.ModelsGameRecordRequest, key, namespace string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_game_record.PutGameRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - } - _, badRequest, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicGameRecord.PutGameRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if badRequest != nil { - errorMsg, _ := json.Marshal(*badRequest.GetPayload()) - logrus.Error(string(errorMsg)) - return badRequest - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// PostPlayerPublicRecordHandlerV1 is used to create public player record -func (couldSaveService *CloudSaveService) PostPlayerPublicRecordHandlerV1(userId, namespace, key string, content map[string]string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_player_record.PostPlayerPublicRecordHandlerV1Params{ - Body: content, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicPlayerRecord.PostPlayerPublicRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// GetPlayerPublicRecordHandlerV1 is used to get other player's public record -func (couldSaveService *CloudSaveService) GetPlayerPublicRecordHandlerV1(userId, namespace, key string) (*cloudsaveclientmodels.ModelsPlayerRecord, error) { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return nil, err - } - param := &public_player_record.GetPlayerPublicRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - UserID: userId, - } - ok, unauthorized, notFound, internalServerError, err := - couldSaveService.CloudSaveServiceClient.PublicPlayerRecord.GetPlayerPublicRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, unauthorized - } - if notFound != nil { - errorMsg, _ := json.Marshal(*notFound.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, notFound - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, internalServerError - } - if err != nil { - logrus.Error(err) - return nil, err - } - return ok.GetPayload(), nil -} - -// DeletePlayerRecordHandlerV1 is used to delete player record -func (couldSaveService *CloudSaveService) DeletePlayerRecordHandlerV1(userId, namespace, key string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_player_record.DeletePlayerRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicPlayerRecord.DeletePlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// GetPlayerRecordHandlerV1 is used to get player record -func (couldSaveService *CloudSaveService) GetPlayerRecordHandlerV1(userId, namespace, key string) (*cloudsaveclientmodels.ModelsPlayerRecord, error) { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return nil, err - } - param := &public_player_record.GetPlayerRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - UserID: userId, - } - ok, unauthorized, notFound, internalServerError, err := - couldSaveService.CloudSaveServiceClient.PublicPlayerRecord.GetPlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, unauthorized - } - if notFound != nil { - errorMsg, _ := json.Marshal(*notFound.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, notFound - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return nil, internalServerError - } - if err != nil { - logrus.Error(err) - return nil, err - } - return ok.GetPayload(), nil -} - -// PostPlayerRecordHandlerV1 is used to create or append player record -func (couldSaveService *CloudSaveService) PostPlayerRecordHandlerV1(userId, namespace, key string, body cloudsaveclientmodels.ModelsPlayerRecordRequest) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_player_record.PostPlayerRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicPlayerRecord.PostPlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// PublicDeletePlayerPublicRecordHandlerV1 is used to delete player public record based on its key -func (couldSaveService *CloudSaveService) PublicDeletePlayerPublicRecordHandlerV1(namespace, key string) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_player_record.PublicDeletePlayerPublicRecordHandlerV1Params{ - Key: key, - Namespace: namespace, - } - _, unauthorized, notFound, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicPlayerRecord.PublicDeletePlayerPublicRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if notFound != nil { - errorMsg, _ := json.Marshal(*notFound.GetPayload()) - logrus.Error(string(errorMsg)) - return notFound - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// PutPlayerPublicRecordHandlerV1 is used to create or replace player record -func (couldSaveService *CloudSaveService) PutPlayerPublicRecordHandlerV1(userId, namespace, key string, body cloudsaveclientmodels.ModelsPlayerRecordRequest) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_player_record.PutPlayerPublicRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicPlayerRecord.PutPlayerPublicRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} - -// PutPlayerRecordHandlerV1 is used to create or replace player record -func (couldSaveService *CloudSaveService) PutPlayerRecordHandlerV1(userId, namespace, key string, body cloudsaveclientmodels.ModelsPlayerRecordRequest) error { - accessToken, err := couldSaveService.TokenRepository.GetToken() - if err != nil { - return err - } - param := &public_player_record.PutPlayerRecordHandlerV1Params{ - Body: body, - Key: key, - Namespace: namespace, - UserID: userId, - } - _, unauthorized, internalServerError, err := couldSaveService.CloudSaveServiceClient.PublicPlayerRecord.PutPlayerRecordHandlerV1(param, client.BearerToken(*accessToken.AccessToken)) - if unauthorized != nil { - errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) - logrus.Error(string(errorMsg)) - return unauthorized - } - if internalServerError != nil { - errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) - logrus.Error(string(errorMsg)) - return internalServerError - } - if err != nil { - logrus.Error(err) - return err - } - return nil -} diff --git a/services-api/pkg/service/cloudsave/adminGameRecord.go b/services-api/pkg/service/cloudsave/adminGameRecord.go new file mode 100644 index 000000000..83dce9f78 --- /dev/null +++ b/services-api/pkg/service/cloudsave/adminGameRecord.go @@ -0,0 +1,171 @@ +package cloudsave + +import ( + "encoding/json" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/admin_game_record" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/admin_player_record" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclientmodels" + "github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository" + "github.com/go-openapi/runtime/client" + "github.com/sirupsen/logrus" +) + +type AdminGameRecordService struct { + Client *cloudsaveclient.JusticeCloudsaveService + TokenRepository repository.TokenRepository +} + +// AdminDeleteGameRecordHandlerV1 is used to purge all records under the given key +func (a *AdminGameRecordService) AdminDeleteGameRecordHandlerV1(input *admin_game_record.AdminDeleteGameRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := a.Client.AdminGameRecord.AdminDeleteGameRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// AdminGetGameRecordHandlerV1 is used to retrieve a record value by its key +func (a *AdminGameRecordService) AdminGetGameRecordHandlerV1(input *admin_game_record.AdminGetGameRecordHandlerV1Params) (*cloudsaveclientmodels.ModelsGameRecord, error) { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return nil, err + } + ok, unauthorized, notFound, internalServerError, err := a.Client.AdminGameRecord.AdminGetGameRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, unauthorized + } + if notFound != nil { + errorMsg, _ := json.Marshal(*notFound.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, notFound + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, internalServerError + } + if err != nil { + logrus.Error(err) + return nil, err + } + return ok.GetPayload(), nil +} + +// AdminPostGameRecordHandlerV1 is used to save namespace level record +func (a *AdminGameRecordService) AdminPostGameRecordHandlerV1(input *admin_game_record.AdminPostGameRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := a.Client.AdminGameRecord.AdminPostGameRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// AdminPutGameRecordHandlerV1 is used to save or replace game record +func (a *AdminGameRecordService) AdminPutGameRecordHandlerV1(input *admin_game_record.AdminPutGameRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := a.Client.AdminGameRecord.AdminPutGameRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// ListGameRecordsHandlerV1 is used to retrieve a record value by its key +func (a *AdminGameRecordService) ListGameRecordsHandlerV1(input *admin_game_record.ListGameRecordsHandlerV1Params) (*cloudsaveclientmodels.ModelsListGameRecordKeys, error) { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return nil, err + } + ok, unauthorized, internalServerError, err := a.Client.AdminGameRecord.ListGameRecordsHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, internalServerError + } + if err != nil { + logrus.Error(err) + return nil, err + } + return ok.GetPayload(), nil +} + +// AdminDeletePlayerPublicRecordHandlerV1 is used to delete player public record based on its key +func (a *AdminGameRecordService) AdminDeletePlayerPublicRecordHandlerV1(input *admin_player_record.AdminDeletePlayerPublicRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, notFound, internalServerError, err := a.Client.AdminPlayerRecord.AdminDeletePlayerPublicRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if notFound != nil { + errorMsg, _ := json.Marshal(*notFound.GetPayload()) + logrus.Error(string(errorMsg)) + return notFound + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} \ No newline at end of file diff --git a/services-api/pkg/service/cloudsave/adminPlayerRecord.go b/services-api/pkg/service/cloudsave/adminPlayerRecord.go new file mode 100644 index 000000000..9166b6e87 --- /dev/null +++ b/services-api/pkg/service/cloudsave/adminPlayerRecord.go @@ -0,0 +1,233 @@ +package cloudsave + +import ( + "encoding/json" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/admin_player_record" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclientmodels" + "github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository" + "github.com/go-openapi/runtime/client" + "github.com/sirupsen/logrus" +) + +type AdminPlayerRecordService struct { + Client *cloudsaveclient.JusticeCloudsaveService + TokenRepository repository.TokenRepository +} + +// AdminDeletePlayerRecordHandlerV1 is used to purge player record based on its key +func (a *AdminPlayerRecordService) AdminDeletePlayerRecordHandlerV1(input *admin_player_record.AdminDeletePlayerRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := a.Client.AdminPlayerRecord.AdminDeletePlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// AdminGetPlayerPublicRecordHandlerV1 is used to retrieve a record value by its key +func (a *AdminPlayerRecordService) AdminGetPlayerPublicRecordHandlerV1(input *admin_player_record.AdminGetPlayerPublicRecordHandlerV1Params) (*cloudsaveclientmodels.ModelsPlayerRecord, error) { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return nil, err + } + ok, unauthorized, notFound, internalServerError, err := a.Client.AdminPlayerRecord.AdminGetPlayerPublicRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, unauthorized + } + if notFound != nil { + errorMsg, _ := json.Marshal(*notFound.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, notFound + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, internalServerError + } + if err != nil { + logrus.Error(err) + return nil, err + } + return ok.GetPayload(), nil +} + +// AdminGetPlayerRecordHandlerV1 is used to retrieve a record value by its key +func (a *AdminPlayerRecordService) AdminGetPlayerRecordHandlerV1(input *admin_player_record.AdminGetPlayerRecordHandlerV1Params) (*cloudsaveclientmodels.ModelsPlayerRecord, error) { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return nil, err + } + ok, unauthorized, notFound, internalServerError, err := a.Client.AdminPlayerRecord.AdminGetPlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, unauthorized + } + if notFound != nil { + errorMsg, _ := json.Marshal(*notFound.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, notFound + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, internalServerError + } + if err != nil { + logrus.Error(err) + return nil, err + } + return ok.GetPayload(), nil +} + +// AdminPostPlayerPublicRecordHandlerV1 is used to save user level record +func (a *AdminPlayerRecordService) AdminPostPlayerPublicRecordHandlerV1(input *admin_player_record.AdminPostPlayerPublicRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, badRequest, unauthorized, internalServerError, err := a.Client.AdminPlayerRecord.AdminPostPlayerPublicRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if badRequest != nil { + errorMsg, _ := json.Marshal(*badRequest.GetPayload()) + logrus.Error(string(errorMsg)) + return badRequest + } + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// AdminPostPlayerRecordHandlerV1 is used to save user level record +func (a *AdminPlayerRecordService) AdminPostPlayerRecordHandlerV1(input *admin_player_record.AdminPostPlayerRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := a.Client.AdminPlayerRecord.AdminPostPlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// AdminPutPlayerPublicRecordHandlerV1 is used to create or replace player record +func (a *AdminPlayerRecordService) AdminPutPlayerPublicRecordHandlerV1(input *admin_player_record.AdminPutPlayerPublicRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, badRequest, unauthorized, internalServerError, err := a.Client.AdminPlayerRecord.AdminPutPlayerPublicRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if badRequest != nil { + errorMsg, _ := json.Marshal(*badRequest.GetPayload()) + logrus.Error(string(errorMsg)) + return badRequest + } + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// AdminPutPlayerRecordHandlerV1 is used to create or replace player record +func (a *AdminPlayerRecordService) AdminPutPlayerRecordHandlerV1(input *admin_player_record.AdminPutPlayerRecordHandlerV1Params) error { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := a.Client.AdminPlayerRecord.AdminPutPlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// ListPlayerRecordHandlerV1 is used to retrieve list of public player records +func (a *AdminPlayerRecordService) ListPlayerRecordHandlerV1(input *admin_player_record.ListPlayerRecordHandlerV1Params) (*cloudsaveclientmodels.ModelsListPlayerRecordKeys, error) { + accessToken, err := a.TokenRepository.GetToken() + if err != nil { + return nil, err + } + ok, badRequest, unauthorized, internalServerError, err := a.Client.AdminPlayerRecord.ListPlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if badRequest != nil { + errorMsg, _ := json.Marshal(*badRequest.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, badRequest + } + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, internalServerError + } + if err != nil { + logrus.Error(err) + return nil, err + } + return ok.GetPayload(), nil +} diff --git a/services-api/pkg/service/cloudsave/concurrentRecord.go b/services-api/pkg/service/cloudsave/concurrentRecord.go new file mode 100644 index 000000000..aed69f46d --- /dev/null +++ b/services-api/pkg/service/cloudsave/concurrentRecord.go @@ -0,0 +1,83 @@ +package cloudsave + +import ( + "encoding/json" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/concurrent_record" + "github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository" + "github.com/go-openapi/runtime/client" + "github.com/sirupsen/logrus" +) + +type ConcurrentRecordService struct { + Client *cloudsaveclient.JusticeCloudsaveService + TokenRepository repository.TokenRepository +} + +// PutGameRecordConcurrentHandlerV1 is used to create or replace player record +func (c *ConcurrentRecordService) PutGameRecordConcurrentHandlerV1(input *concurrent_record.PutGameRecordConcurrentHandlerV1Params) error { + accessToken, err := c.TokenRepository.GetToken() + if err != nil { + return err + } + _, badRequest, unauthorized, preconditionFailed, internalServerError, err := c.Client.ConcurrentRecord.PutGameRecordConcurrentHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if badRequest != nil { + errorMsg, _ := json.Marshal(*badRequest.GetPayload()) + logrus.Error(string(errorMsg)) + return badRequest + } + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if preconditionFailed != nil { + errorMsg, _ := json.Marshal(*preconditionFailed.GetPayload()) + logrus.Error(string(errorMsg)) + return preconditionFailed + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// PutPlayerPublicRecordConcurrentHandlerV1 is used to create or replace player record +func (c *ConcurrentRecordService) PutPlayerPublicRecordConcurrentHandlerV1(input *concurrent_record.PutPlayerPublicRecordConcurrentHandlerV1Params) error { + accessToken, err := c.TokenRepository.GetToken() + if err != nil { + return err + } + _, badRequest, unauthorized, preconditionFailed, internalServerError, err := c.Client.ConcurrentRecord.PutPlayerPublicRecordConcurrentHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if badRequest != nil { + errorMsg, _ := json.Marshal(*badRequest.GetPayload()) + logrus.Error(string(errorMsg)) + return badRequest + } + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if preconditionFailed != nil { + errorMsg, _ := json.Marshal(*preconditionFailed.GetPayload()) + logrus.Error(string(errorMsg)) + return preconditionFailed + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} diff --git a/services-api/pkg/service/cloudsave/publicGameRecord.go b/services-api/pkg/service/cloudsave/publicGameRecord.go new file mode 100644 index 000000000..75eab5969 --- /dev/null +++ b/services-api/pkg/service/cloudsave/publicGameRecord.go @@ -0,0 +1,118 @@ +package cloudsave + +import ( + "encoding/json" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/public_game_record" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclientmodels" + "github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository" + "github.com/go-openapi/runtime/client" + "github.com/sirupsen/logrus" +) + +type PublicGameRecordService struct { + Client *cloudsaveclient.JusticeCloudsaveService + TokenRepository repository.TokenRepository +} + +// PostGameRecordHandlerV1 is used for create or append game record +func (p *PublicGameRecordService) PostGameRecordHandlerV1(input *public_game_record.PostGameRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, badRequest, internalServerError, err := p.Client.PublicGameRecord.PostGameRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if badRequest != nil { + errorMsg, _ := json.Marshal(*badRequest.GetPayload()) + logrus.Error(string(errorMsg)) + return badRequest + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// GetGameRecordHandlerV1 is used to get game record +func (p *PublicGameRecordService) GetGameRecordHandlerV1(input *public_game_record.GetGameRecordHandlerV1Params) (*cloudsaveclientmodels.ModelsGameRecord, error) { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return nil, err + } + ok, unauthorized, notFound, internalServerError, err := p.Client.PublicGameRecord.GetGameRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, unauthorized + } + if notFound != nil { + errorMsg, _ := json.Marshal(*notFound.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, notFound + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, internalServerError + } + if err != nil { + logrus.Error(err) + return nil, err + } + return ok.GetPayload(), nil +} + +// DeleteGameRecordHandlerV1 is used to delete game record +func (p *PublicGameRecordService) DeleteGameRecordHandlerV1(input *public_game_record.DeleteGameRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := p.Client.PublicGameRecord.DeleteGameRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// PutGameRecordHandlerV1 is used for create or append game record +func (p *PublicGameRecordService) PutGameRecordHandlerV1(input *public_game_record.PutGameRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, badRequest, internalServerError, err := p.Client.PublicGameRecord.PutGameRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if badRequest != nil { + errorMsg, _ := json.Marshal(*badRequest.GetPayload()) + logrus.Error(string(errorMsg)) + return badRequest + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + diff --git a/services-api/pkg/service/cloudsave/publicPlayerRecord.go b/services-api/pkg/service/cloudsave/publicPlayerRecord.go new file mode 100644 index 000000000..84795c509 --- /dev/null +++ b/services-api/pkg/service/cloudsave/publicPlayerRecord.go @@ -0,0 +1,226 @@ +package cloudsave + +import ( + "encoding/json" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclient/public_player_record" + "github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclientmodels" + "github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository" + "github.com/go-openapi/runtime/client" + "github.com/sirupsen/logrus" +) + +type PublicPlayerRecordService struct { + Client *cloudsaveclient.JusticeCloudsaveService + TokenRepository repository.TokenRepository +} + +// PostPlayerPublicRecordHandlerV1 is used to create public player record +func (p *PublicPlayerRecordService) PostPlayerPublicRecordHandlerV1(input *public_player_record.PostPlayerPublicRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := p.Client.PublicPlayerRecord.PostPlayerPublicRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// GetPlayerPublicRecordHandlerV1 is used to get other player's public record +func (p *PublicPlayerRecordService) GetPlayerPublicRecordHandlerV1(input *public_player_record.GetPlayerPublicRecordHandlerV1Params) (*cloudsaveclientmodels.ModelsPlayerRecord, error) { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return nil, err + } + ok, unauthorized, notFound, internalServerError, err := + p.Client.PublicPlayerRecord.GetPlayerPublicRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, unauthorized + } + if notFound != nil { + errorMsg, _ := json.Marshal(*notFound.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, notFound + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, internalServerError + } + if err != nil { + logrus.Error(err) + return nil, err + } + return ok.GetPayload(), nil +} + +// DeletePlayerRecordHandlerV1 is used to delete player record +func (p *PublicPlayerRecordService) DeletePlayerRecordHandlerV1(input *public_player_record.DeletePlayerRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := p.Client.PublicPlayerRecord.DeletePlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// GetPlayerRecordHandlerV1 is used to get player record +func (p *PublicPlayerRecordService) GetPlayerRecordHandlerV1(input *public_player_record.GetPlayerRecordHandlerV1Params) (*cloudsaveclientmodels.ModelsPlayerRecord, error) { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return nil, err + } + ok, unauthorized, notFound, internalServerError, err := + p.Client.PublicPlayerRecord.GetPlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, unauthorized + } + if notFound != nil { + errorMsg, _ := json.Marshal(*notFound.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, notFound + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return nil, internalServerError + } + if err != nil { + logrus.Error(err) + return nil, err + } + return ok.GetPayload(), nil +} + +// PostPlayerRecordHandlerV1 is used to create or append player record +func (p *PublicPlayerRecordService) PostPlayerRecordHandlerV1(input *public_player_record.PostPlayerRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := p.Client.PublicPlayerRecord.PostPlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// PublicDeletePlayerPublicRecordHandlerV1 is used to delete player public record based on its key +func (p *PublicPlayerRecordService) PublicDeletePlayerPublicRecordHandlerV1(input *public_player_record.PublicDeletePlayerPublicRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, notFound, internalServerError, err := p.Client.PublicPlayerRecord.PublicDeletePlayerPublicRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if notFound != nil { + errorMsg, _ := json.Marshal(*notFound.GetPayload()) + logrus.Error(string(errorMsg)) + return notFound + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// PutPlayerPublicRecordHandlerV1 is used to create or replace player record +func (p *PublicPlayerRecordService) PutPlayerPublicRecordHandlerV1(input *public_player_record.PutPlayerPublicRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := p.Client.PublicPlayerRecord.PutPlayerPublicRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} + +// PutPlayerRecordHandlerV1 is used to create or replace player record +func (p *PublicPlayerRecordService) PutPlayerRecordHandlerV1(input *public_player_record.PutPlayerRecordHandlerV1Params) error { + accessToken, err := p.TokenRepository.GetToken() + if err != nil { + return err + } + _, unauthorized, internalServerError, err := p.Client.PublicPlayerRecord.PutPlayerRecordHandlerV1(input, client.BearerToken(*accessToken.AccessToken)) + if unauthorized != nil { + errorMsg, _ := json.Marshal(*unauthorized.GetPayload()) + logrus.Error(string(errorMsg)) + return unauthorized + } + if internalServerError != nil { + errorMsg, _ := json.Marshal(*internalServerError.GetPayload()) + logrus.Error(string(errorMsg)) + return internalServerError + } + if err != nil { + logrus.Error(err) + return err + } + return nil +} +