初始化项目
This commit is contained in:
@@ -2,7 +2,6 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
@@ -33,12 +32,7 @@ func (c *adSource) Create(ctx context.Context, req *dto.CreateAdSourceReq) (res
|
||||
|
||||
// Update 更新广告源
|
||||
func (c *adSource) Update(ctx context.Context, req *dto.UpdateAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
id, err := strconv.ParseInt(req.Id, 10, 64)
|
||||
if err != nil {
|
||||
return nil, gerror.New("无效的广告源ID")
|
||||
}
|
||||
|
||||
affected, err := service.AdSource.UpdateAdSource(ctx, id, req)
|
||||
affected, err := service.AdSource.UpdateAdSource(ctx, req.Id, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -46,7 +40,7 @@ func (c *adSource) Update(ctx context.Context, req *dto.UpdateAdSourceReq) (res
|
||||
return nil, gerror.New("广告源更新失败")
|
||||
}
|
||||
|
||||
adSource, err := service.AdSource.GetAdSourceByID(ctx, id)
|
||||
adSource, err := service.AdSource.GetAdSourceByID(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -58,12 +52,7 @@ func (c *adSource) Update(ctx context.Context, req *dto.UpdateAdSourceReq) (res
|
||||
|
||||
// Delete 删除广告源
|
||||
func (c *adSource) Delete(ctx context.Context, req *dto.DeleteAdSourceReq) (res *dto.DeleteAdSourceRes, err error) {
|
||||
id, err := strconv.ParseInt(req.Id, 10, 64)
|
||||
if err != nil {
|
||||
return nil, gerror.New("无效的广告源ID")
|
||||
}
|
||||
|
||||
affected, err := service.AdSource.DeleteAdSource(ctx, id)
|
||||
affected, err := service.AdSource.DeleteAdSource(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -78,12 +67,7 @@ func (c *adSource) Delete(ctx context.Context, req *dto.DeleteAdSourceReq) (res
|
||||
|
||||
// GetByID 根据ID获取广告源
|
||||
func (c *adSource) GetByID(ctx context.Context, req *dto.GetAdSourceReq) (res *dto.GetAdSourceRes, err error) {
|
||||
id, err := strconv.ParseInt(req.Id, 10, 64)
|
||||
if err != nil {
|
||||
return nil, gerror.New("无效的广告源ID")
|
||||
}
|
||||
|
||||
adSource, err := service.AdSource.GetAdSourceByID(ctx, id)
|
||||
adSource, err := service.AdSource.GetAdSourceByID(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -96,8 +80,8 @@ func (c *adSource) GetByID(ctx context.Context, req *dto.GetAdSourceReq) (res *d
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetList 获取广告源列表
|
||||
func (c *adSource) GetList(ctx context.Context, req *dto.ListAdSourceReq) (res *dto.ListAdSourceRes, err error) {
|
||||
// List 获取广告源列表
|
||||
func (c *adSource) List(ctx context.Context, req *dto.ListAdSourceReq) (res *dto.ListAdSourceRes, err error) {
|
||||
adSources, err := service.AdSource.GetAvailableSources(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"cid/model/dto"
|
||||
"cid/service"
|
||||
@@ -13,11 +14,14 @@ type application struct{}
|
||||
|
||||
// CreateApplication 创建应用
|
||||
func (c *application) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (res *dto.CreateApplicationRes, err error) {
|
||||
id, err := service.Application.CreateApplication(ctx, req)
|
||||
idStr, err := service.Application.CreateApplication(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将字符串ID转换为int64
|
||||
id, _ := strconv.ParseInt(idStr, 10, 64)
|
||||
|
||||
return &dto.CreateApplicationRes{
|
||||
ID: id,
|
||||
}, nil
|
||||
@@ -25,7 +29,7 @@ func (c *application) CreateApplication(ctx context.Context, req *dto.CreateAppl
|
||||
|
||||
// UpdateApplication 更新应用
|
||||
func (c *application) UpdateApplication(ctx context.Context, req *dto.UpdateApplicationReq) (res *dto.UpdateApplicationRes, err error) {
|
||||
affected, err := service.Application.UpdateApplication(ctx, req.ID, req)
|
||||
affected, err := service.Application.UpdateApplication(ctx, strconv.FormatInt(req.ID, 10), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -37,14 +41,19 @@ func (c *application) UpdateApplication(ctx context.Context, req *dto.UpdateAppl
|
||||
|
||||
// GetApplication 获取应用信息
|
||||
func (c *application) GetApplication(ctx context.Context, req *dto.GetApplicationReq) (res *dto.GetApplicationRes, err error) {
|
||||
app, err := service.Application.GetApplicationByID(ctx, req.ID)
|
||||
app, err := service.Application.GetApplicationByID(ctx, strconv.FormatInt(req.ID, 10))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将字符串ID转换为int64
|
||||
id, _ := strconv.ParseInt(app.Id, 10, 64)
|
||||
// Application实体中没有TenantId字段,暂时设为0
|
||||
tenantID := int64(0)
|
||||
|
||||
return &dto.GetApplicationRes{
|
||||
ID: app.Id,
|
||||
TenantID: app.TenantId,
|
||||
ID: id,
|
||||
TenantID: tenantID,
|
||||
Name: app.Name,
|
||||
Code: app.Code,
|
||||
Description: app.Description,
|
||||
@@ -64,7 +73,7 @@ func (c *application) GetApplication(ctx context.Context, req *dto.GetApplicatio
|
||||
|
||||
// ListApplications 获取应用列表
|
||||
func (c *application) ListApplications(ctx context.Context, req *dto.ListApplicationsReq) (res *dto.ListApplicationsRes, err error) {
|
||||
list, total, err := service.Application.GetApplicationsByTenant(ctx, req.TenantID, req.Platform, req.Status, req.Page, req.Size)
|
||||
list, total, err := service.Application.GetApplicationsByTenant(ctx, strconv.FormatInt(req.TenantID, 10), req.Platform, req.Status, req.Page, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -72,8 +81,9 @@ func (c *application) ListApplications(ctx context.Context, req *dto.ListApplica
|
||||
// 转换为响应格式
|
||||
appItems := make([]dto.ApplicationItem, len(list))
|
||||
for i, app := range list {
|
||||
id, _ := strconv.ParseInt(app.Id, 10, 64)
|
||||
appItems[i] = dto.ApplicationItem{
|
||||
ID: app.Id,
|
||||
ID: id,
|
||||
Name: app.Name,
|
||||
Code: app.Code,
|
||||
Description: app.Description,
|
||||
@@ -99,7 +109,7 @@ func (c *application) ListApplications(ctx context.Context, req *dto.ListApplica
|
||||
|
||||
// ResetAPIKeys 重置API密钥
|
||||
func (c *application) ResetAPIKeys(ctx context.Context, req *dto.ResetAPIKeysReq) (res *dto.ResetAPIKeysRes, err error) {
|
||||
appKey, appSecret, err := service.Application.ResetAPIKeys(ctx, req.ID)
|
||||
appKey, appSecret, err := service.Application.ResetAPIKeys(ctx, strconv.FormatInt(req.ID, 10))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -119,13 +129,17 @@ func (c *application) ValidateApplication(ctx context.Context, req *dto.Validate
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 将字符串ID转换为int64
|
||||
appID, _ := strconv.ParseInt(app.Id, 10, 64)
|
||||
// Application实体中没有TenantId字段,暂时设为0
|
||||
tenantID := int64(0)
|
||||
tentantName := ""
|
||||
|
||||
return &dto.ValidateApplicationRes{
|
||||
Valid: true,
|
||||
AppID: app.Id,
|
||||
AppID: appID,
|
||||
AppName: app.Name,
|
||||
TenantID: app.TenantId,
|
||||
TenantID: tenantID,
|
||||
TenantName: tentantName,
|
||||
Platform: app.Platform,
|
||||
AdTypes: app.AdTypes,
|
||||
@@ -134,7 +148,7 @@ func (c *application) ValidateApplication(ctx context.Context, req *dto.Validate
|
||||
|
||||
// DeleteApplication 删除应用
|
||||
func (c *application) DeleteApplication(ctx context.Context, req *dto.DeleteApplicationReq) (res *dto.DeleteApplicationRes, err error) {
|
||||
affected, err := service.Application.DeleteApplication(ctx, req.ID)
|
||||
affected, err := service.Application.DeleteApplication(ctx, strconv.FormatInt(req.ID, 10))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user