fix: ci dir error
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
Nacos NacosConf
|
||||
}
|
||||
|
||||
type NacosConf struct {
|
||||
Hosts []string
|
||||
NamespaceId string `json:",optional"`
|
||||
Group string `json:",optional"`
|
||||
RegisterIP string `json:",optional"`
|
||||
ConfigID string `json:",optional"`
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package dao
|
||||
|
||||
const (
|
||||
AdStatusNormal uint8 = 1 // 正常
|
||||
AdStatusDisabled uint8 = 2 // 禁用
|
||||
)
|
||||
|
||||
// type: 1、商城首页banner 2、商城首页视频 3、商城首页公告 4、商城首页教程
|
||||
|
||||
type AdCreate struct {
|
||||
Id int `gorm:"column:id;primaryKey;autoIncrement"`
|
||||
Type uint8 `gorm:"column:type"`
|
||||
Image string `gorm:"column:image"`
|
||||
Content string `gorm:"column:content"`
|
||||
Url string `gorm:"column:url"`
|
||||
AdminId int `gorm:"column:admin_id"`
|
||||
AdminName string `gorm:"column:admin_name"`
|
||||
}
|
||||
|
||||
type AdInfo struct {
|
||||
Id int `gorm:"column:id"`
|
||||
Type uint8 `gorm:"column:type"`
|
||||
Image string `gorm:"column:image"`
|
||||
Content string `gorm:"column:content"`
|
||||
Reason string `gorm:"column:reason"`
|
||||
Status uint8 `gorm:"column:status"`
|
||||
Url string `gorm:"column:url"`
|
||||
UpdateTime string `gorm:"column:update_time"`
|
||||
CreateTime string `gorm:"column:create_time"`
|
||||
}
|
||||
|
||||
type AdStatus struct {
|
||||
Id int `gorm:"column:id;primaryKey"`
|
||||
Reason string `gorm:"column:reason"`
|
||||
Status uint8 `gorm:"column:status"`
|
||||
AdminId int `gorm:"column:admin_id"`
|
||||
AdminName string `gorm:"column:admin_name"`
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
"lone-services/services/ad/internal/dao"
|
||||
)
|
||||
|
||||
func toAdItem(row dao.AdInfo) *ad.Item {
|
||||
return &ad.Item{
|
||||
Id: int64(row.Id),
|
||||
Type: uint32(row.Type),
|
||||
Image: row.Image,
|
||||
Content: row.Content,
|
||||
Reason: row.Reason,
|
||||
Status: uint32(row.Status),
|
||||
Url: row.Url,
|
||||
UpdateTime: row.UpdateTime,
|
||||
CreateTime: row.CreateTime,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
"lone-services/services/ad/internal/dao"
|
||||
"lone-services/services/ad/internal/model"
|
||||
"lone-services/services/ad/internal/svc"
|
||||
"lone-services/services/ad/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic {
|
||||
return &CreateLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateLogic) Create(in *ad.CreateReq) (*ad.Response, error) {
|
||||
var req validator.AdCreateValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
data := dao.AdCreate{
|
||||
Type: uint8(req.Type),
|
||||
Image: req.Image,
|
||||
Content: req.Content,
|
||||
Url: req.Url,
|
||||
AdminId: int(adminInfo.ID),
|
||||
AdminName: adminInfo.Name,
|
||||
}
|
||||
if err := (model.AdModel{}.Init().Create(&data)); err != nil {
|
||||
log.Errorf("create ad: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(strconv.Itoa(data.Id)), nil
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
"lone-services/services/ad/internal/dao"
|
||||
"lone-services/services/ad/internal/model"
|
||||
"lone-services/services/ad/internal/svc"
|
||||
"lone-services/services/ad/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type EditLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic {
|
||||
return &EditLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *EditLogic) Edit(in *ad.EditReq) (*ad.Response, error) {
|
||||
var req validator.AdEditValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}}
|
||||
var info dao.AdCreate
|
||||
m := model.AdModel{}.Init()
|
||||
if err := m.GetOne(w, &info); err != nil {
|
||||
log.Errorf("edit ad get: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
info.Type = uint8(req.Type)
|
||||
info.Image = req.Image
|
||||
info.Content = req.Content
|
||||
info.Url = req.Url
|
||||
info.AdminId = int(adminInfo.ID)
|
||||
info.AdminName = adminInfo.Name
|
||||
|
||||
if _, err := m.Edit(w, &info); err != nil {
|
||||
log.Errorf("edit ad: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(utils.StringEmpty), nil
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
"lone-services/services/ad/internal/dao"
|
||||
"lone-services/services/ad/internal/model"
|
||||
"lone-services/services/ad/internal/svc"
|
||||
"lone-services/services/ad/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic {
|
||||
return &ItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ItemsLogic) Items(in *ad.ItemsReq) (*ad.Response, error) {
|
||||
var req validator.AdItemsValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
page := int(req.Page)
|
||||
size := int(req.PageSize)
|
||||
if page < modelbase.DefaultPage {
|
||||
page = modelbase.DefaultPage
|
||||
}
|
||||
if size < modelbase.DefaultPage {
|
||||
size = modelbase.DefaultSize
|
||||
}
|
||||
|
||||
w := modelbase.Params{
|
||||
Page: page,
|
||||
Size: size,
|
||||
Order: "id desc",
|
||||
}
|
||||
|
||||
var info []dao.AdInfo
|
||||
result, err := model.AdModel{}.Init().Page(w, &info)
|
||||
if err != nil {
|
||||
log.Errorf("ad items: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]*ad.Item, 0, len(info))
|
||||
for _, row := range info {
|
||||
items = append(items, toAdItem(row))
|
||||
}
|
||||
|
||||
return okResponse(utils.StructToJson(&ad.ItemsData{
|
||||
Count: result.Count,
|
||||
Items: items,
|
||||
})), nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"lone-services/pkg/utils"
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
)
|
||||
|
||||
func okResponse(data string) *ad.Response {
|
||||
return &ad.Response{
|
||||
Code: utils.Ok.Code,
|
||||
Msg: utils.Ok.Msg,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func failResponse(status utils.Status) *ad.Response {
|
||||
return &ad.Response{
|
||||
Code: status.Code,
|
||||
Msg: status.Msg,
|
||||
}
|
||||
}
|
||||
|
||||
func outResponse(status utils.Status, msg string) *ad.Response {
|
||||
return &ad.Response{
|
||||
Code: status.Code,
|
||||
Msg: msg,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
"lone-services/services/ad/internal/dao"
|
||||
"lone-services/services/ad/internal/model"
|
||||
"lone-services/services/ad/internal/svc"
|
||||
"lone-services/services/ad/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type StatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogic {
|
||||
return &StatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *StatusLogic) Status(in *ad.StatusReq) (*ad.Response, error) {
|
||||
var req validator.AdStatusValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}}
|
||||
var info dao.AdStatus
|
||||
m := model.AdModel{}.Init()
|
||||
if err := m.GetOne(w, &info); err != nil {
|
||||
log.Errorf("ad status get: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
info.Reason = req.Reason
|
||||
info.Status = uint8(req.Status)
|
||||
info.AdminId = int(adminInfo.ID)
|
||||
info.AdminName = adminInfo.Name
|
||||
|
||||
if _, err := m.Edit(w, &info); err != nil {
|
||||
log.Errorf("ad status edit: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(utils.StringEmpty), nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/services/ad/internal/dao"
|
||||
)
|
||||
|
||||
type AdModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
func (m AdModel) TableName() string {
|
||||
return modelbase.Prefix() + "ad"
|
||||
}
|
||||
|
||||
func (m AdModel) Init() AdModel {
|
||||
m.Table = m.TableName()
|
||||
return m
|
||||
}
|
||||
|
||||
func (m AdModel) Create(data *dao.AdCreate) error {
|
||||
return m.Base.Create(data)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
// Source: ad.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/ad/pb"
|
||||
"lone-services/services/ad/internal/logic"
|
||||
"lone-services/services/ad/internal/svc"
|
||||
)
|
||||
|
||||
type AdServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
ad.UnimplementedAdServer
|
||||
}
|
||||
|
||||
func NewAdServer(svcCtx *svc.ServiceContext) *AdServer {
|
||||
return &AdServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 添加广告
|
||||
func (s *AdServer) Create(ctx context.Context, in *ad.CreateReq) (*ad.Response, error) {
|
||||
l := logic.NewCreateLogic(ctx, s.svcCtx)
|
||||
return l.Create(in)
|
||||
}
|
||||
|
||||
// 编辑广告
|
||||
func (s *AdServer) Edit(ctx context.Context, in *ad.EditReq) (*ad.Response, error) {
|
||||
l := logic.NewEditLogic(ctx, s.svcCtx)
|
||||
return l.Edit(in)
|
||||
}
|
||||
|
||||
// 广告列表
|
||||
func (s *AdServer) Items(ctx context.Context, in *ad.ItemsReq) (*ad.Response, error) {
|
||||
l := logic.NewItemsLogic(ctx, s.svcCtx)
|
||||
return l.Items(in)
|
||||
}
|
||||
|
||||
// 广告状态
|
||||
func (s *AdServer) Status(ctx context.Context, in *ad.StatusReq) (*ad.Response, error) {
|
||||
l := logic.NewStatusLogic(ctx, s.svcCtx)
|
||||
return l.Status(in)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/ad/internal/config"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
Prefix string
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user