Skip to content

Commit

Permalink
refactor: achievement sdk wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nurjalal committed Oct 13, 2021
1 parent 3634041 commit 0313762
Showing 1 changed file with 32 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
package service
package achievement

import (
"encoding/json"
"github.com/AccelByte/accelbyte-go-sdk/achievement-sdk/pkg/achievementclient"
"github.com/AccelByte/accelbyte-go-sdk/achievement-sdk/pkg/achievementclient/achievements"
"github.com/AccelByte/accelbyte-go-sdk/achievement-sdk/pkg/achievementclientmodels"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository"
"github.com/go-openapi/runtime"

"github.com/go-openapi/runtime/client"
"github.com/sirupsen/logrus"
)

type AchievementService struct {
AchievementServiceClient *achievementclient.JusticeAchievementService
TokenRepository repository.TokenRepository
type AchievementsService struct {
Client *achievementclient.JusticeAchievementService
TokenRepository repository.TokenRepository
}

func (a *AchievementService) AdminCreateNewAchievement(body *achievementclientmodels.ModelsAchievementRequest, namespace string) (*achievementclientmodels.ModelsAchievementResponse, error) {
func (a *AchievementsService) AdminCreateNewAchievement(input *achievements.AdminCreateNewAchievementParams) (*achievementclientmodels.ModelsAchievementResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.AdminCreateNewAchievementParams{
Body: body,
Namespace: namespace,
}
ok, badRequest, unauthorized, internalServerError, err := a.AchievementServiceClient.Achievements.AdminCreateNewAchievement(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, internalServerError, err := a.Client.Achievements.AdminCreateNewAchievement(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -49,16 +43,12 @@ func (a *AchievementService) AdminCreateNewAchievement(body *achievementclientmo
return ok.GetPayload(), nil
}

func (a *AchievementService) AdminDeleteAchievement(achievementsCode, namespace string) error {
func (a *AchievementsService) AdminDeleteAchievement(input *achievements.AdminDeleteAchievementParams) error {
token, err := a.TokenRepository.GetToken()
if err != nil {
return err
}
params := &achievements.AdminDeleteAchievementParams{
AchievementCode: achievementsCode,
Namespace: namespace,
}
_, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.AdminDeleteAchievement(params, client.BearerToken(*token.AccessToken))
_, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.AdminDeleteAchievement(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -85,16 +75,12 @@ func (a *AchievementService) AdminDeleteAchievement(achievementsCode, namespace
return nil
}

func (a *AchievementService) AdminGetAchievement(achievementsCode, namespace string) (*achievementclientmodels.ModelsAchievementResponse, error) {
func (a *AchievementsService) AdminGetAchievement(input *achievements.AdminGetAchievementParams) (*achievementclientmodels.ModelsAchievementResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.AdminGetAchievementParams{
AchievementCode: achievementsCode,
Namespace: namespace,
}
ok, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.AdminGetAchievement(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.AdminGetAchievement(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -121,18 +107,12 @@ func (a *AchievementService) AdminGetAchievement(achievementsCode, namespace str
return ok.GetPayload(), nil
}

func (a *AchievementService) AdminListAchievements(limit *int64, namespace string, offset *int64, sortBy *string) (*achievementclientmodels.ModelsPaginatedAchievementResponse, error) {
func (a *AchievementsService) AdminListAchievements(input *achievements.AdminListAchievementsParams) (*achievementclientmodels.ModelsPaginatedAchievementResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.AdminListAchievementsParams{
Limit: limit,
Namespace: namespace,
Offset: offset,
SortBy: sortBy,
}
ok, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.AdminListAchievements(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.AdminListAchievements(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -159,19 +139,12 @@ func (a *AchievementService) AdminListAchievements(limit *int64, namespace strin
return ok.GetPayload(), nil
}

func (a *AchievementService) AdminListUserAchievements(limit *int64, namespace string, offset *int64, preferUnlocked *bool, userID string) (*achievementclientmodels.ModelsPaginatedUserAchievementResponse, error) {
func (a *AchievementsService) AdminListUserAchievements(input *achievements.AdminListUserAchievementsParams) (*achievementclientmodels.ModelsPaginatedUserAchievementResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.AdminListUserAchievementsParams{
Limit: limit,
Namespace: namespace,
Offset: offset,
PreferUnlocked: preferUnlocked,
UserID: userID,
}
ok, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.AdminListUserAchievements(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.AdminListUserAchievements(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -198,17 +171,12 @@ func (a *AchievementService) AdminListUserAchievements(limit *int64, namespace s
return ok.GetPayload(), nil
}

func (a *AchievementService) AdminUnlockAchievement(achievementCode, namespace, userID string) error {
func (a *AchievementsService) AdminUnlockAchievement(input *achievements.AdminUnlockAchievementParams) error {
token, err := a.TokenRepository.GetToken()
if err != nil {
return err
}
params := &achievements.AdminUnlockAchievementParams{
AchievementCode: achievementCode,
Namespace: namespace,
UserID: userID,
}
_, badRequest, unauthorized, internalServerError, err := a.AchievementServiceClient.Achievements.AdminUnlockAchievement(params, client.BearerToken(*token.AccessToken))
_, badRequest, unauthorized, internalServerError, err := a.Client.Achievements.AdminUnlockAchievement(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -230,17 +198,12 @@ func (a *AchievementService) AdminUnlockAchievement(achievementCode, namespace,
return nil
}

func (a *AchievementService) AdminUpdateAchievement(body *achievementclientmodels.ModelsAchievementUpdateRequest, achievementCode, namespace string) (*achievementclientmodels.ModelsAchievementResponse, error) {
func (a *AchievementsService) AdminUpdateAchievement(input *achievements.AdminUpdateAchievementParams) (*achievementclientmodels.ModelsAchievementResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.AdminUpdateAchievementParams{
Body: body,
AchievementCode: achievementCode,
Namespace: namespace,
}
ok, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.AdminUpdateAchievement(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.AdminUpdateAchievement(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -267,17 +230,12 @@ func (a *AchievementService) AdminUpdateAchievement(body *achievementclientmodel
return ok.GetPayload(), nil
}

func (a *AchievementService) AdminUpdateAchievementListOrder(body *achievementclientmodels.ModelsAchievementOrderUpdateRequest, achievementCode, namespace string) error {
func (a *AchievementsService) AdminUpdateAchievementListOrder(input *achievements.AdminUpdateAchievementListOrderParams) error {
token, err := a.TokenRepository.GetToken()
if err != nil {
return err
}
params := &achievements.AdminUpdateAchievementListOrderParams{
Body: body,
AchievementCode: achievementCode,
Namespace: namespace,
}
_, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.AdminUpdateAchievementListOrder(params, client.BearerToken(*token.AccessToken))
_, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.AdminUpdateAchievementListOrder(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -304,15 +262,12 @@ func (a *AchievementService) AdminUpdateAchievementListOrder(body *achievementcl
return nil
}

func (a *AchievementService) ExportAchievements(namespace string) ([]*achievementclientmodels.ModelsAchievement, error) {
func (a *AchievementsService) ExportAchievements(input *achievements.ExportAchievementsParams) ([]*achievementclientmodels.ModelsAchievement, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.ExportAchievementsParams{
Namespace: namespace,
}
ok, unauthorized, forbidden, internalServerError, err := a.AchievementServiceClient.Achievements.ExportAchievements(params, client.BearerToken(*token.AccessToken))
ok, unauthorized, forbidden, internalServerError, err := a.Client.Achievements.ExportAchievements(input, client.BearerToken(*token.AccessToken))
if unauthorized != nil {
errorMsg, _ := json.Marshal(*unauthorized.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -334,17 +289,12 @@ func (a *AchievementService) ExportAchievements(namespace string) ([]*achievemen
return ok.GetPayload(), nil
}

func (a *AchievementService) ImportAchievements(file runtime.NamedReadCloser, namespace string, strategy *string) (*achievementclientmodels.ServiceImportConfigResponse, error) {
func (a *AchievementsService) ImportAchievements(input *achievements.ImportAchievementsParams) (*achievementclientmodels.ServiceImportConfigResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.ImportAchievementsParams{
File: file,
Namespace: namespace,
Strategy: strategy,
}
ok, unauthorized, forbidden, internalServerError, err := a.AchievementServiceClient.Achievements.ImportAchievements(params, client.BearerToken(*token.AccessToken))
ok, unauthorized, forbidden, internalServerError, err := a.Client.Achievements.ImportAchievements(input, client.BearerToken(*token.AccessToken))
if unauthorized != nil {
errorMsg, _ := json.Marshal(*unauthorized.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -366,17 +316,12 @@ func (a *AchievementService) ImportAchievements(file runtime.NamedReadCloser, na
return ok.GetPayload(), nil
}

func (a *AchievementService) PublicGetAchievement(achievementCode, language, namespace string) (*achievementclientmodels.ModelsPublicAchievementResponse, error) {
func (a *AchievementsService) PublicGetAchievement(input *achievements.PublicGetAchievementParams) (*achievementclientmodels.ModelsPublicAchievementResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.PublicGetAchievementParams{
AchievementCode: achievementCode,
Language: language,
Namespace: namespace,
}
ok, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.PublicGetAchievement(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.PublicGetAchievement(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -403,19 +348,12 @@ func (a *AchievementService) PublicGetAchievement(achievementCode, language, nam
return ok.GetPayload(), nil
}

func (a *AchievementService) PublicListAchievements(language string, limit *int64, namespace string, offset *int64, sortBy *string) (*achievementclientmodels.ModelsPublicAchievementsResponse, error) {
func (a *AchievementsService) PublicListAchievements(input *achievements.PublicListAchievementsParams) (*achievementclientmodels.ModelsPublicAchievementsResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.PublicListAchievementsParams{
Language: language,
Limit: limit,
Namespace: namespace,
Offset: offset,
SortBy: sortBy,
}
ok, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.PublicListAchievements(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.PublicListAchievements(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -442,19 +380,12 @@ func (a *AchievementService) PublicListAchievements(language string, limit *int6
return ok.GetPayload(), nil
}

func (a *AchievementService) PublicListUserAchievements(limit *int64, namespace string, offset *int64, preferUnlocked *bool, userID string) (*achievementclientmodels.ModelsPaginatedUserAchievementResponse, error) {
func (a *AchievementsService) PublicListUserAchievements(input *achievements.PublicListUserAchievementsParams) (*achievementclientmodels.ModelsPaginatedUserAchievementResponse, error) {
token, err := a.TokenRepository.GetToken()
if err != nil {
return nil, err
}
params := &achievements.PublicListUserAchievementsParams{
Limit: limit,
Namespace: namespace,
Offset: offset,
PreferUnlocked: preferUnlocked,
UserID: userID,
}
ok, badRequest, unauthorized, notFound, internalServerError, err := a.AchievementServiceClient.Achievements.PublicListUserAchievements(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServerError, err := a.Client.Achievements.PublicListUserAchievements(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -481,17 +412,12 @@ func (a *AchievementService) PublicListUserAchievements(limit *int64, namespace
return ok.GetPayload(), nil
}

func (a *AchievementService) PublicUnlockAchievement(achievementCode, namespace, userID string) error {
func (a *AchievementsService) PublicUnlockAchievement(input *achievements.PublicUnlockAchievementParams) error {
token, err := a.TokenRepository.GetToken()
if err != nil {
return err
}
params := &achievements.PublicUnlockAchievementParams{
AchievementCode: achievementCode,
Namespace: namespace,
UserID: userID,
}
_, badRequest, unauthorized, internalServerError, err := a.AchievementServiceClient.Achievements.PublicUnlockAchievement(params, client.BearerToken(*token.AccessToken))
_, badRequest, unauthorized, internalServerError, err := a.Client.Achievements.PublicUnlockAchievement(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down

0 comments on commit 0313762

Please sign in to comment.