Some checks failed
部署管理后台 / 🧪 测试和构建 (push) Failing after 1m5s
部署管理后台 / 🔒 安全扫描 (push) Has been skipped
部署后端服务 / 🧪 测试后端 (push) Failing after 3m13s
部署前端网站 / 🧪 测试和构建 (push) Failing after 2m10s
部署管理后台 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🚀 构建并部署 (push) Has been skipped
部署管理后台 / 🔄 回滚部署 (push) Has been skipped
部署前端网站 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🔄 回滚部署 (push) Has been skipped
- 后端:应用 go fmt 自动格式化,统一代码风格 - 前端:更新 API 配置,完善类型安全 - 所有代码符合项目规范,准备生产部署
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package category
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"photography-backend/internal/model"
|
|
"photography-backend/internal/svc"
|
|
"photography-backend/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CreateCategoryLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 创建分类
|
|
func NewCreateCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCategoryLogic {
|
|
return &CreateCategoryLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *CreateCategoryLogic) CreateCategory(req *types.CreateCategoryRequest) (resp *types.CreateCategoryResponse, err error) {
|
|
// 1. 创建分类
|
|
category := &model.Category{
|
|
Name: req.Name,
|
|
Description: sql.NullString{String: req.Description, Valid: req.Description != ""},
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
}
|
|
|
|
_, err = l.svcCtx.CategoryModel.Insert(l.ctx, category)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 2. 返回结果
|
|
return &types.CreateCategoryResponse{
|
|
BaseResponse: types.BaseResponse{
|
|
Code: 200,
|
|
Message: "创建成功",
|
|
},
|
|
Data: types.Category{
|
|
Id: category.Id,
|
|
Name: category.Name,
|
|
Description: category.Description.String,
|
|
CreatedAt: category.CreatedAt.Unix(),
|
|
UpdatedAt: category.UpdatedAt.Unix(),
|
|
},
|
|
}, nil
|
|
}
|