hi-server/internal/logic/admin/application/createAppVersionLogic.go
shanshanzhong 1d81df6664
Some checks failed
Build docker and publish / build (20.15.1) (push) Has been cancelled
add:添加短链接服务
2026-01-24 00:32:08 -08:00

76 lines
2.1 KiB
Go

package application
import (
"context"
"encoding/json"
"github.com/perfect-panel/server/internal/model/client"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type CreateAppVersionLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateAppVersionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAppVersionLogic {
return &CreateAppVersionLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateAppVersionLogic) CreateAppVersion(req *types.CreateAppVersionRequest) (resp *types.ApplicationVersion, err error) {
// Defaults
isDefault := false
if req.IsDefault != nil {
isDefault = *req.IsDefault
}
isInReview := false
if req.IsInReview != nil {
isInReview = *req.IsInReview
}
description := json.RawMessage(req.Description)
version := &client.ApplicationVersion{
Platform: req.Platform,
Version: req.Version,
MinVersion: req.MinVersion,
ForceUpdate: req.ForceUpdate,
Url: req.Url,
Description: description,
IsDefault: isDefault,
IsInReview: isInReview,
}
if err := l.svcCtx.DB.Create(version).Error; err != nil {
l.Errorw("[CreateAppVersion] create version error", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create version error: %v", err)
}
// Manual mapping to types.ApplicationVersion
resp = &types.ApplicationVersion{
Id: version.Id,
Platform: version.Platform, // Note: types.ApplicationVersion might not have Platform field based on previous view_file. Let's check.
Version: version.Version,
MinVersion: version.MinVersion,
ForceUpdate: version.ForceUpdate,
Description: make(map[string]string), // Simplified for now
Url: version.Url,
IsDefault: version.IsDefault,
IsInReview: version.IsInReview,
CreatedAt: version.CreatedAt.Unix(),
}
// Try to unmarshal description
_ = json.Unmarshal(version.Description, &resp.Description)
return resp, nil
}