Skip to content

Commit

Permalink
Merge pull request #200 from suyuan32/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
suyuan32 authored Oct 17, 2023
2 parents 8f51641 + f0a5aef commit b89aad6
Show file tree
Hide file tree
Showing 43 changed files with 218 additions and 110 deletions.
34 changes: 11 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,23 @@ gen-rpc-ent-logic: # Generate logic code from Ent, need model and group params |
goctls rpc ent --schema=./rpc/ent/schema --style=$(PROJECT_STYLE) --import_prefix=/rpc --service_name=$(SERVICE) --project_name=$(SERVICE_STYLE) -o=./rpc --model=$(model) --group=$(group) --i18n=$(PROJECT_I18N) --proto_out=./rpc/desc/$(shell echo $(model) | tr A-Z a-z).proto --overwrite=true
@echo "Generate logic codes from Ent successfully"

.PHONY: build-win-rpc
build-win-rpc: # Build RPC project for Windows | 构建Windows下的RPC可执行文件
.PHONY: build-win
build-win: # Build project for Windows | 构建Windows下的可执行文件
env CGO_ENABLED=0 GOOS=windows GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -trimpath -o $(SERVICE_STYLE)_rpc.exe ./rpc/$(SERVICE_STYLE).go
@echo "Build RPC project for Windows successfully"

.PHONY: build-mac-rpc
build-mac-rpc: # Build RPC project for MacOS | 构建MacOS下的RPC可执行文件
env CGO_ENABLED=0 GOOS=darwin GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -trimpath -o $(SERVICE_STYLE)_rpc ./rpc/$(SERVICE_STYLE).go
@echo "Build RPC project for MacOS successfully"

.PHONY: build-linux-rpc
build-linux-rpc: # Build RPC project for Linux | 构建Linux下的RPC可执行文件
env CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -trimpath -o $(SERVICE_STYLE)_rpc ./rpc/$(SERVICE_STYLE).go
@echo "Build RPC project for Linux successfully"

.PHONY: build-win-api
build-win-api: # Build API project for Windows | 构建Windows下的API可执行文件
env CGO_ENABLED=0 GOOS=windows GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -trimpath -o $(SERVICE_STYLE)_api.exe ./api/$(SERVICE_STYLE).go
@echo "Build API project for windows successfully"
@echo "Build project for Windows successfully"

.PHONY: build-mac-api
build-mac-api: # Build API project for MacOS | 构建MacOS下的API可执行文件
.PHONY: build-mac
build-mac: # Build project for MacOS | 构建MacOS下的可执行文件
env CGO_ENABLED=0 GOOS=darwin GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -trimpath -o $(SERVICE_STYLE)_rpc ./rpc/$(SERVICE_STYLE).go
env CGO_ENABLED=0 GOOS=darwin GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -trimpath -o $(SERVICE_STYLE)_api ./api/$(SERVICE_STYLE).go
@echo "Build API project for MacOS successfully"
@echo "Build project for MacOS successfully"

.PHONY: build-linux-api
build-linux-api: # Build API project for Linux | 构建Linux下的API可执行文件
.PHONY: build-linux
build-linux: # Build project for Linux | 构建Linux下的可执行文件
env CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -trimpath -o $(SERVICE_STYLE)_rpc ./rpc/$(SERVICE_STYLE).go
env CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -trimpath -o $(SERVICE_STYLE)_api ./api/$(SERVICE_STYLE).go
@echo "Build API project for Linux successfully"
@echo "Build project for Linux successfully"

