init: 1.0.0
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/application"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type CreateApplicationLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateApplicationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateApplicationLogic {
|
||||
return &CreateApplicationLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateApplicationLogic) CreateApplication(req *types.CreateApplicationRequest) error {
|
||||
var ios []application.ApplicationVersion
|
||||
if len(req.Platform.IOS) > 0 {
|
||||
for _, ios_ := range req.Platform.IOS {
|
||||
ios = append(ios, application.ApplicationVersion{
|
||||
Url: ios_.Url,
|
||||
Version: ios_.Version,
|
||||
Platform: "ios",
|
||||
IsDefault: ios_.IsDefault,
|
||||
Description: ios_.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var mac []application.ApplicationVersion
|
||||
if len(req.Platform.MacOS) > 0 {
|
||||
for _, mac_ := range req.Platform.MacOS {
|
||||
mac = append(mac, application.ApplicationVersion{
|
||||
Url: mac_.Url,
|
||||
Version: mac_.Version,
|
||||
Platform: "macos",
|
||||
IsDefault: mac_.IsDefault,
|
||||
Description: mac_.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var linux []application.ApplicationVersion
|
||||
if len(req.Platform.Linux) > 0 {
|
||||
for _, linux_ := range req.Platform.Linux {
|
||||
linux = append(linux, application.ApplicationVersion{
|
||||
Url: linux_.Url,
|
||||
Version: linux_.Version,
|
||||
Platform: "linux",
|
||||
IsDefault: linux_.IsDefault,
|
||||
Description: linux_.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var android []application.ApplicationVersion
|
||||
if len(req.Platform.Android) > 0 {
|
||||
for _, android_ := range req.Platform.Android {
|
||||
android = append(android, application.ApplicationVersion{
|
||||
Url: android_.Url,
|
||||
Version: android_.Version,
|
||||
Platform: "android",
|
||||
IsDefault: android_.IsDefault,
|
||||
Description: android_.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var windows []application.ApplicationVersion
|
||||
if len(req.Platform.Windows) > 0 {
|
||||
for _, windows_ := range req.Platform.Windows {
|
||||
windows = append(windows, application.ApplicationVersion{
|
||||
Url: windows_.Url,
|
||||
Version: windows_.Version,
|
||||
Platform: "windows",
|
||||
IsDefault: windows_.IsDefault,
|
||||
Description: windows_.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var harmony []application.ApplicationVersion
|
||||
if len(req.Platform.Harmony) > 0 {
|
||||
for _, harmony_ := range req.Platform.Harmony {
|
||||
harmony = append(harmony, application.ApplicationVersion{
|
||||
Url: harmony_.Url,
|
||||
Version: harmony_.Version,
|
||||
Platform: "harmony",
|
||||
IsDefault: harmony_.IsDefault,
|
||||
Description: harmony_.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
var applicationVersions []application.ApplicationVersion
|
||||
applicationVersions = append(applicationVersions, ios...)
|
||||
applicationVersions = append(applicationVersions, mac...)
|
||||
applicationVersions = append(applicationVersions, linux...)
|
||||
applicationVersions = append(applicationVersions, android...)
|
||||
applicationVersions = append(applicationVersions, windows...)
|
||||
applicationVersions = append(applicationVersions, harmony...)
|
||||
app := application.Application{
|
||||
Name: req.Name,
|
||||
Icon: req.Icon,
|
||||
SubscribeType: req.SubscribeType,
|
||||
ApplicationVersions: applicationVersions,
|
||||
}
|
||||
err := l.svcCtx.ApplicationModel.Insert(l.ctx, &app)
|
||||
if err != nil {
|
||||
l.Errorw("[CreateApplicationLogic] create application error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create application error: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/application"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type CreateApplicationVersionLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Create application version
|
||||
func NewCreateApplicationVersionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateApplicationVersionLogic {
|
||||
return &CreateApplicationVersionLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateApplicationVersionLogic) CreateApplicationVersion(req *types.CreateApplicationVersionRequest) error {
|
||||
create := &application.ApplicationVersion{
|
||||
Url: req.Url,
|
||||
Platform: req.Platform,
|
||||
Version: req.Version,
|
||||
Description: req.Description,
|
||||
IsDefault: req.IsDefault,
|
||||
ApplicationId: req.ApplicationId,
|
||||
}
|
||||
err := l.svcCtx.ApplicationModel.InsertVersion(l.ctx, create)
|
||||
if err != nil {
|
||||
l.Errorw("[CreateApplicationVersion] create application version error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create application version error: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type DeleteApplicationLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteApplicationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteApplicationLogic {
|
||||
return &DeleteApplicationLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteApplicationLogic) DeleteApplication(req *types.DeleteApplicationRequest) error {
|
||||
// delete application
|
||||
err := l.svcCtx.ApplicationModel.Delete(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
l.Errorw("[DeleteApplicationLogic] delete application error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "delete application error: %v", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type DeleteApplicationVersionLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Delete application
|
||||
func NewDeleteApplicationVersionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteApplicationVersionLogic {
|
||||
return &DeleteApplicationVersionLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteApplicationVersionLogic) DeleteApplicationVersion(req *types.DeleteApplicationVersionRequest) error {
|
||||
// delete application
|
||||
err := l.svcCtx.ApplicationModel.DeleteVersion(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
l.Errorw("[DeleteApplicationVersion] delete application version error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "delete application version error: %v", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
)
|
||||
|
||||
type GetApplicationConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// get application config
|
||||
func NewGetApplicationConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApplicationConfigLogic {
|
||||
return &GetApplicationConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetApplicationConfigLogic) GetApplicationConfig() (resp *types.ApplicationConfig, err error) {
|
||||
resp = &types.ApplicationConfig{}
|
||||
appConfig, err := l.svcCtx.ApplicationModel.FindOneConfig(l.ctx, 1)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
l.Errorw("[GetApplicationConfig] Database Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get app config error: %v", err.Error())
|
||||
}
|
||||
resp.AppId = appConfig.AppId
|
||||
resp.EncryptionKey = appConfig.EncryptionKey
|
||||
resp.EncryptionMethod = appConfig.EncryptionMethod
|
||||
resp.Domains = strings.Split(appConfig.Domains, ";")
|
||||
resp.StartupPicture = appConfig.StartupPicture
|
||||
resp.StartupPictureSkipTime = appConfig.StartupPictureSkipTime
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/application"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
)
|
||||
|
||||
type GetApplicationLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get application
|
||||
func NewGetApplicationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApplicationLogic {
|
||||
return &GetApplicationLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetApplicationLogic) GetApplication() (resp *types.ApplicationResponse, err error) {
|
||||
resp = &types.ApplicationResponse{}
|
||||
var applications []*application.Application
|
||||
err = l.svcCtx.ApplicationModel.Transaction(l.ctx, func(tx *gorm.DB) (err error) {
|
||||
return tx.Model(applications).Preload("ApplicationVersions").Find(&applications).Error
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[GetApplicationLogic] get application error: ", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get application error: %v", err.Error())
|
||||
}
|
||||
|
||||
if len(applications) == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
for _, app := range applications {
|
||||
applicationResponse := types.ApplicationResponseInfo{
|
||||
Id: app.Id,
|
||||
Name: app.Name,
|
||||
Icon: app.Icon,
|
||||
Description: app.Description,
|
||||
SubscribeType: app.SubscribeType,
|
||||
}
|
||||
applicationVersions := app.ApplicationVersions
|
||||
if len(applicationVersions) != 0 {
|
||||
for _, applicationVersion := range applicationVersions {
|
||||
switch applicationVersion.Platform {
|
||||
case "ios":
|
||||
applicationResponse.Platform.IOS = append(applicationResponse.Platform.IOS, &types.ApplicationVersion{
|
||||
Id: applicationVersion.Id,
|
||||
Url: applicationVersion.Url,
|
||||
Version: applicationVersion.Version,
|
||||
IsDefault: applicationVersion.IsDefault,
|
||||
Description: applicationVersion.Description,
|
||||
})
|
||||
case "macos":
|
||||
applicationResponse.Platform.MacOS = append(applicationResponse.Platform.MacOS, &types.ApplicationVersion{
|
||||
Id: applicationVersion.Id,
|
||||
Url: applicationVersion.Url,
|
||||
Version: applicationVersion.Version,
|
||||
IsDefault: applicationVersion.IsDefault,
|
||||
Description: applicationVersion.Description,
|
||||
})
|
||||
case "linux":
|
||||
applicationResponse.Platform.Linux = append(applicationResponse.Platform.Linux, &types.ApplicationVersion{
|
||||
Id: applicationVersion.Id,
|
||||
Url: applicationVersion.Url,
|
||||
Version: applicationVersion.Version,
|
||||
IsDefault: applicationVersion.IsDefault,
|
||||
Description: applicationVersion.Description,
|
||||
})
|
||||
case "android":
|
||||
applicationResponse.Platform.Android = append(applicationResponse.Platform.Android, &types.ApplicationVersion{
|
||||
Id: applicationVersion.Id,
|
||||
Url: applicationVersion.Url,
|
||||
Version: applicationVersion.Version,
|
||||
IsDefault: applicationVersion.IsDefault,
|
||||
Description: applicationVersion.Description,
|
||||
})
|
||||
case "windows":
|
||||
applicationResponse.Platform.Windows = append(applicationResponse.Platform.Windows, &types.ApplicationVersion{
|
||||
Id: applicationVersion.Id,
|
||||
Url: applicationVersion.Url,
|
||||
Version: applicationVersion.Version,
|
||||
IsDefault: applicationVersion.IsDefault,
|
||||
Description: applicationVersion.Description,
|
||||
})
|
||||
case "harmony":
|
||||
applicationResponse.Platform.Harmony = append(applicationResponse.Platform.Harmony, &types.ApplicationVersion{
|
||||
Id: applicationVersion.Id,
|
||||
Url: applicationVersion.Url,
|
||||
Version: applicationVersion.Version,
|
||||
IsDefault: applicationVersion.IsDefault,
|
||||
Description: applicationVersion.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
resp.Applications = append(resp.Applications, applicationResponse)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetCurrencyConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get Currency Config
|
||||
func NewGetCurrencyConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCurrencyConfigLogic {
|
||||
return &GetCurrencyConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetCurrencyConfigLogic) GetCurrencyConfig() (resp *types.CurrencyConfig, err error) {
|
||||
configs, err := l.svcCtx.SystemModel.GetCurrencyConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[GetCurrencyConfigLogic] GetCurrencyConfig error: ", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "GetCurrencyConfig error: %v", err.Error())
|
||||
}
|
||||
resp = &types.CurrencyConfig{}
|
||||
tool.SystemConfigSliceReflectToStruct(configs, resp)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetInviteConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetInviteConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInviteConfigLogic {
|
||||
return &GetInviteConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetInviteConfigLogic) GetInviteConfig() (*types.InviteConfig, error) {
|
||||
resp := &types.InviteConfig{}
|
||||
// get invite config from db
|
||||
configs, err := l.svcCtx.SystemModel.GetInviteConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[GetInviteConfigLogic] get invite config error: ", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get invite config error: %v", err.Error())
|
||||
}
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(configs, resp)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetNodeConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetNodeConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetNodeConfigLogic {
|
||||
return &GetNodeConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetNodeConfigLogic) GetNodeConfig() (*types.NodeConfig, error) {
|
||||
resp := &types.NodeConfig{}
|
||||
|
||||
// get server config from db
|
||||
configs, err := l.svcCtx.SystemModel.GetNodeConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[GetNodeConfigLogic] GetNodeConfig get server config error: ", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "GetNodeConfig get server config error: %v", err.Error())
|
||||
}
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(configs, resp)
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetNodeMultiplierLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get Node Multiplier
|
||||
func NewGetNodeMultiplierLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetNodeMultiplierLogic {
|
||||
return &GetNodeMultiplierLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetNodeMultiplierLogic) GetNodeMultiplier() (resp *types.GetNodeMultiplierResponse, err error) {
|
||||
data, err := l.svcCtx.SystemModel.FindNodeMultiplierConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Logger.Error("Get Node Multiplier Config Error: ", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Get Node Multiplier Config Error: %s", err.Error())
|
||||
}
|
||||
var periods []types.TimePeriod
|
||||
if data.Value != "" {
|
||||
if err := json.Unmarshal([]byte(data.Value), &periods); err != nil {
|
||||
l.Logger.Error("Unmarshal Node Multiplier Config Error: ", logger.Field("error", err.Error()), logger.Field("value", data.Value))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Unmarshal Node Multiplier Config Error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return &types.GetNodeMultiplierResponse{
|
||||
Periods: periods,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetPrivacyPolicyConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewGetPrivacyPolicyConfigLogic get Privacy Policy Config
|
||||
func NewGetPrivacyPolicyConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPrivacyPolicyConfigLogic {
|
||||
return &GetPrivacyPolicyConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPrivacyPolicyConfigLogic) GetPrivacyPolicyConfig() (resp *types.PrivacyPolicyConfig, err error) {
|
||||
resp = &types.PrivacyPolicyConfig{}
|
||||
// get tos config from db
|
||||
configs, err := l.svcCtx.SystemModel.GetTosConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[GetTosConfig] GetTosConfig error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "GetTosConfig error: %v", err.Error())
|
||||
}
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(configs, resp)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetRegisterConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetRegisterConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRegisterConfigLogic {
|
||||
return &GetRegisterConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetRegisterConfigLogic) GetRegisterConfig() (*types.RegisterConfig, error) {
|
||||
resp := &types.RegisterConfig{}
|
||||
|
||||
// get register config from database
|
||||
configs, err := l.svcCtx.SystemModel.GetRegisterConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[GetRegisterConfig] Database query error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get register config error: %v", err.Error())
|
||||
}
|
||||
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(configs, resp)
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetSiteConfigLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logger.Logger
|
||||
}
|
||||
|
||||
func NewGetSiteConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSiteConfigLogic {
|
||||
return &GetSiteConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSiteConfigLogic) GetSiteConfig() (resp *types.SiteConfig, err error) {
|
||||
resp = &types.SiteConfig{}
|
||||
// get site config from db
|
||||
siteConfigs, err := l.svcCtx.SystemModel.GetSiteConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Logger.Error("[GetSiteConfig] Database query error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get site config failed: %v", err.Error())
|
||||
}
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(siteConfigs, resp)
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetSubscribeConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetSubscribeConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubscribeConfigLogic {
|
||||
return &GetSubscribeConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSubscribeConfigLogic) GetSubscribeConfig() (resp *types.SubscribeConfig, err error) {
|
||||
resp = &types.SubscribeConfig{}
|
||||
// get subscribe config from db
|
||||
subscribeConfigs, err := l.svcCtx.SystemModel.GetSubscribeConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[GetSubscribeConfig] Database query error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get subscribe config failed: %v", err.Error())
|
||||
}
|
||||
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(subscribeConfigs, resp)
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/subscribeType"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetSubscribeTypeLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logger.Logger
|
||||
}
|
||||
|
||||
func NewGetSubscribeTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubscribeTypeLogic {
|
||||
return &GetSubscribeTypeLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logger.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSubscribeTypeLogic) GetSubscribeType() (resp *types.SubscribeType, err error) {
|
||||
var list []*subscribeType.SubscribeType
|
||||
err = l.svcCtx.DB.Model(&subscribeType.SubscribeType{}).Find(&list).Error
|
||||
if err != nil {
|
||||
l.Errorw("[GetSubscribeType] get subscribe type failed", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get subscribe type failed: %v", err)
|
||||
}
|
||||
typeList := make([]string, 0)
|
||||
for _, item := range list {
|
||||
typeList = append(typeList, item.Name)
|
||||
}
|
||||
return &types.SubscribeType{
|
||||
SubscribeTypes: typeList,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetTosConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetTosConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTosConfigLogic {
|
||||
return &GetTosConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetTosConfigLogic) GetTosConfig() (resp *types.TosConfig, err error) {
|
||||
resp = &types.TosConfig{}
|
||||
// get tos config from db
|
||||
configs, err := l.svcCtx.SystemModel.GetTosConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[GetTosConfig] GetTosConfig error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "GetTosConfig error: %v", err.Error())
|
||||
}
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(configs, resp)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetVerifyCodeConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get Verify Code Config
|
||||
func NewGetVerifyCodeConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetVerifyCodeConfigLogic {
|
||||
return &GetVerifyCodeConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetVerifyCodeConfigLogic) GetVerifyCodeConfig() (resp *types.VerifyCodeConfig, err error) {
|
||||
data, err := l.svcCtx.SystemModel.GetVerifyCodeConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("Get Verify Code Config Error: ", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Get Verify Code Config Error: %s", err.Error())
|
||||
}
|
||||
resp = &types.VerifyCodeConfig{}
|
||||
tool.SystemConfigSliceReflectToStruct(data, resp)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/initialize"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetVerifyConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetVerifyConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetVerifyConfigLogic {
|
||||
return &GetVerifyConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetVerifyConfigLogic) GetVerifyConfig() (*types.VerifyConfig, error) {
|
||||
resp := &types.VerifyConfig{}
|
||||
// get verify config from db
|
||||
verifyConfigs, err := l.svcCtx.SystemModel.GetVerifyConfig(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get verify config failed: %v", err.Error())
|
||||
}
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(verifyConfigs, resp)
|
||||
// update verify config to system
|
||||
initialize.Verify(l.svcCtx)
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SetNodeMultiplierLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Set Node Multiplier
|
||||
func NewSetNodeMultiplierLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetNodeMultiplierLogic {
|
||||
return &SetNodeMultiplierLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SetNodeMultiplierLogic) SetNodeMultiplier(req *types.SetNodeMultiplierRequest) error {
|
||||
data, err := json.Marshal(req.Periods)
|
||||
if err != nil {
|
||||
l.Logger.Error("Marshal Node Multiplier Config Error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Marshal Node Multiplier Config Error: %s", err.Error())
|
||||
}
|
||||
if err := l.svcCtx.SystemModel.UpdateNodeMultiplierConfig(l.ctx, string(data)); err != nil {
|
||||
l.Logger.Error("Update Node Multiplier Config Error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Update Node Multiplier Config Error: %s", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/initialize"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
)
|
||||
|
||||
type SettingTelegramBotLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewSettingTelegramBotLogic setting telegram bot
|
||||
func NewSettingTelegramBotLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SettingTelegramBotLogic {
|
||||
return &SettingTelegramBotLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SettingTelegramBotLogic) SettingTelegramBot() error {
|
||||
initialize.Telegram(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/application"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type UpdateApplicationConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// update application config
|
||||
func NewUpdateApplicationConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateApplicationConfigLogic {
|
||||
return &UpdateApplicationConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateApplicationConfigLogic) UpdateApplicationConfig(req *types.ApplicationConfig) error {
|
||||
err := l.svcCtx.ApplicationModel.UpdateConfig(l.ctx, &application.ApplicationConfig{
|
||||
Id: 1,
|
||||
AppId: req.AppId,
|
||||
EncryptionKey: req.EncryptionKey,
|
||||
EncryptionMethod: req.EncryptionMethod,
|
||||
Domains: strings.Join(req.Domains, ";"),
|
||||
StartupPicture: req.StartupPicture,
|
||||
StartupPictureSkipTime: req.StartupPictureSkipTime,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateApplicationConfig] Database Error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update app config error: %v", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/application"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
)
|
||||
|
||||
type UpdateApplicationLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateApplicationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateApplicationLogic {
|
||||
return &UpdateApplicationLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateApplicationLogic) UpdateApplication(req *types.UpdateApplicationRequest) error {
|
||||
|
||||
// find application
|
||||
app, err := l.svcCtx.ApplicationModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateApplication] find application error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find application error: %v", err.Error())
|
||||
}
|
||||
app.Name = req.Name
|
||||
app.Icon = req.Icon
|
||||
app.SubscribeType = req.SubscribeType
|
||||
app.Description = req.Description
|
||||
|
||||
var ios []application.ApplicationVersion
|
||||
if len(req.Platform.IOS) > 0 {
|
||||
for _, ios_ := range req.Platform.IOS {
|
||||
ios = append(ios, application.ApplicationVersion{
|
||||
Url: ios_.Url,
|
||||
Version: ios_.Version,
|
||||
Platform: "ios",
|
||||
IsDefault: ios_.IsDefault,
|
||||
Description: ios_.Description,
|
||||
ApplicationId: app.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var mac []application.ApplicationVersion
|
||||
if len(req.Platform.MacOS) > 0 {
|
||||
for _, mac_ := range req.Platform.MacOS {
|
||||
mac = append(mac, application.ApplicationVersion{
|
||||
Url: mac_.Url,
|
||||
Version: mac_.Version,
|
||||
Platform: "macos",
|
||||
IsDefault: mac_.IsDefault,
|
||||
Description: mac_.Description,
|
||||
ApplicationId: app.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var linux []application.ApplicationVersion
|
||||
if len(req.Platform.Linux) > 0 {
|
||||
for _, linux_ := range req.Platform.Linux {
|
||||
linux = append(linux, application.ApplicationVersion{
|
||||
Url: linux_.Url,
|
||||
Version: linux_.Version,
|
||||
Platform: "linux",
|
||||
IsDefault: linux_.IsDefault,
|
||||
Description: linux_.Description,
|
||||
ApplicationId: app.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var android []application.ApplicationVersion
|
||||
if len(req.Platform.Android) > 0 {
|
||||
for _, android_ := range req.Platform.Android {
|
||||
android = append(android, application.ApplicationVersion{
|
||||
Url: android_.Url,
|
||||
Version: android_.Version,
|
||||
Platform: "android",
|
||||
IsDefault: android_.IsDefault,
|
||||
Description: android_.Description,
|
||||
ApplicationId: app.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var windows []application.ApplicationVersion
|
||||
if len(req.Platform.Windows) > 0 {
|
||||
for _, windows_ := range req.Platform.Windows {
|
||||
windows = append(windows, application.ApplicationVersion{
|
||||
Url: windows_.Url,
|
||||
Version: windows_.Version,
|
||||
Platform: "windows",
|
||||
IsDefault: windows_.IsDefault,
|
||||
Description: windows_.Description,
|
||||
ApplicationId: app.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var harmony []application.ApplicationVersion
|
||||
if len(req.Platform.Harmony) > 0 {
|
||||
for _, harmony_ := range req.Platform.Harmony {
|
||||
harmony = append(harmony, application.ApplicationVersion{
|
||||
Url: harmony_.Url,
|
||||
Version: harmony_.Version,
|
||||
Platform: "harmony",
|
||||
IsDefault: harmony_.IsDefault,
|
||||
Description: harmony_.Description,
|
||||
ApplicationId: app.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
var applicationVersions []application.ApplicationVersion
|
||||
applicationVersions = append(applicationVersions, ios...)
|
||||
applicationVersions = append(applicationVersions, mac...)
|
||||
applicationVersions = append(applicationVersions, linux...)
|
||||
applicationVersions = append(applicationVersions, android...)
|
||||
applicationVersions = append(applicationVersions, windows...)
|
||||
applicationVersions = append(applicationVersions, harmony...)
|
||||
app.ApplicationVersions = applicationVersions
|
||||
err = l.svcCtx.ApplicationModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
|
||||
if err = db.Where("application_id = ?", app.Id).Delete(&application.ApplicationVersion{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err = db.Create(&applicationVersions).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return db.Save(app).Error
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateApplication] update application error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update application error: %v", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type UpdateApplicationVersionLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Update application version
|
||||
func NewUpdateApplicationVersionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateApplicationVersionLogic {
|
||||
return &UpdateApplicationVersionLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateApplicationVersionLogic) UpdateApplicationVersion(req *types.UpdateApplicationVersionRequest) error {
|
||||
// find application
|
||||
app, err := l.svcCtx.ApplicationModel.FindOneVersion(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateApplicationVersion] find application version error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find application error: %v", err.Error())
|
||||
}
|
||||
app.Url = req.Url
|
||||
app.Version = req.Version
|
||||
app.Description = req.Description
|
||||
app.IsDefault = req.IsDefault
|
||||
err = l.svcCtx.ApplicationModel.UpdateVersion(l.ctx, app)
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateApplicationVersion] update application version error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update application version error: %v", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
)
|
||||
|
||||
type UpdateCurrencyConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Update Currency Config
|
||||
func NewUpdateCurrencyConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCurrencyConfigLogic {
|
||||
return &UpdateCurrencyConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateCurrencyConfigLogic) UpdateCurrencyConfig(req *types.CurrencyConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the invite config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'currency' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// clear cache
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.CurrencyConfigKey, config.GlobalConfigKey).Err()
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateCurrencyConfig] update currency config error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update invite config error: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/initialize"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
)
|
||||
|
||||
type UpdateInviteConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateInviteConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateInviteConfigLogic {
|
||||
return &UpdateInviteConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateInviteConfigLogic) UpdateInviteConfig(req *types.InviteConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the invite config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'invite' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// clear cache
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.InviteConfigKey, config.GlobalConfigKey).Err()
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateInviteConfig] update invite config error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update invite config error: %v", err)
|
||||
}
|
||||
initialize.Invite(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/initialize"
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
)
|
||||
|
||||
type UpdateNodeConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateNodeConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNodeConfigLogic {
|
||||
return &UpdateNodeConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateNodeConfigLogic) UpdateNodeConfig(req *types.NodeConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the server config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'server' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.NodeConfigKey).Err()
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateNodeConfig] update node config error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update server config error: %v", err)
|
||||
}
|
||||
initialize.Node(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
)
|
||||
|
||||
type UpdatePrivacyPolicyConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Update Privacy Policy Config
|
||||
func NewUpdatePrivacyPolicyConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePrivacyPolicyConfigLogic {
|
||||
return &UpdatePrivacyPolicyConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdatePrivacyPolicyConfigLogic) UpdatePrivacyPolicyConfig(req *types.PrivacyPolicyConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the tos config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'tos' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.TosConfigKey).Err()
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateTosConfigLogic] update tos config error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update tos config error: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/initialize"
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
)
|
||||
|
||||
type UpdateRegisterConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateRegisterConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRegisterConfigLogic {
|
||||
return &UpdateRegisterConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateRegisterConfigLogic) UpdateRegisterConfig(req *types.RegisterConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the site config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'register' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.RegisterConfigKey, config.GlobalConfigKey).Err()
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateRegisterConfig] update register config error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update register config error: %v", err.Error())
|
||||
}
|
||||
// init system config
|
||||
initialize.Register(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/initialize"
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UpdateSiteConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateSiteConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateSiteConfigLogic {
|
||||
return &UpdateSiteConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateSiteConfigLogic) UpdateSiteConfig(req *types.SiteConfig) error {
|
||||
// Get the reflection value of the structure
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value
|
||||
fieldValue := v.Field(i)
|
||||
err = db.Model(&system.System{}).Where("`category` = 'site' and `key` = ?", fieldName).Update("value", fieldValue.String()).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.SiteConfigKey, config.GlobalConfigKey).Err()
|
||||
})
|
||||
if err != nil {
|
||||
l.Logger.Error("[UpdateSiteConfig] update site config error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update site config error: %v", err.Error())
|
||||
}
|
||||
initialize.Site(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/initialize"
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UpdateSubscribeConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateSubscribeConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateSubscribeConfigLogic {
|
||||
return &UpdateSubscribeConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateSubscribeConfigLogic) UpdateSubscribeConfig(req *types.SubscribeConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the site config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'subscribe' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.SubscribeConfigKey, config.GlobalConfigKey).Err()
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateSubscribeConfigLogic] update subscribe config error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update subscribe config error: %v", err)
|
||||
}
|
||||
|
||||
if l.svcCtx.Config.Subscribe.SubscribePath != req.SubscribePath {
|
||||
go func(svc *svc.ServiceContext) {
|
||||
err = svc.Restart()
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateSubscribeConfigLogic] restart error: ", logger.Field("error", err.Error()))
|
||||
}
|
||||
}(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
|
||||
initialize.Subscribe(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UpdateTosConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateTosConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateTosConfigLogic {
|
||||
return &UpdateTosConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateTosConfigLogic) UpdateTosConfig(req *types.TosConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the tos config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'tos' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.TosConfigKey).Err()
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateTosConfigLogic] update tos config error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update tos config error: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
)
|
||||
|
||||
type UpdateVerifyCodeConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Update Verify Code Config
|
||||
func NewUpdateVerifyCodeConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateVerifyCodeConfigLogic {
|
||||
return &UpdateVerifyCodeConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateVerifyCodeConfigLogic) UpdateVerifyCodeConfig(req *types.VerifyCodeConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the site config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'verify_code' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
err = l.svcCtx.Redis.Del(l.ctx, config.VerifyCodeConfigKey).Err()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateRegisterConfig] update verify code config error", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update register config error: %v", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/initialize"
|
||||
"github.com/perfect-panel/ppanel-server/internal/config"
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/system"
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UpdateVerifyConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateVerifyConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateVerifyConfigLogic {
|
||||
return &UpdateVerifyConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateVerifyConfigLogic) UpdateVerifyConfig(req *types.VerifyConfig) error {
|
||||
v := reflect.ValueOf(*req)
|
||||
// Get the reflection type of the structure
|
||||
t := v.Type()
|
||||
err := l.svcCtx.SystemModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
var err error
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
// Get the field name
|
||||
fieldName := t.Field(i).Name
|
||||
// Get the field value to string
|
||||
fieldValue := tool.ConvertValueToString(v.Field(i))
|
||||
// Update the site config
|
||||
err = db.Model(&system.System{}).Where("`category` = 'verify' and `key` = ?", fieldName).Update("value", fieldValue).Error
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// clear cache
|
||||
return l.svcCtx.Redis.Del(l.ctx, config.VerifyConfigKey, config.GlobalConfigKey).Err()
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[UpdateVerifyConfigLogic] update verify config error: ", logger.Field("error", err.Error()))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update verify config error: %v", err)
|
||||
}
|
||||
// Update the config
|
||||
tool.DeepCopy(&l.svcCtx.Config.Verify, req)
|
||||
initialize.Verify(l.svcCtx)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user