Skip to content

Commit

Permalink
refactor: ugc sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nurjalal committed Oct 13, 2021
1 parent 11a239a commit 3634041
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 726 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,31 @@
// This is licensed software from AccelByte Inc, for limitations
// and restrictions contact your company contract manager.

package service
package ugc

import (
"encoding/json"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository"
"github.com/AccelByte/accelbyte-go-sdk/ugc-sdk/pkg/ugcclient"
nr "github.com/AccelByte/accelbyte-go-sdk/ugc-sdk/pkg/ugcclient/nr_admin_channel"
"github.com/AccelByte/accelbyte-go-sdk/ugc-sdk/pkg/ugcclient/nr_admin_channel"
"github.com/AccelByte/accelbyte-go-sdk/ugc-sdk/pkg/ugcclientmodels"
"github.com/go-openapi/runtime/client"
"github.com/sirupsen/logrus"
)

type AdminChannelConfigService struct {
UgcServiceClient *ugcclient.JusticeUgcService
TokenRepository repository.TokenRepository
type AdminChannelService struct {
Client *ugcclient.JusticeUgcService
TokenRepository repository.TokenRepository
}

// AdminCreateChannel creates channel
func (u *AdminChannelConfigService) AdminCreateChannel(namespace string, body *ugcclientmodels.ModelsChannelRequest) (*ugcclientmodels.ModelsChannelResponse, error) {
func (u *AdminChannelService) AdminCreateChannel(input *nr_admin_channel.AdminCreateChannelParams) (*ugcclientmodels.ModelsChannelResponse, error) {
token, err := u.TokenRepository.GetToken()
if err != nil {
logrus.Error(err)
return nil, err
}
params := &nr.AdminCreateChannelParams{
Body: body,
Namespace: namespace,
}
created, unauthorized, notFound, internalServer, err := u.UgcServiceClient.NrAdminChannel.AdminCreateChannel(params, client.BearerToken(*token.AccessToken))
created, unauthorized, notFound, internalServer, err := u.Client.NrAdminChannel.AdminCreateChannel(input, client.BearerToken(*token.AccessToken))
if unauthorized != nil {
errorMsg, _ := json.Marshal(*unauthorized.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -54,18 +50,13 @@ func (u *AdminChannelConfigService) AdminCreateChannel(namespace string, body *u
}

// AdminDeleteChannel deletes channel
func (u *AdminChannelConfigService) AdminDeleteChannel(namespace, userId, channelId string) (*ugcclientmodels.ModelsChannelResponse, error) {
func (u *AdminChannelService) AdminDeleteChannel(input *nr_admin_channel.AdminDeleteChannelParams) (*ugcclientmodels.ModelsChannelResponse, error) {
token, err := u.TokenRepository.GetToken()
if err != nil {
logrus.Error(err)
return nil, err
}
params := &nr.AdminDeleteChannelParams{
ChannelID: channelId,
Namespace: namespace,
UserID: userId,
}
ok, unauthorized, notFound, internalServer, err := u.UgcServiceClient.NrAdminChannel.AdminDeleteChannel(params, client.BearerToken(*token.AccessToken))
ok, unauthorized, notFound, internalServer, err := u.Client.NrAdminChannel.AdminDeleteChannel(input, client.BearerToken(*token.AccessToken))
if unauthorized != nil {
errorMsg, _ := json.Marshal(*unauthorized.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -89,19 +80,13 @@ func (u *AdminChannelConfigService) AdminDeleteChannel(namespace, userId, channe
}

// AdminGetChannel gets channels
func (u *AdminChannelConfigService) AdminGetChannel(namespace, userId string, limit, offset *string) (*ugcclientmodels.ModelsPaginatedGetChannelResponse, error) {
func (u *AdminChannelService) AdminGetChannel(input *nr_admin_channel.AdminGetChannelParams) (*ugcclientmodels.ModelsPaginatedGetChannelResponse, error) {
token, err := u.TokenRepository.GetToken()
if err != nil {
logrus.Error(err)
return nil, err
}
params := &nr.AdminGetChannelParams{
Limit: limit,
Namespace: namespace,
Offset: offset,
UserID: userId,
}
ok, unauthorized, notFound, internalServer, err := u.UgcServiceClient.NrAdminChannel.AdminGetChannel(params, client.BearerToken(*token.AccessToken))
ok, unauthorized, notFound, internalServer, err := u.Client.NrAdminChannel.AdminGetChannel(input, client.BearerToken(*token.AccessToken))
if unauthorized != nil {
errorMsg, _ := json.Marshal(*unauthorized.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -125,19 +110,13 @@ func (u *AdminChannelConfigService) AdminGetChannel(namespace, userId string, li
}

// AdminUpdateChannel updates channel
func (u *AdminChannelConfigService) AdminUpdateChannel(namespace, userId, channelId string, body *ugcclientmodels.ModelsChannelRequest) (*ugcclientmodels.ModelsChannelResponse, error) {
func (u *AdminChannelService) AdminUpdateChannel(input *nr_admin_channel.AdminUpdateChannelParams) (*ugcclientmodels.ModelsChannelResponse, error) {
token, err := u.TokenRepository.GetToken()
if err != nil {
logrus.Error(err)
return nil, err
}
params := &nr.AdminUpdateChannelParams{
Body: body,
ChannelID: channelId,
Namespace: namespace,
UserID: userId,
}
ok, badRequest, unauthorized, notFound, internalServer, err := u.UgcServiceClient.NrAdminChannel.AdminUpdateChannel(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServer, err := u.Client.NrAdminChannel.AdminUpdateChannel(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down Expand Up @@ -166,17 +145,13 @@ func (u *AdminChannelConfigService) AdminUpdateChannel(namespace, userId, channe
}

// SingleAdminDeleteChannel deletes channel
func (u *AdminChannelConfigService) SingleAdminDeleteChannel(namespace, channelId string) (*ugcclientmodels.ModelsChannelResponse, error) {
func (u *AdminChannelService) SingleAdminDeleteChannel(input *nr_admin_channel.SingleAdminDeleteChannelParams) (*ugcclientmodels.ModelsChannelResponse, error) {
token, err := u.TokenRepository.GetToken()
if err != nil {
logrus.Error(err)
return nil, err
}
params := &nr.SingleAdminDeleteChannelParams{
ChannelID: channelId,
Namespace: namespace,
}
ok, unauthorized, notFound, internalServer, err := u.UgcServiceClient.NrAdminChannel.SingleAdminDeleteChannel(params, client.BearerToken(*token.AccessToken))
ok, unauthorized, notFound, internalServer, err := u.Client.NrAdminChannel.SingleAdminDeleteChannel(input, client.BearerToken(*token.AccessToken))
if unauthorized != nil {
errorMsg, _ := json.Marshal(*unauthorized.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -200,18 +175,13 @@ func (u *AdminChannelConfigService) SingleAdminDeleteChannel(namespace, channelI
}

// SingleAdminGetChannel gets channel
func (u *AdminChannelConfigService) SingleAdminGetChannel(namespace string, limit, offset *string) (*ugcclientmodels.ModelsPaginatedGetChannelResponse, error) {
func (u *AdminChannelService) SingleAdminGetChannel(input *nr_admin_channel.SingleAdminGetChannelParams) (*ugcclientmodels.ModelsPaginatedGetChannelResponse, error) {
token, err := u.TokenRepository.GetToken()
if err != nil {
logrus.Error(err)
return nil, err
}
params := &nr.SingleAdminGetChannelParams{
Limit: limit,
Namespace: namespace,
Offset: offset,
}
ok, unauthorized, notFound, internalServer, err := u.UgcServiceClient.NrAdminChannel.SingleAdminGetChannel(params, client.BearerToken(*token.AccessToken))
ok, unauthorized, notFound, internalServer, err := u.Client.NrAdminChannel.SingleAdminGetChannel(input, client.BearerToken(*token.AccessToken))
if unauthorized != nil {
errorMsg, _ := json.Marshal(*unauthorized.GetPayload())
logrus.Error(string(errorMsg))
Expand All @@ -235,18 +205,13 @@ func (u *AdminChannelConfigService) SingleAdminGetChannel(namespace string, limi
}

// SingleAdminUpdateChannel updates channel
func (u *AdminChannelConfigService) SingleAdminUpdateChannel(namespace, channelId string, body *ugcclientmodels.ModelsChannelRequest) (*ugcclientmodels.ModelsChannelResponse, error) {
func (u *AdminChannelService) SingleAdminUpdateChannel(input *nr_admin_channel.SingleAdminUpdateChannelParams) (*ugcclientmodels.ModelsChannelResponse, error) {
token, err := u.TokenRepository.GetToken()
if err != nil {
logrus.Error(err)
return nil, err
}
params := &nr.SingleAdminUpdateChannelParams{
Body: body,
ChannelID: channelId,
Namespace: namespace,
}
ok, badRequest, unauthorized, notFound, internalServer, err := u.UgcServiceClient.NrAdminChannel.SingleAdminUpdateChannel(params, client.BearerToken(*token.AccessToken))
ok, badRequest, unauthorized, notFound, internalServer, err := u.Client.NrAdminChannel.SingleAdminUpdateChannel(input, client.BearerToken(*token.AccessToken))
if badRequest != nil {
errorMsg, _ := json.Marshal(*badRequest.GetPayload())
logrus.Error(string(errorMsg))
Expand Down
Loading

0 comments on commit 3634041

Please sign in to comment.