.PHONY: gen-swagger
gen-swagger: # Generate swagger file | 生成 swagger 文件
Expand Down
2 changes: 1 addition & 1 deletion api/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Schemes: http, https
// Host: localhost:9100
// BasePath: /
// Version: 1.1.5
// Version: 1.1.6
// Contact: [email protected]
// SecurityDefinitions:
// Token:
Expand Down
3 changes: 2 additions & 1 deletion api/internal/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"permissionDeny": "User does not have permission to access this interface",
"constraintError": "Operation failed: Data conflict",
"validationError": "Operation failed: Validation failed",
"notSingularError": "Operation failed: Data not unique"
"notSingularError": "Operation failed: Data not unique",
"serviceUnavailable": "Service is unavailable, please check if the service is enabled"
},
"apiGroup":{
"cloud_file_tag": "Cloud File's Tag",
Expand Down
3 changes: 2 additions & 1 deletion api/internal/i18n/locale/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"permissionDeny": "用户无权限访问此接口",
"constraintError": "操作失败: 数据冲突",
"validationError": "操作失败: 校验失败",
"notSingularError": "操作失败: 数据不唯一"
"notSingularError": "操作失败: 数据不唯一",
"serviceUnavailable": "服务不可用,请检查服务是否已启用"
},
"apiGroup":{
"cloud_file_tag": "云文件标签管理",
Expand Down
3 changes: 3 additions & 0 deletions api/internal/logic/base/init_job_database_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func NewInitJobDatabaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *I
}

func (l *InitJobDatabaseLogic) InitJobDatabase() (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.JobRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
result, err := l.svcCtx.JobRpc.InitDatabase(l.ctx, &job.Empty{})
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions api/internal/logic/base/init_mcms_database_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func NewInitMcmsDatabaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}

