优化mongo,封装count逻辑,处理objectId
This commit is contained in:
@@ -12,14 +12,13 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var (
|
||||
Application = applicationService{}
|
||||
)
|
||||
type application struct{}
|
||||
|
||||
type applicationService struct{}
|
||||
// Application 应用服务
|
||||
var Application = new(application)
|
||||
|
||||
// CreateApplication 创建应用
|
||||
func (s *applicationService) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (id string, err error) {
|
||||
func (s *application) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (id string, err error) {
|
||||
// 检查应用名称是否已存在
|
||||
existingApp, err := dao.Application.GetByName(ctx, req.Name)
|
||||
if err != nil {
|
||||
@@ -57,7 +56,7 @@ func (s *applicationService) CreateApplication(ctx context.Context, req *dto.Cre
|
||||
}
|
||||
|
||||
// UpdateApplication 更新应用
|
||||
func (s *applicationService) UpdateApplication(ctx context.Context, id string, req *dto.UpdateApplicationReq) (affected int64, err error) {
|
||||
func (s *application) UpdateApplication(ctx context.Context, id string, req *dto.UpdateApplicationReq) (affected int64, err error) {
|
||||
// 检查应用是否存在
|
||||
existingApp, err := dao.Application.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
@@ -117,7 +116,7 @@ func (s *applicationService) UpdateApplication(ctx context.Context, id string, r
|
||||
}
|
||||
|
||||
// GetApplicationsByTenant 获取租户下的应用列表
|
||||
func (s *applicationService) GetApplicationsByTenant(ctx context.Context, tenantID string, platform, status string, page, size int) (list []*entity.Application, total int64, err error) {
|
||||
func (s *application) GetApplicationsByTenant(ctx context.Context, tenantID string, platform, status string, page, size int) (list []*entity.Application, total int64, err error) {
|
||||
// 调用DAO的GetByTenantID方法获取租户下的所有应用
|
||||
apps, err := dao.Application.GetByTenantID(ctx, tenantID)
|
||||
if err != nil {
|
||||
@@ -150,17 +149,17 @@ func (s *applicationService) GetApplicationsByTenant(ctx context.Context, tenant
|
||||
}
|
||||
|
||||
// GetApplicationByKey 根据API密钥获取应用
|
||||
func (s *applicationService) GetApplicationByKey(ctx context.Context, appKey string) (application *entity.Application, err error) {
|
||||
func (s *application) GetApplicationByKey(ctx context.Context, appKey string) (application *entity.Application, err error) {
|
||||
return dao.Application.GetByAPIKey(ctx, appKey)
|
||||
}
|
||||
|
||||
// GetApplicationByID 根据ID获取应用
|
||||
func (s *applicationService) GetApplicationByID(ctx context.Context, id string) (application *entity.Application, err error) {
|
||||
func (s *application) GetApplicationByID(ctx context.Context, id string) (application *entity.Application, err error) {
|
||||
return dao.Application.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
// DeleteApplication 删除应用
|
||||
func (s *applicationService) DeleteApplication(ctx context.Context, id string) (affected int64, err error) {
|
||||
func (s *application) DeleteApplication(ctx context.Context, id string) (affected int64, err error) {
|
||||
err = dao.Application.Delete(ctx, id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -169,7 +168,7 @@ func (s *applicationService) DeleteApplication(ctx context.Context, id string) (
|
||||
}
|
||||
|
||||
// ValidateApplication 验证应用权限
|
||||
func (s *applicationService) ValidateApplication(ctx context.Context, appKey, appSecret string) (application *entity.Application, err error) {
|
||||
func (s *application) ValidateApplication(ctx context.Context, appKey, appSecret string) (application *entity.Application, err error) {
|
||||
app, err := dao.Application.GetByAPIKey(ctx, appKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -188,7 +187,7 @@ func (s *applicationService) ValidateApplication(ctx context.Context, appKey, ap
|
||||
}
|
||||
|
||||
// generateAPIKeys 生成API密钥
|
||||
func (s *applicationService) generateAPIKeys() (appKey, appSecret string, err error) {
|
||||
func (s *application) generateAPIKeys() (appKey, appSecret string, err error) {
|
||||
// 生成32位随机字符串作为AppKey
|
||||
keyBytes := make([]byte, 16)
|
||||
if _, err := rand.Read(keyBytes); err != nil {
|
||||
@@ -207,7 +206,7 @@ func (s *applicationService) generateAPIKeys() (appKey, appSecret string, err er
|
||||
}
|
||||
|
||||
// ResetAPIKeys 重置API密钥
|
||||
func (s *applicationService) ResetAPIKeys(ctx context.Context, id string) (appKey, appSecret string, err error) {
|
||||
func (s *application) ResetAPIKeys(ctx context.Context, id string) (appKey, appSecret string, err error) {
|
||||
// 检查应用是否存在
|
||||
existingApp, err := dao.Application.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user