func (l *InitMcmsDatabaseLogic) InitMcmsDatabase() (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
check, err := l.svcCtx.CoreRpc.GetApiList(l.ctx, &core.ApiListReq{
Page: 1,
PageSize: 10,
Expand Down
5 changes: 5 additions & 0 deletions api/internal/logic/emaillog/create_email_log_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package emaillog

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -25,6 +27,9 @@ func NewCreateEmailLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cr
}

func (l *CreateEmailLogLogic) CreateEmailLog(req *types.EmailLogInfo) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.CreateEmailLog(l.ctx,
&mcms.EmailLogInfo{
Target: req.Target,
Expand Down
5 changes: 5 additions & 0 deletions api/internal/logic/emaillog/delete_email_log_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package emaillog

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -25,6 +27,9 @@ func NewDeleteEmailLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *De
}

func (l *DeleteEmailLogLogic) DeleteEmailLog(req *types.UUIDsReq) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.DeleteEmailLog(l.ctx, &mcms.UUIDsReq{
Ids: req.Ids,
})
Expand Down
4 changes: 4 additions & 0 deletions api/internal/logic/emaillog/get_email_log_by_id_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package emaillog
import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -26,6 +27,9 @@ func NewGetEmailLogByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *G
}

func (l *GetEmailLogByIdLogic) GetEmailLogById(req *types.UUIDReq) (resp *types.EmailLogInfoResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.GetEmailLogById(l.ctx, &mcms.UUIDReq{Id: req.Id})
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions api/internal/logic/emaillog/get_email_log_list_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package emaillog
import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -26,6 +27,9 @@ func NewGetEmailLogListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *G
}

func (l *GetEmailLogListLogic) GetEmailLogList(req *types.EmailLogListReq) (resp *types.EmailLogListResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.GetEmailLogList(l.ctx,
&mcms.EmailLogListReq{
Page: req.Page,
Expand Down
5 changes: 5 additions & 0 deletions api/internal/logic/emaillog/update_email_log_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package emaillog

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -25,6 +27,9 @@ func NewUpdateEmailLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up
}

func (l *UpdateEmailLogLogic) UpdateEmailLog(req *types.EmailLogInfo) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.UpdateEmailLog(l.ctx,
&mcms.EmailLogInfo{
Id: req.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package emailprovider

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -25,6 +27,9 @@ func NewCreateEmailProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext
}

func (l *CreateEmailProviderLogic) CreateEmailProvider(req *types.EmailProviderInfo) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.CreateEmailProvider(l.ctx,
&mcms.EmailProviderInfo{
Name: req.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package emailprovider

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -25,6 +27,9 @@ func NewDeleteEmailProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext
}

func (l *DeleteEmailProviderLogic) DeleteEmailProvider(req *types.IDsReq) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.DeleteEmailProvider(l.ctx, &mcms.IDsReq{
Ids: req.Ids,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package emailprovider
import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -26,6 +27,9 @@ func NewGetEmailProviderByIdLogic(ctx context.Context, svcCtx *svc.ServiceContex
}

func (l *GetEmailProviderByIdLogic) GetEmailProviderById(req *types.IDReq) (resp *types.EmailProviderInfoResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.GetEmailProviderById(l.ctx, &mcms.IDReq{Id: req.Id})
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package emailprovider
import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -26,6 +27,9 @@ func NewGetEmailProviderListLogic(ctx context.Context, svcCtx *svc.ServiceContex
}

func (l *GetEmailProviderListLogic) GetEmailProviderList(req *types.EmailProviderListReq) (resp *types.EmailProviderListResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.GetEmailProviderList(l.ctx,
&mcms.EmailProviderListReq{
Page: req.Page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package emailprovider

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -25,6 +27,9 @@ func NewUpdateEmailProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext
}

func (l *UpdateEmailProviderLogic) UpdateEmailProvider(req *types.EmailProviderInfo) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.UpdateEmailProvider(l.ctx,
&mcms.EmailProviderInfo{
Id: req.Id,
Expand Down
5 changes: 5 additions & 0 deletions api/internal/logic/messagesender/send_email_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package messagesender

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/suyuan32/simple-admin-message-center/types/mcms"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"

"github.com/zeromicro/go-zero/core/errorx"
"github.com/zeromicro/go-zero/core/logx"
)

Expand All @@ -24,6 +26,9 @@ func NewSendEmailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendEma
}

func (l *SendEmailLogic) SendEmail(req *types.SendEmailReq) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
result, err := l.svcCtx.McmsRpc.SendEmail(l.ctx, &mcms.EmailInfo{
Target: []string{req.Target},
Subject: req.Subject,
Expand Down
5 changes: 5 additions & 0 deletions api/internal/logic/messagesender/send_sms_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package messagesender

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/suyuan32/simple-admin-common/utils/pointy"
"github.com/suyuan32/simple-admin-message-center/types/mcms"
"github.com/zeromicro/go-zero/core/errorx"
"strings"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
Expand All @@ -26,6 +28,9 @@ func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLo
}

func (l *SendSmsLogic) SendSms(req *types.SendSmsReq) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
var result *mcms.BaseUUIDResp
if req.TemplateId == nil {
result, err = l.svcCtx.McmsRpc.SendSms(l.ctx, &mcms.SmsInfo{
Expand Down
5 changes: 5 additions & 0 deletions api/internal/logic/smslog/create_sms_log_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package smslog

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -25,6 +27,9 @@ func NewCreateSmsLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Crea
}

func (l *CreateSmsLogLogic) CreateSmsLog(req *types.SmsLogInfo) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.CreateSmsLog(l.ctx,
&mcms.SmsLogInfo{
PhoneNumber: req.PhoneNumber,
Expand Down
5 changes: 5 additions & 0 deletions api/internal/logic/smslog/delete_sms_log_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package smslog

import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -25,6 +27,9 @@ func NewDeleteSmsLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Dele
}

func (l *DeleteSmsLogLogic) DeleteSmsLog(req *types.UUIDsReq) (resp *types.BaseMsgResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.DeleteSmsLog(l.ctx, &mcms.UUIDsReq{
Ids: req.Ids,
})
Expand Down
4 changes: 4 additions & 0 deletions api/internal/logic/smslog/get_sms_log_by_id_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package smslog
import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/zeromicro/go-zero/core/errorx"

"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
Expand All @@ -26,6 +27,9 @@ func NewGetSmsLogByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
}

func (l *GetSmsLogByIdLogic) GetSmsLogById(req *types.UUIDReq) (resp *types.SmsLogInfoResp, err error) {
if !l.svcCtx.Config.McmsRpc.Enabled {
return nil, errorx.NewCodeUnavailableError(i18n.ServiceUnavailable)
}
data, err := l.svcCtx.McmsRpc.GetSmsLogById(l.ctx, &mcms.UUIDReq{Id: req.Id})
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit b89aad6

Please sign in to comment.