refactor: organize service dto contracts
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -13,12 +14,12 @@ func NewAnnouncement(service *service.AnnouncementService) *Announcement {
|
||||
return &Announcement{service: service}
|
||||
}
|
||||
|
||||
func announcementInput(req service.AnnouncementRequest) service.AnnouncementInput {
|
||||
func announcementInput(req dto.AnnouncementRequest) service.AnnouncementInput {
|
||||
return service.AnnouncementInput{ID: req.ID, Title: req.Title, Content: req.Content, UserID: req.UserID, Attachments: req.Attachments}
|
||||
}
|
||||
|
||||
func (h *Announcement) Create(c *gin.Context) {
|
||||
var req service.AnnouncementRequest
|
||||
var req dto.AnnouncementRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -47,7 +48,7 @@ func (h *Announcement) DeleteByIDs(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Announcement) Update(c *gin.Context) {
|
||||
var req service.AnnouncementRequest
|
||||
var req dto.AnnouncementRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -69,7 +70,7 @@ func (h *Announcement) Find(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Announcement) List(c *gin.Context) {
|
||||
var req service.AnnouncementSearchRequest
|
||||
var req dto.AnnouncementSearchRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -11,7 +12,7 @@ type API struct{ service *service.APIService }
|
||||
func NewAPI(service *service.APIService) *API { return &API{service: service} }
|
||||
|
||||
func (h *API) List(c *gin.Context) {
|
||||
var req service.APIListRequest
|
||||
var req dto.APIListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -40,7 +41,7 @@ func (h *API) All(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{"apis": items}, "获取成功")
|
||||
}
|
||||
func (h *API) Create(c *gin.Context) {
|
||||
var req service.APIRequest
|
||||
var req dto.APIRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -57,7 +58,7 @@ func (h *API) Create(c *gin.Context) {
|
||||
Write(c, CodeSuccess, created, "创建成功")
|
||||
}
|
||||
func (h *API) Update(c *gin.Context) {
|
||||
var req service.APIRequest
|
||||
var req dto.APIRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -73,7 +74,7 @@ func (h *API) Update(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "修改成功")
|
||||
}
|
||||
func (h *API) Delete(c *gin.Context) {
|
||||
var req service.DeleteAPIRequest
|
||||
var req dto.DeleteAPIRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -89,7 +90,7 @@ func (h *API) Delete(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *API) DeleteByIDs(c *gin.Context) {
|
||||
var req service.DeleteAPIsRequest
|
||||
var req dto.DeleteAPIsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -101,7 +102,7 @@ func (h *API) DeleteByIDs(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *API) Find(c *gin.Context) {
|
||||
var req service.GetAPIRequest
|
||||
var req dto.GetAPIRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -142,7 +143,7 @@ func (h *API) Roles(c *gin.Context) {
|
||||
Write(c, CodeSuccess, ids, "获取成功")
|
||||
}
|
||||
func (h *API) SetRoles(c *gin.Context) {
|
||||
var req service.SetAPIRolesRequest
|
||||
var req dto.SetAPIRolesRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -160,9 +161,9 @@ func (h *API) SetRoles(c *gin.Context) {
|
||||
func (h *API) Sync(engine *gin.Engine) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
routes := engine.Routes()
|
||||
values := make([]service.APIRequest, 0, len(routes))
|
||||
values := make([]dto.APIRequest, 0, len(routes))
|
||||
for _, route := range routes {
|
||||
values = append(values, service.APIRequest{Path: route.Path, Method: route.Method})
|
||||
values = append(values, dto.APIRequest{Path: route.Path, Method: route.Method})
|
||||
}
|
||||
result, err := h.service.SyncAPIResponses(c.Request.Context(), values)
|
||||
if err != nil {
|
||||
@@ -173,7 +174,7 @@ func (h *API) Sync(engine *gin.Engine) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
func (h *API) Ignore(c *gin.Context) {
|
||||
var req service.IgnoreAPIRequest
|
||||
var req dto.IgnoreAPIRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -185,7 +186,7 @@ func (h *API) Ignore(c *gin.Context) {
|
||||
OK(c)
|
||||
}
|
||||
func (h *API) ApplySync(c *gin.Context) {
|
||||
var req service.ApplyAPISyncRequest
|
||||
var req dto.ApplyAPISyncRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -205,7 +206,7 @@ func (h *API) FreshCasbin(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *API) SetPolicyPaths(c *gin.Context) {
|
||||
var req service.SetPolicyPathsRequest
|
||||
var req dto.SetPolicyPathsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -221,7 +222,7 @@ func (h *API) SetPolicyPaths(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "更新成功")
|
||||
}
|
||||
func (h *API) PolicyPaths(c *gin.Context) {
|
||||
var req service.GetPolicyPathsRequest
|
||||
var req dto.GetPolicyPathsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -238,7 +239,7 @@ func (h *API) PolicyPaths(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{"paths": paths}, "获取成功")
|
||||
}
|
||||
|
||||
func validateAPIRequest(req *service.APIRequest) string {
|
||||
func validateAPIRequest(req *dto.APIRequest) string {
|
||||
switch {
|
||||
case req.Path == "":
|
||||
return "Path值不能为空"
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -15,7 +16,7 @@ func NewAPIToken(service *service.TokenService) *APIToken {
|
||||
}
|
||||
|
||||
func (h *APIToken) Create(c *gin.Context) {
|
||||
var req service.CreateAPITokenRequest
|
||||
var req dto.CreateAPITokenRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -29,7 +30,7 @@ func (h *APIToken) Create(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *APIToken) List(c *gin.Context) {
|
||||
var req service.APITokenListRequest
|
||||
var req dto.APITokenListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -43,7 +44,7 @@ func (h *APIToken) List(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *APIToken) Delete(c *gin.Context) {
|
||||
var req service.IDRequest
|
||||
var req dto.IDRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -24,7 +25,7 @@ func NewAudit(service *service.AuditService, recorder *service.AuditRecorder, lo
|
||||
}
|
||||
|
||||
func (h *Audit) Operations(c *gin.Context) {
|
||||
var req service.OperationRecordSearchRequest
|
||||
var req dto.OperationRecordSearchRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -37,7 +38,7 @@ func (h *Audit) Operations(c *gin.Context) {
|
||||
Write(c, CodeSuccess, PageResult{List: items, Total: total, Page: req.Page, PageSize: req.PageSize}, "获取成功")
|
||||
}
|
||||
func (h *Audit) Operation(c *gin.Context) {
|
||||
var req service.AuditIDQuery
|
||||
var req dto.AuditIDQuery
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -54,7 +55,7 @@ func (h *Audit) Operation(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{"reSysOperationRecord": item}, "查询成功")
|
||||
}
|
||||
func (h *Audit) DeleteOperation(c *gin.Context) {
|
||||
var req service.IDRequest
|
||||
var req dto.IDRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -66,7 +67,7 @@ func (h *Audit) DeleteOperation(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Audit) DeleteOperations(c *gin.Context) {
|
||||
var req service.AuditIDsRequest
|
||||
var req dto.AuditIDsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -79,7 +80,7 @@ func (h *Audit) DeleteOperations(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Audit) Logins(c *gin.Context) {
|
||||
var req service.LoginLogSearchRequest
|
||||
var req dto.LoginLogSearchRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -92,7 +93,7 @@ func (h *Audit) Logins(c *gin.Context) {
|
||||
Write(c, CodeSuccess, PageResult{List: items, Total: total, Page: req.Page, PageSize: req.PageSize}, "获取成功")
|
||||
}
|
||||
func (h *Audit) Login(c *gin.Context) {
|
||||
var req service.AuditIDQuery
|
||||
var req dto.AuditIDQuery
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -105,7 +106,7 @@ func (h *Audit) Login(c *gin.Context) {
|
||||
Write(c, CodeSuccess, item, "查询成功")
|
||||
}
|
||||
func (h *Audit) DeleteLogin(c *gin.Context) {
|
||||
var req service.IDRequest
|
||||
var req dto.IDRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -117,7 +118,7 @@ func (h *Audit) DeleteLogin(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Audit) DeleteLogins(c *gin.Context) {
|
||||
var req service.AuditIDsRequest
|
||||
var req dto.AuditIDsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -130,7 +131,7 @@ func (h *Audit) DeleteLogins(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Audit) DataAccess(c *gin.Context) {
|
||||
var req service.DataAccessListRequest
|
||||
var req dto.DataAccessListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -143,7 +144,7 @@ func (h *Audit) DataAccess(c *gin.Context) {
|
||||
Write(c, CodeSuccess, PageResult{List: items, Total: total, Page: req.Page, PageSize: req.PageSize}, "获取成功")
|
||||
}
|
||||
func (h *Audit) DeleteDataAccess(c *gin.Context) {
|
||||
var req service.IDsRequest
|
||||
var req dto.IDsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -246,7 +247,7 @@ func (h *Audit) DeleteErrors(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "批量删除成功")
|
||||
}
|
||||
func (h *Audit) UpdateError(c *gin.Context) {
|
||||
var req service.ErrorRecordMutationRequest
|
||||
var req dto.ErrorRecordMutationRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -289,7 +290,7 @@ func (h *Audit) Errors(c *gin.Context) {
|
||||
Write(c, CodeSuccess, PageResult{List: items, Total: total, Page: p, PageSize: size}, "获取成功")
|
||||
}
|
||||
func (h *Audit) CreateError(c *gin.Context) {
|
||||
var req service.ErrorRecordMutationRequest
|
||||
var req dto.ErrorRecordMutationRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -19,7 +20,7 @@ func (h *Authority) List(c *gin.Context) {
|
||||
Write(c, CodeSuccess, items, "获取成功")
|
||||
}
|
||||
func (h *Authority) Create(c *gin.Context) {
|
||||
var req service.AuthorityRequest
|
||||
var req dto.AuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -40,7 +41,7 @@ func (h *Authority) Create(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{"authority": value}, "创建成功")
|
||||
}
|
||||
func (h *Authority) Copy(c *gin.Context) {
|
||||
var req service.CopyAuthorityRequest
|
||||
var req dto.CopyAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -65,7 +66,7 @@ func (h *Authority) Copy(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{"authority": value}, "拷贝成功")
|
||||
}
|
||||
func (h *Authority) Update(c *gin.Context) {
|
||||
var req service.AuthorityRequest
|
||||
var req dto.AuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -86,7 +87,7 @@ func (h *Authority) Update(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{"authority": value}, "更新成功")
|
||||
}
|
||||
func (h *Authority) Delete(c *gin.Context) {
|
||||
var req service.DeleteAuthorityRequest
|
||||
var req dto.DeleteAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -102,7 +103,7 @@ func (h *Authority) Delete(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Authority) SetUsers(c *gin.Context) {
|
||||
var req service.SetRoleUsersRequest
|
||||
var req dto.SetRoleUsersRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -118,7 +119,7 @@ func (h *Authority) SetUsers(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "设置成功")
|
||||
}
|
||||
func (h *Authority) Users(c *gin.Context) {
|
||||
var req service.SetRoleUsersRequest
|
||||
var req dto.SetRoleUsersRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -134,7 +135,7 @@ func (h *Authority) Users(c *gin.Context) {
|
||||
Write(c, CodeSuccess, ids, "获取成功")
|
||||
}
|
||||
func (h *Authority) SetDataScope(c *gin.Context) {
|
||||
var req service.SetDataScopeRequest
|
||||
var req dto.SetDataScopeRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -150,7 +151,7 @@ func (h *Authority) SetDataScope(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "设置成功")
|
||||
}
|
||||
func (h *Authority) DataScopeDepartments(c *gin.Context) {
|
||||
var req service.SetDataScopeRequest
|
||||
var req dto.SetDataScopeRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -14,7 +15,7 @@ func NewDictionary(service *service.DictionaryService) *Dictionary {
|
||||
}
|
||||
|
||||
func (h *Dictionary) Create(c *gin.Context) {
|
||||
var req service.DictionaryRequest
|
||||
var req dto.DictionaryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -27,7 +28,7 @@ func (h *Dictionary) Create(c *gin.Context) {
|
||||
Write(c, CodeSuccess, created, "创建成功")
|
||||
}
|
||||
func (h *Dictionary) Update(c *gin.Context) {
|
||||
var req service.DictionaryRequest
|
||||
var req dto.DictionaryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -39,7 +40,7 @@ func (h *Dictionary) Update(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "更新成功")
|
||||
}
|
||||
func (h *Dictionary) Delete(c *gin.Context) {
|
||||
var req service.DictionaryRequest
|
||||
var req dto.DictionaryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -51,7 +52,7 @@ func (h *Dictionary) Delete(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Dictionary) Find(c *gin.Context) {
|
||||
var req service.DictionaryRequest
|
||||
var req dto.DictionaryRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -74,7 +75,7 @@ func (h *Dictionary) List(details bool) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
func (h *Dictionary) Export(c *gin.Context) {
|
||||
var req service.DictionaryRequest
|
||||
var req dto.DictionaryRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -91,7 +92,7 @@ func (h *Dictionary) Export(c *gin.Context) {
|
||||
Write(c, CodeSuccess, item, "导出成功")
|
||||
}
|
||||
func (h *Dictionary) Import(c *gin.Context) {
|
||||
var req service.ImportDictionaryRequest
|
||||
var req dto.ImportDictionaryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -104,7 +105,7 @@ func (h *Dictionary) Import(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Dictionary) CreateDetail(c *gin.Context) {
|
||||
var req service.DictionaryDetailRequest
|
||||
var req dto.DictionaryDetailRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -116,7 +117,7 @@ func (h *Dictionary) CreateDetail(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "创建成功")
|
||||
}
|
||||
func (h *Dictionary) UpdateDetail(c *gin.Context) {
|
||||
var req service.DictionaryDetailRequest
|
||||
var req dto.DictionaryDetailRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -128,7 +129,7 @@ func (h *Dictionary) UpdateDetail(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "更新成功")
|
||||
}
|
||||
func (h *Dictionary) DeleteDetail(c *gin.Context) {
|
||||
var req service.DictionaryDetailRequest
|
||||
var req dto.DictionaryDetailRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -140,7 +141,7 @@ func (h *Dictionary) DeleteDetail(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Dictionary) FindDetail(c *gin.Context) {
|
||||
var req service.DictionaryDetailRequest
|
||||
var req dto.DictionaryDetailRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -171,7 +172,7 @@ func (h *Dictionary) Details(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
filter := service.DictionaryDetailListRequest{DictionaryID: uint(dictionaryID), Label: c.Query("label"), Value: c.Query("value")}
|
||||
filter := dto.DictionaryDetailListRequest{DictionaryID: uint(dictionaryID), Label: c.Query("label"), Value: c.Query("value")}
|
||||
if raw, exists := c.GetQuery("status"); exists {
|
||||
value, parseErr := strconv.ParseBool(raw)
|
||||
if parseErr != nil {
|
||||
@@ -231,7 +232,7 @@ func (h *Dictionary) Tree(byType bool) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
func (h *Dictionary) DetailsByParent(c *gin.Context) {
|
||||
var req service.DictionaryDetailsByParentRequest
|
||||
var req dto.DictionaryDetailsByParentRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -19,7 +20,7 @@ func (h *Email) Test(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Email) Send(c *gin.Context) {
|
||||
var req service.SendEmailRequest
|
||||
var req dto.SendEmailRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"errors"
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@@ -42,7 +43,7 @@ func exportIssueParams(values url.Values, blank bool) (map[string]string, error)
|
||||
}
|
||||
|
||||
func (h *Export) Create(c *gin.Context) {
|
||||
var req service.ExportTemplateRequest
|
||||
var req dto.ExportTemplateRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -58,7 +59,7 @@ func (h *Export) Create(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "创建成功")
|
||||
}
|
||||
func (h *Export) Update(c *gin.Context) {
|
||||
var req service.ExportTemplateRequest
|
||||
var req dto.ExportTemplateRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -74,7 +75,7 @@ func (h *Export) Update(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "更新成功")
|
||||
}
|
||||
func (h *Export) Delete(c *gin.Context) {
|
||||
var req service.IDRequest
|
||||
var req dto.IDRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -92,7 +93,7 @@ func (h *Export) Delete(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Export) DeleteMany(c *gin.Context) {
|
||||
var req service.IDsRequest
|
||||
var req dto.IDsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -104,7 +105,7 @@ func (h *Export) DeleteMany(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "批量删除成功")
|
||||
}
|
||||
func (h *Export) Find(c *gin.Context) {
|
||||
var req service.ExportTemplateRequest
|
||||
var req dto.ExportTemplateRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -33,7 +34,7 @@ func (h *IntegrationConfig) Find(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *IntegrationConfig) Save(c *gin.Context) {
|
||||
var req service.IntegrationConfigRequest
|
||||
var req dto.IntegrationConfigRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"errors"
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -66,7 +67,7 @@ func (h *Media) Upload(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Media) List(c *gin.Context) {
|
||||
var req service.MediaListRequest
|
||||
var req dto.MediaListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -79,7 +80,7 @@ func (h *Media) List(c *gin.Context) {
|
||||
Write(c, CodeSuccess, PageResult{List: items, Total: total, Page: req.Page, PageSize: req.PageSize}, "获取成功")
|
||||
}
|
||||
func (h *Media) Delete(c *gin.Context) {
|
||||
var req service.IDRequest
|
||||
var req dto.IDRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -91,7 +92,7 @@ func (h *Media) Delete(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Media) DeleteMany(c *gin.Context) {
|
||||
var req service.MediaBatchDeleteRequest
|
||||
var req dto.MediaBatchDeleteRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -122,7 +123,7 @@ func (h *Media) Find(c *gin.Context) {
|
||||
OKWithData(c, item)
|
||||
}
|
||||
func (h *Media) Rename(c *gin.Context) {
|
||||
var req service.RenameMediaRequest
|
||||
var req dto.RenameMediaRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -134,7 +135,7 @@ func (h *Media) Rename(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "编辑成功")
|
||||
}
|
||||
func (h *Media) ImportURLs(c *gin.Context) {
|
||||
var req []service.ImportMediaRequest
|
||||
var req []dto.ImportMediaRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -146,7 +147,7 @@ func (h *Media) ImportURLs(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "导入URL成功")
|
||||
}
|
||||
func (h *Media) Storage(c *gin.Context) {
|
||||
var req service.StorageListRequest
|
||||
var req dto.StorageListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -168,7 +169,7 @@ func (h *Media) Categories(c *gin.Context) {
|
||||
OKWithData(c, items)
|
||||
}
|
||||
func (h *Media) SaveCategory(c *gin.Context) {
|
||||
var req service.CategoryRequest
|
||||
var req dto.CategoryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, "参数错误")
|
||||
return
|
||||
@@ -180,7 +181,7 @@ func (h *Media) SaveCategory(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "创建/更新成功")
|
||||
}
|
||||
func (h *Media) DeleteCategory(c *gin.Context) {
|
||||
var req service.IDRequest
|
||||
var req dto.IDRequest
|
||||
if c.ShouldBindJSON(&req) != nil || req.ID == 0 {
|
||||
Fail(c, "参数错误")
|
||||
return
|
||||
@@ -194,7 +195,7 @@ func (h *Media) DeleteCategory(c *gin.Context) {
|
||||
|
||||
func (h *Media) InitUpload(c *gin.Context) {
|
||||
claims := Claims(c)
|
||||
var req service.InitUploadRequest
|
||||
var req dto.InitUploadRequest
|
||||
if claims == nil {
|
||||
Fail(c, "参数错误")
|
||||
return
|
||||
@@ -257,7 +258,7 @@ func (h *Media) SaveChunk(c *gin.Context) {
|
||||
}
|
||||
func (h *Media) CompleteUpload(c *gin.Context) {
|
||||
claims := Claims(c)
|
||||
var req service.CompleteUploadRequest
|
||||
var req dto.CompleteUploadRequest
|
||||
if claims == nil {
|
||||
Fail(c, "参数错误")
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -29,7 +30,7 @@ func (h *Menu) Tree(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Menu) Create(c *gin.Context) {
|
||||
var req service.MenuRequest
|
||||
var req dto.MenuRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -62,7 +63,7 @@ func (h *Menu) Create(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Menu) Update(c *gin.Context) {
|
||||
var req service.MenuRequest
|
||||
var req dto.MenuRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -95,7 +96,7 @@ func (h *Menu) Update(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Menu) Delete(c *gin.Context) {
|
||||
var req service.DeleteMenuRequest
|
||||
var req dto.DeleteMenuRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -112,7 +113,7 @@ func (h *Menu) Delete(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Menu) Find(c *gin.Context) {
|
||||
var req service.GetMenuRequest
|
||||
var req dto.GetMenuRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -130,7 +131,7 @@ func (h *Menu) Find(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Menu) SetAuthorityMenus(c *gin.Context) {
|
||||
var req service.SetAuthorityMenusRequest
|
||||
var req dto.SetAuthorityMenusRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -147,7 +148,7 @@ func (h *Menu) SetAuthorityMenus(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Menu) AuthorityMenus(c *gin.Context) {
|
||||
var req service.GetAuthorityMenusRequest
|
||||
var req dto.GetAuthorityMenusRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -165,7 +166,7 @@ func (h *Menu) AuthorityMenus(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Menu) RoleIDs(c *gin.Context) {
|
||||
var req service.SetMenuRolesRequest
|
||||
var req dto.SetMenuRolesRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -194,7 +195,7 @@ func (h *Menu) RoleIDs(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Menu) SetRoles(c *gin.Context) {
|
||||
var req service.SetMenuRolesRequest
|
||||
var req dto.SetMenuRolesRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -16,7 +17,7 @@ func NewOrganization(departments *service.DepartmentService, positions *service.
|
||||
}
|
||||
|
||||
func (h *Organization) ListDepartments(c *gin.Context) {
|
||||
var req service.DepartmentListRequest
|
||||
var req dto.DepartmentListRequest
|
||||
_ = c.ShouldBindJSON(&req)
|
||||
items, err := h.departments.Departments(c.Request.Context(), req.Name)
|
||||
if err != nil {
|
||||
@@ -26,7 +27,7 @@ func (h *Organization) ListDepartments(c *gin.Context) {
|
||||
Write(c, CodeSuccess, items, "获取成功")
|
||||
}
|
||||
func (h *Organization) CreateDepartment(c *gin.Context) {
|
||||
var req service.DepartmentRequest
|
||||
var req dto.DepartmentRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -42,7 +43,7 @@ func (h *Organization) CreateDepartment(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "创建成功")
|
||||
}
|
||||
func (h *Organization) UpdateDepartment(c *gin.Context) {
|
||||
var req service.DepartmentRequest
|
||||
var req dto.DepartmentRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -58,7 +59,7 @@ func (h *Organization) UpdateDepartment(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "更新成功")
|
||||
}
|
||||
func (h *Organization) DeleteDepartment(c *gin.Context) {
|
||||
var req service.DeleteDepartmentRequest
|
||||
var req dto.DeleteDepartmentRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -70,7 +71,7 @@ func (h *Organization) DeleteDepartment(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Organization) FindDepartment(c *gin.Context) {
|
||||
var req service.DeleteDepartmentRequest
|
||||
var req dto.DeleteDepartmentRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -83,7 +84,7 @@ func (h *Organization) FindDepartment(c *gin.Context) {
|
||||
Write(c, CodeSuccess, item, "获取成功")
|
||||
}
|
||||
func (h *Organization) DepartmentUsers(c *gin.Context) {
|
||||
var req service.SetDepartmentUsersRequest
|
||||
var req dto.SetDepartmentUsersRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -99,7 +100,7 @@ func (h *Organization) DepartmentUsers(c *gin.Context) {
|
||||
Write(c, CodeSuccess, ids, "获取成功")
|
||||
}
|
||||
func (h *Organization) SetDepartmentUsers(c *gin.Context) {
|
||||
var req service.SetDepartmentUsersRequest
|
||||
var req dto.SetDepartmentUsersRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -115,7 +116,7 @@ func (h *Organization) SetDepartmentUsers(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "设置成功")
|
||||
}
|
||||
func (h *Organization) SetUserDepartments(c *gin.Context) {
|
||||
var req service.SetUserDepartmentsRequest
|
||||
var req dto.SetUserDepartmentsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -132,7 +133,7 @@ func (h *Organization) SetUserDepartments(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Organization) ListPositions(c *gin.Context) {
|
||||
var req service.PositionListRequest
|
||||
var req dto.PositionListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -145,7 +146,7 @@ func (h *Organization) ListPositions(c *gin.Context) {
|
||||
Write(c, CodeSuccess, PageResult{List: items, Total: total, Page: req.Page, PageSize: req.PageSize}, "获取成功")
|
||||
}
|
||||
func (h *Organization) CreatePosition(c *gin.Context) {
|
||||
var req service.PositionRequest
|
||||
var req dto.PositionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -161,7 +162,7 @@ func (h *Organization) CreatePosition(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "创建成功")
|
||||
}
|
||||
func (h *Organization) UpdatePosition(c *gin.Context) {
|
||||
var req service.PositionRequest
|
||||
var req dto.PositionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -177,7 +178,7 @@ func (h *Organization) UpdatePosition(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "更新成功")
|
||||
}
|
||||
func (h *Organization) DeletePosition(c *gin.Context) {
|
||||
var req service.DeletePositionRequest
|
||||
var req dto.DeletePositionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -189,7 +190,7 @@ func (h *Organization) DeletePosition(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
}
|
||||
func (h *Organization) FindPosition(c *gin.Context) {
|
||||
var req service.DeletePositionRequest
|
||||
var req dto.DeletePositionRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -202,7 +203,7 @@ func (h *Organization) FindPosition(c *gin.Context) {
|
||||
Write(c, CodeSuccess, item, "获取成功")
|
||||
}
|
||||
func (h *Organization) PositionUsers(c *gin.Context) {
|
||||
var req service.SetPositionUsersRequest
|
||||
var req dto.SetPositionUsersRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -218,7 +219,7 @@ func (h *Organization) PositionUsers(c *gin.Context) {
|
||||
Write(c, CodeSuccess, ids, "获取成功")
|
||||
}
|
||||
func (h *Organization) SetPositionUsers(c *gin.Context) {
|
||||
var req service.SetPositionUsersRequest
|
||||
var req dto.SetPositionUsersRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -234,7 +235,7 @@ func (h *Organization) SetPositionUsers(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "设置成功")
|
||||
}
|
||||
func (h *Organization) SetUserPositions(c *gin.Context) {
|
||||
var req service.SetUserPositionsRequest
|
||||
var req dto.SetUserPositionsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -15,7 +16,7 @@ func NewParameter(service *service.ParameterService) *Parameter {
|
||||
}
|
||||
|
||||
func (h *Parameter) Create(c *gin.Context) {
|
||||
var req service.SystemParameterRequest
|
||||
var req dto.SystemParameterRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -28,7 +29,7 @@ func (h *Parameter) Create(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Parameter) Update(c *gin.Context) {
|
||||
var req service.SystemParameterRequest
|
||||
var req dto.SystemParameterRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -76,7 +77,7 @@ func (h *Parameter) Get(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Parameter) List(c *gin.Context) {
|
||||
var req service.SystemParameterSearchRequest
|
||||
var req dto.SystemParameterSearchRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"io"
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,7 +13,7 @@ type Payment struct{ service *service.PaymentService }
|
||||
|
||||
func NewPayment(service *service.PaymentService) *Payment { return &Payment{service: service} }
|
||||
func (h *Payment) Order(c *gin.Context) {
|
||||
var req service.PaymentQueryRequest
|
||||
var req dto.PaymentQueryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -42,7 +43,7 @@ func (h *Payment) RefundByPath(c *gin.Context) {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
result, err := h.service.Refund(c.Request.Context(), &service.PaymentRefundRequest{
|
||||
result, err := h.service.Refund(c.Request.Context(), &dto.PaymentRefundRequest{
|
||||
Provider: c.Param("provider"), TradeNo: c.Param("tradeNo"), Amount: req.Amount,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -53,7 +54,7 @@ func (h *Payment) RefundByPath(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Payment) FulfillByPath(c *gin.Context) {
|
||||
result, err := h.service.Fulfill(c.Request.Context(), &service.PaymentFulfillRequest{
|
||||
result, err := h.service.Fulfill(c.Request.Context(), &dto.PaymentFulfillRequest{
|
||||
Provider: c.Param("provider"), TradeNo: c.Param("tradeNo"),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -64,7 +65,7 @@ func (h *Payment) FulfillByPath(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Payment) Orders(c *gin.Context) {
|
||||
var req service.PaymentOrderListRequest
|
||||
var req dto.PaymentOrderListRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -90,7 +91,7 @@ func (h *Payment) TestProvider(c *gin.Context) {
|
||||
OKWithData(c, result)
|
||||
}
|
||||
func (h *Payment) Create(c *gin.Context) {
|
||||
var req service.PaymentRequest
|
||||
var req dto.PaymentRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -104,7 +105,7 @@ func (h *Payment) Create(c *gin.Context) {
|
||||
OKWithData(c, result)
|
||||
}
|
||||
func (h *Payment) Query(c *gin.Context) {
|
||||
var req service.PaymentQueryRequest
|
||||
var req dto.PaymentQueryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -117,7 +118,7 @@ func (h *Payment) Query(c *gin.Context) {
|
||||
OKWithData(c, result)
|
||||
}
|
||||
func (h *Payment) Refund(c *gin.Context) {
|
||||
var req service.PaymentRefundRequest
|
||||
var req dto.PaymentRefundRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -131,7 +132,7 @@ func (h *Payment) Refund(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Payment) Fulfill(c *gin.Context) {
|
||||
var req service.PaymentFulfillRequest
|
||||
var req dto.PaymentFulfillRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -162,12 +163,12 @@ func (h *Payment) Callback(c *gin.Context) {
|
||||
query[k] = v[0]
|
||||
}
|
||||
}
|
||||
ack, err := h.service.Callback(c.Request.Context(), &service.PaymentCallbackRequest{Provider: c.Param("provider"), Headers: headers, Body: raw, Query: query})
|
||||
ack, err := h.service.Callback(c.Request.Context(), &dto.PaymentCallbackRequest{Provider: c.Param("provider"), Headers: headers, Body: raw, Query: query})
|
||||
writePaymentCallbackAck(c, ack)
|
||||
_ = err
|
||||
}
|
||||
|
||||
func writePaymentCallbackAck(c *gin.Context, ack service.PaymentCallbackAck) {
|
||||
func writePaymentCallbackAck(c *gin.Context, ack dto.PaymentCallbackAck) {
|
||||
if ack.StatusCode == 0 {
|
||||
ack.StatusCode = http.StatusInternalServerError
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service/dto"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"kra/internal/service"
|
||||
)
|
||||
|
||||
func TestWritePaymentCallbackAckDoesNotExposeError(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
recorder := httptest.NewRecorder()
|
||||
context, _ := gin.CreateTestContext(recorder)
|
||||
writePaymentCallbackAck(context, service.PaymentCallbackAck{
|
||||
writePaymentCallbackAck(context, dto.PaymentCallbackAck{
|
||||
StatusCode: 500,
|
||||
ContentType: "text/plain; charset=utf-8",
|
||||
Body: []byte("failure"),
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -13,7 +14,7 @@ func NewPermission(service *service.PermissionService) *Permission {
|
||||
}
|
||||
|
||||
func (h *Permission) Buttons(c *gin.Context) {
|
||||
var req service.GetAuthorityButtonsRequest
|
||||
var req dto.GetAuthorityButtonsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -27,7 +28,7 @@ func (h *Permission) Buttons(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Permission) SetButtons(c *gin.Context) {
|
||||
var req service.SetAuthorityButtonsRequest
|
||||
var req dto.SetAuthorityButtonsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
@@ -58,7 +59,7 @@ func (h *Public) Captcha(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Public) Login(c *gin.Context) {
|
||||
var req service.LoginRequest
|
||||
var req dto.LoginRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -126,15 +127,15 @@ func (h *Public) InitializeDatabase(engine *gin.Engine) gin.HandlerFunc {
|
||||
Fail(c, "已存在数据库配置")
|
||||
return
|
||||
}
|
||||
var input service.DatabaseInitRequest
|
||||
var input dto.DatabaseInitRequest
|
||||
if c.ShouldBindJSON(&input) != nil {
|
||||
Fail(c, "参数校验不通过")
|
||||
return
|
||||
}
|
||||
routes := engine.Routes()
|
||||
values := make([]service.Route, 0, len(routes))
|
||||
values := make([]dto.Route, 0, len(routes))
|
||||
for _, route := range routes {
|
||||
values = append(values, service.Route{Path: route.Path, Method: route.Method})
|
||||
values = append(values, dto.Route{Path: route.Path, Method: route.Method})
|
||||
}
|
||||
if err := h.system.InitializeRoutes(c.Request.Context(), &input, values); err != nil {
|
||||
Fail(c, "自动创建数据库失败,请查看后台日志,检查后在进行初始化")
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -25,7 +26,7 @@ func (h *SystemConfig) GetSecurity(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *SystemConfig) SetSecurity(c *gin.Context) {
|
||||
var req service.SecurityConfigRequest
|
||||
var req dto.SecurityConfigRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -48,7 +49,7 @@ func (h *SystemConfig) Get(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *SystemConfig) Set(c *gin.Context) {
|
||||
var req service.SetSystemConfigRequest
|
||||
var req dto.SetSystemConfigRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"fmt"
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -18,7 +19,7 @@ func NewTask(service *service.TaskService) *Task {
|
||||
}
|
||||
|
||||
func (h *Task) Create(c *gin.Context) {
|
||||
var req service.TaskRequest
|
||||
var req dto.TaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -32,7 +33,7 @@ func (h *Task) Create(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Task) Update(c *gin.Context) {
|
||||
var req service.TaskRequest
|
||||
var req dto.TaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -45,7 +46,7 @@ func (h *Task) Update(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Task) Delete(c *gin.Context) {
|
||||
var req service.DeleteTaskRequest
|
||||
var req dto.DeleteTaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -58,7 +59,7 @@ func (h *Task) Delete(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Task) Toggle(c *gin.Context) {
|
||||
var req service.ToggleTaskRequest
|
||||
var req dto.ToggleTaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -71,7 +72,7 @@ func (h *Task) Toggle(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Task) Trigger(c *gin.Context) {
|
||||
var req service.DeleteTaskRequest
|
||||
var req dto.DeleteTaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -84,7 +85,7 @@ func (h *Task) Trigger(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Task) List(c *gin.Context) {
|
||||
var req service.TaskListRequest
|
||||
var req dto.TaskListRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -98,7 +99,7 @@ func (h *Task) List(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Task) Logs(c *gin.Context) {
|
||||
var req service.TaskLogListRequest
|
||||
var req dto.TaskLogListRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -18,7 +19,7 @@ func NewUser(user *service.UserService, auth *service.AuthService) *User {
|
||||
}
|
||||
|
||||
func (h *User) List(c *gin.Context) {
|
||||
var req service.UserListRequest
|
||||
var req dto.UserListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -40,7 +41,7 @@ func (h *User) List(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *User) Create(c *gin.Context) {
|
||||
var req service.UserRequest
|
||||
var req dto.UserRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -68,7 +69,7 @@ func (h *User) Create(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if result == nil {
|
||||
result = &service.UserResponse{}
|
||||
result = &dto.UserResponse{}
|
||||
}
|
||||
Write(c, CodeError, gin.H{"user": result}, "注册失败")
|
||||
return
|
||||
@@ -77,7 +78,7 @@ func (h *User) Create(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *User) Update(c *gin.Context) {
|
||||
var req service.UserRequest
|
||||
var req dto.UserRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -99,7 +100,7 @@ func (h *User) UpdateSelf(c *gin.Context) {
|
||||
NoAuth(c, "未登录或非法访问")
|
||||
return
|
||||
}
|
||||
var req service.SelfUserRequest
|
||||
var req dto.SelfUserRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -112,7 +113,7 @@ func (h *User) UpdateSelf(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *User) Delete(c *gin.Context) {
|
||||
var req service.IDRequest
|
||||
var req dto.IDRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -134,7 +135,7 @@ func (h *User) Delete(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *User) ResetPassword(c *gin.Context) {
|
||||
var req service.ResetPasswordRequest
|
||||
var req dto.ResetPasswordRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -152,7 +153,7 @@ func (h *User) ResetPassword(c *gin.Context) {
|
||||
|
||||
func (h *User) ChangePassword(c *gin.Context) {
|
||||
claims := Claims(c)
|
||||
var req service.ChangePasswordRequest
|
||||
var req dto.ChangePasswordRequest
|
||||
if claims == nil {
|
||||
NoAuth(c, "未登录或非法访问")
|
||||
return
|
||||
@@ -199,7 +200,7 @@ func (h *User) SetSelfSetting(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *User) SetAuthorities(c *gin.Context) {
|
||||
var req service.UserAuthoritiesRequest
|
||||
var req dto.UserAuthoritiesRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -213,7 +214,7 @@ func (h *User) SetAuthorities(c *gin.Context) {
|
||||
|
||||
func (h *User) SwitchAuthority(c *gin.Context) {
|
||||
claims := Claims(c)
|
||||
var req service.SwitchAuthorityRequest
|
||||
var req dto.SwitchAuthorityRequest
|
||||
if claims == nil {
|
||||
NoAuth(c, "未登录或非法访问")
|
||||
return
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -56,7 +57,7 @@ func (h *Version) Find(c *gin.Context) {
|
||||
OKWithData(c, item)
|
||||
}
|
||||
func (h *Version) List(c *gin.Context) {
|
||||
var req service.VersionSearchRequest
|
||||
var req dto.VersionSearchRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -81,7 +82,7 @@ func (h *Version) List(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Version) Export(c *gin.Context) {
|
||||
var req service.ExportVersionRequest
|
||||
var req dto.ExportVersionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
@@ -124,7 +125,7 @@ func (h *Version) Download(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "application/json", []byte(raw))
|
||||
}
|
||||
func (h *Version) Import(c *gin.Context) {
|
||||
var req service.ImportVersionRequest
|
||||
var req dto.ImportVersionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, "解析JSON数据失败:"+err.Error())
|
||||
return
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"kra/internal/conf"
|
||||
"kra/internal/service"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -80,7 +81,7 @@ func OperationAudit(runtime *conf.Runtime, recorder *service.AuditRecorder) gin.
|
||||
responseBody = "[超出记录长度]"
|
||||
}
|
||||
errorMessage := c.Errors.ByType(gin.ErrorTypePrivate).String()
|
||||
if err := recorder.RecordOperationRequest(c.Request.Context(), &service.OperationRecordRequest{IP: c.ClientIP(), Method: c.Request.Method, Path: path, Status: status, LatencyMS: time.Since(started).Milliseconds(), Agent: c.Request.UserAgent(), ErrorMessage: errorMessage, Body: operationRequestBody(requestBody, c.GetHeader("Content-Type"), maxBytes), Response: responseBody, UserID: userID, RequestID: stringValue(requestID), TraceID: stringValueFromContext(c, "trace_id"), DeviceID: c.GetHeader("X-Device-Id")}); err != nil {
|
||||
if err := recorder.RecordOperationRequest(c.Request.Context(), &dto.OperationRecordRequest{IP: c.ClientIP(), Method: c.Request.Method, Path: path, Status: status, LatencyMS: time.Since(started).Milliseconds(), Agent: c.Request.UserAgent(), ErrorMessage: errorMessage, Body: operationRequestBody(requestBody, c.GetHeader("Content-Type"), maxBytes), Response: responseBody, UserID: userID, RequestID: stringValue(requestID), TraceID: stringValueFromContext(c, "trace_id"), DeviceID: c.GetHeader("X-Device-Id")}); err != nil {
|
||||
// Preserve the business response, but expose audit persistence failures
|
||||
// to the global access/error logging pipeline.
|
||||
c.Set(ctxOperationAuditPersistFailedKey, true)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type AnnouncementInput struct {
|
||||
@@ -22,8 +23,8 @@ func NewAnnouncementService(uc *biz.AnnouncementUsecase) *AnnouncementService {
|
||||
return &AnnouncementService{uc: uc}
|
||||
}
|
||||
|
||||
func announcementDTO(item *biz.Announcement) *AnnouncementResponse {
|
||||
return &AnnouncementResponse{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, DeletedAt: nil, Title: item.Title, Content: item.Content, UserID: item.UserID, Attachments: json.RawMessage(item.Attachments)}
|
||||
func announcementDTO(item *biz.Announcement) *dto.AnnouncementResponse {
|
||||
return &dto.AnnouncementResponse{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, DeletedAt: nil, Title: item.Title, Content: item.Content, UserID: item.UserID, Attachments: json.RawMessage(item.Attachments)}
|
||||
}
|
||||
|
||||
func announcementDO(in AnnouncementInput) *biz.Announcement {
|
||||
@@ -46,7 +47,7 @@ func (s *AnnouncementService) DeleteByIDs(ctx context.Context, ids []string) err
|
||||
return s.uc.DeleteByIDs(ctx, ids)
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) Find(ctx context.Context, id string) (*AnnouncementResponse, error) {
|
||||
func (s *AnnouncementService) Find(ctx context.Context, id string) (*dto.AnnouncementResponse, error) {
|
||||
item, err := s.uc.Find(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -54,26 +55,26 @@ func (s *AnnouncementService) Find(ctx context.Context, id string) (*Announcemen
|
||||
return announcementDTO(item), nil
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) List(ctx context.Context, page, pageSize int, start, end *time.Time) ([]*AnnouncementResponse, int64, error) {
|
||||
func (s *AnnouncementService) List(ctx context.Context, page, pageSize int, start, end *time.Time) ([]*dto.AnnouncementResponse, int64, error) {
|
||||
items, total, err := s.uc.List(ctx, biz.AnnouncementFilter{Page: page, PageSize: pageSize, StartCreatedAt: start, EndCreatedAt: end})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
result := make([]*AnnouncementResponse, 0, len(items))
|
||||
result := make([]*dto.AnnouncementResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, announcementDTO(item))
|
||||
}
|
||||
return result, total, nil
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) UserOptions(ctx context.Context) ([]*SelectOptionResponse, error) {
|
||||
func (s *AnnouncementService) UserOptions(ctx context.Context) ([]*dto.SelectOptionResponse, error) {
|
||||
items, err := s.uc.UserOptions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*SelectOptionResponse, 0, len(items))
|
||||
result := make([]*dto.SelectOptionResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, &SelectOptionResponse{Label: item.Label, Value: item.Value})
|
||||
result = append(result, &dto.SelectOptionResponse{Label: item.Label, Value: item.Value})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
+20
-19
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type APIService struct {
|
||||
@@ -23,23 +24,23 @@ func (s *APIService) NormalizeRoutePath(path string) string {
|
||||
return NormalizeRoutePath(path, s.settings.RouterPrefix())
|
||||
}
|
||||
|
||||
func (s *APIService) apiDomain(value *APIRequest) *biz.API {
|
||||
func (s *APIService) apiDomain(value *dto.APIRequest) *biz.API {
|
||||
return &biz.API{ID: value.ID, Path: s.NormalizeRoutePath(value.Path), Description: value.Description, APIGroup: value.APIGroup, Method: value.Method}
|
||||
}
|
||||
|
||||
func apiResponse(value *biz.API) *APIResponse {
|
||||
return &APIResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Path: value.Path, Description: value.Description, APIGroup: value.APIGroup, Method: value.Method}
|
||||
func apiResponse(value *biz.API) *dto.APIResponse {
|
||||
return &dto.APIResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Path: value.Path, Description: value.Description, APIGroup: value.APIGroup, Method: value.Method}
|
||||
}
|
||||
|
||||
func apiResponses(items []*biz.API) []*APIResponse {
|
||||
out := make([]*APIResponse, 0, len(items))
|
||||
func apiResponses(items []*biz.API) []*dto.APIResponse {
|
||||
out := make([]*dto.APIResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, apiResponse(item))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *APIService) ListAPI(ctx context.Context, req *APIListRequest) ([]*APIResponse, int64, error) {
|
||||
func (s *APIService) ListAPI(ctx context.Context, req *dto.APIListRequest) ([]*dto.APIResponse, int64, error) {
|
||||
items, total, err := s.uc.ListAPIs(ctx, req.Page, req.PageSize, &biz.API{Path: req.Path, Description: req.Description, APIGroup: req.APIGroup, Method: req.Method, OrderKey: req.OrderKey, Desc: req.Desc})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -47,7 +48,7 @@ func (s *APIService) ListAPI(ctx context.Context, req *APIListRequest) ([]*APIRe
|
||||
return apiResponses(items), total, nil
|
||||
}
|
||||
|
||||
func (s *APIService) AllAPI(ctx context.Context, strict bool) ([]*APIResponse, error) {
|
||||
func (s *APIService) AllAPI(ctx context.Context, strict bool) ([]*dto.APIResponse, error) {
|
||||
items, _, err := s.uc.ListAPIs(ctx, 0, 0, &biz.API{StrictAll: strict})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -79,24 +80,24 @@ func (s *APIService) Groups(ctx context.Context) ([]string, map[string]string, e
|
||||
return groups, groupAPIMap, nil
|
||||
}
|
||||
|
||||
func (s *APIService) CreateAPIRequest(ctx context.Context, req *APIRequest) (*APIResponse, error) {
|
||||
func (s *APIService) CreateAPIRequest(ctx context.Context, req *dto.APIRequest) (*dto.APIResponse, error) {
|
||||
value := s.apiDomain(req)
|
||||
if err := s.uc.CreateAPI(ctx, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return apiResponse(value), nil
|
||||
}
|
||||
func (s *APIService) UpdateAPIRequest(ctx context.Context, req *APIRequest) error {
|
||||
func (s *APIService) UpdateAPIRequest(ctx context.Context, req *dto.APIRequest) error {
|
||||
return s.uc.UpdateAPI(ctx, s.apiDomain(req))
|
||||
}
|
||||
func (s *APIService) FindAPIResponse(ctx context.Context, id uint) (*APIResponse, error) {
|
||||
func (s *APIService) FindAPIResponse(ctx context.Context, id uint) (*dto.APIResponse, error) {
|
||||
value, err := s.uc.FindAPI(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return apiResponse(value), nil
|
||||
}
|
||||
func (s *APIService) ApplyAPISyncRequest(ctx context.Context, req *ApplyAPISyncRequest) error {
|
||||
func (s *APIService) ApplyAPISyncRequest(ctx context.Context, req *dto.ApplyAPISyncRequest) error {
|
||||
added := make([]*biz.API, 0, len(req.NewAPIs))
|
||||
deleted := make([]*biz.API, 0, len(req.DeleteAPIs))
|
||||
for i := range req.NewAPIs {
|
||||
@@ -107,28 +108,28 @@ func (s *APIService) ApplyAPISyncRequest(ctx context.Context, req *ApplyAPISyncR
|
||||
}
|
||||
return s.uc.ApplyAPISync(ctx, added, deleted)
|
||||
}
|
||||
func (s *APIService) SetPolicyPathsRequest(ctx context.Context, req *SetPolicyPathsRequest) error {
|
||||
func (s *APIService) SetPolicyPathsRequest(ctx context.Context, req *dto.SetPolicyPathsRequest) error {
|
||||
paths := make([]*biz.API, 0, len(req.Infos))
|
||||
for _, value := range req.Infos {
|
||||
paths = append(paths, &biz.API{Path: value.Path, Method: value.Method})
|
||||
}
|
||||
return s.uc.SetPolicyPaths(ctx, req.AuthorityID, paths)
|
||||
}
|
||||
func (s *APIService) PolicyPathResponses(ctx context.Context, authorityID uint) ([]PolicyPathRequest, error) {
|
||||
func (s *APIService) PolicyPathResponses(ctx context.Context, authorityID uint) ([]dto.PolicyPathRequest, error) {
|
||||
items, err := s.uc.PolicyPaths(ctx, authorityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []PolicyPathRequest
|
||||
var out []dto.PolicyPathRequest
|
||||
if len(items) > 0 {
|
||||
out = make([]PolicyPathRequest, 0, len(items))
|
||||
out = make([]dto.PolicyPathRequest, 0, len(items))
|
||||
}
|
||||
for _, item := range items {
|
||||
out = append(out, PolicyPathRequest{Path: item.Path, Method: item.Method})
|
||||
out = append(out, dto.PolicyPathRequest{Path: item.Path, Method: item.Method})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *APIService) SyncAPIResponses(ctx context.Context, routes []APIRequest) (*APISyncResponse, error) {
|
||||
func (s *APIService) SyncAPIResponses(ctx context.Context, routes []dto.APIRequest) (*dto.APISyncResponse, error) {
|
||||
items := make([]*biz.API, 0, len(routes))
|
||||
for i := range routes {
|
||||
routes[i].Path = s.NormalizeRoutePath(routes[i].Path)
|
||||
@@ -155,12 +156,12 @@ func (s *APIService) SetAPIRoles(ctx context.Context, path, method string, ids [
|
||||
func (s *APIService) FreshCasbin(ctx context.Context) error {
|
||||
return s.uc.FreshCasbin(ctx)
|
||||
}
|
||||
func (s *APIService) SyncAPIs(ctx context.Context, routes []*biz.API) (*APISyncResponse, error) {
|
||||
func (s *APIService) SyncAPIs(ctx context.Context, routes []*biz.API) (*dto.APISyncResponse, error) {
|
||||
diff, err := s.uc.SyncAPIs(ctx, routes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &APISyncResponse{NewAPIs: apiResponses(diff.Added), DeleteAPIs: apiResponses(diff.Deleted), IgnoreAPIs: apiResponses(diff.Ignored)}, nil
|
||||
return &dto.APISyncResponse{NewAPIs: apiResponses(diff.Added), DeleteAPIs: apiResponses(diff.Deleted), IgnoreAPIs: apiResponses(diff.Ignored)}, nil
|
||||
}
|
||||
func (s *APIService) SetAPIIgnored(ctx context.Context, path, method string, ignored bool) error {
|
||||
return s.uc.SetAPIIgnored(ctx, s.NormalizeRoutePath(path), method, ignored)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type TokenService struct {
|
||||
@@ -16,12 +17,12 @@ func NewTokenService(uc *biz.TokenUsecase, issuer biz.TokenIssuer) *TokenService
|
||||
return &TokenService{uc: uc, issuer: issuer}
|
||||
}
|
||||
|
||||
func tokenDTO(v *biz.APIToken) *APITokenResponse {
|
||||
var user *UserResponse
|
||||
func tokenDTO(v *biz.APIToken) *dto.APITokenResponse {
|
||||
var user *dto.UserResponse
|
||||
if v.User != nil {
|
||||
user = convertUser(v.User)
|
||||
}
|
||||
return &APITokenResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, UserID: v.UserID, AuthorityID: v.AuthorityID, Token: v.Token, Status: v.Status, ExpiresAt: v.ExpiresAt, Remark: v.Remark, User: user}
|
||||
return &dto.APITokenResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, UserID: v.UserID, AuthorityID: v.AuthorityID, Token: v.Token, Status: v.Status, ExpiresAt: v.ExpiresAt, Remark: v.Remark, User: user}
|
||||
}
|
||||
|
||||
func (s *TokenService) CreateAPIToken(ctx context.Context, userID, authorityID uint, days int, remark string) (string, error) {
|
||||
@@ -39,12 +40,12 @@ func (s *TokenService) CreateAPIToken(ctx context.Context, userID, authorityID u
|
||||
}
|
||||
return issued.Value, nil
|
||||
}
|
||||
func (s *TokenService) APITokens(ctx context.Context, page, size int, userID uint, status *bool) ([]*APITokenResponse, int64, error) {
|
||||
func (s *TokenService) APITokens(ctx context.Context, page, size int, userID uint, status *bool) ([]*dto.APITokenResponse, int64, error) {
|
||||
items, total, err := s.uc.ListAPITokens(ctx, page, size, userID, status)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*APITokenResponse, 0, len(items))
|
||||
out := make([]*dto.APITokenResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, tokenDTO(v))
|
||||
}
|
||||
|
||||
+21
-20
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type AuditService struct{ uc *biz.AuditUsecase }
|
||||
@@ -17,31 +18,31 @@ func NewAuditRecorder(uc *biz.AuditRecorderUsecase) *AuditRecorder { return &Aud
|
||||
func (s *AuditRecorder) RecordOperation(ctx context.Context, v *biz.OperationRecord) error {
|
||||
return s.uc.RecordOperation(ctx, v)
|
||||
}
|
||||
func (s *AuditRecorder) RecordOperationRequest(ctx context.Context, value *OperationRecordRequest) error {
|
||||
func (s *AuditRecorder) RecordOperationRequest(ctx context.Context, value *dto.OperationRecordRequest) error {
|
||||
return s.RecordOperation(ctx, &biz.OperationRecord{IP: value.IP, Method: value.Method, Path: value.Path, Status: value.Status, LatencyMS: value.LatencyMS, Agent: value.Agent, ErrorMessage: value.ErrorMessage, Body: value.Body, Response: value.Response, UserID: value.UserID, RequestID: value.RequestID, TraceID: value.TraceID, DeviceID: value.DeviceID})
|
||||
}
|
||||
func (s *AuditService) OperationsFilter(ctx context.Context, page, size int, path, method string, status int) ([]*OperationRecordResponse, int64, error) {
|
||||
func (s *AuditService) OperationsFilter(ctx context.Context, page, size int, path, method string, status int) ([]*dto.OperationRecordResponse, int64, error) {
|
||||
return s.Operations(ctx, page, size, &biz.OperationRecord{Path: path, Method: method, Status: status})
|
||||
}
|
||||
func opDTO(v *biz.OperationRecord) *OperationRecordResponse {
|
||||
func opDTO(v *biz.OperationRecord) *dto.OperationRecordResponse {
|
||||
var user any = map[string]any{}
|
||||
if v.User != nil {
|
||||
user = convertUser(v.User)
|
||||
}
|
||||
return &OperationRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, IP: v.IP, Method: v.Method, Path: v.Path, Status: v.Status, LatencyMS: v.LatencyMS, Agent: v.Agent, ErrorMessage: v.ErrorMessage, Body: v.Body, Response: v.Response, UserID: v.UserID, RequestID: v.RequestID, TraceID: v.TraceID, DeviceID: v.DeviceID, User: user}
|
||||
return &dto.OperationRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, IP: v.IP, Method: v.Method, Path: v.Path, Status: v.Status, LatencyMS: v.LatencyMS, Agent: v.Agent, ErrorMessage: v.ErrorMessage, Body: v.Body, Response: v.Response, UserID: v.UserID, RequestID: v.RequestID, TraceID: v.TraceID, DeviceID: v.DeviceID, User: user}
|
||||
}
|
||||
func (s *AuditService) Operations(ctx context.Context, page, size int, q *biz.OperationRecord) ([]*OperationRecordResponse, int64, error) {
|
||||
func (s *AuditService) Operations(ctx context.Context, page, size int, q *biz.OperationRecord) ([]*dto.OperationRecordResponse, int64, error) {
|
||||
items, total, err := s.uc.ListOperations(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*OperationRecordResponse, 0, len(items))
|
||||
out := make([]*dto.OperationRecordResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, opDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *AuditService) Operation(ctx context.Context, id uint) (*OperationRecordResponse, error) {
|
||||
func (s *AuditService) Operation(ctx context.Context, id uint) (*dto.OperationRecordResponse, error) {
|
||||
v, err := s.uc.FindOperation(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -55,31 +56,31 @@ func (s *AuditService) DeleteOperations(ctx context.Context, ids []int) error {
|
||||
func (s *AuditRecorder) RecordLogin(ctx context.Context, v *biz.LoginLog) error {
|
||||
return s.uc.RecordLogin(ctx, v)
|
||||
}
|
||||
func (s *AuditRecorder) RecordLoginRequest(ctx context.Context, value *LoginLogRequest) error {
|
||||
func (s *AuditRecorder) RecordLoginRequest(ctx context.Context, value *dto.LoginLogRequest) error {
|
||||
return s.RecordLogin(ctx, &biz.LoginLog{Username: value.Username, IP: value.IP, Status: value.Status, ErrorMessage: value.ErrorMessage, Agent: value.Agent, UserID: value.UserID})
|
||||
}
|
||||
func (s *AuditService) LoginsFilter(ctx context.Context, page, size int, username string, status bool) ([]*LoginLogResponse, int64, error) {
|
||||
func (s *AuditService) LoginsFilter(ctx context.Context, page, size int, username string, status bool) ([]*dto.LoginLogResponse, int64, error) {
|
||||
return s.Logins(ctx, page, size, &biz.LoginLog{Username: username, Status: status, FilterByStatus: status})
|
||||
}
|
||||
func loginDTO(v *biz.LoginLog) *LoginLogResponse {
|
||||
func loginDTO(v *biz.LoginLog) *dto.LoginLogResponse {
|
||||
var user any = map[string]any{}
|
||||
if v.User != nil {
|
||||
user = convertUser(v.User)
|
||||
}
|
||||
return &LoginLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Username: v.Username, IP: v.IP, Status: v.Status, ErrorMessage: v.ErrorMessage, Agent: v.Agent, UserID: v.UserID, User: user}
|
||||
return &dto.LoginLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Username: v.Username, IP: v.IP, Status: v.Status, ErrorMessage: v.ErrorMessage, Agent: v.Agent, UserID: v.UserID, User: user}
|
||||
}
|
||||
func (s *AuditService) Logins(ctx context.Context, page, size int, q *biz.LoginLog) ([]*LoginLogResponse, int64, error) {
|
||||
func (s *AuditService) Logins(ctx context.Context, page, size int, q *biz.LoginLog) ([]*dto.LoginLogResponse, int64, error) {
|
||||
items, total, err := s.uc.ListLogins(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*LoginLogResponse, 0, len(items))
|
||||
out := make([]*dto.LoginLogResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, loginDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *AuditService) Login(ctx context.Context, id uint) (*LoginLogResponse, error) {
|
||||
func (s *AuditService) Login(ctx context.Context, id uint) (*dto.LoginLogResponse, error) {
|
||||
v, err := s.uc.FindLogin(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -93,21 +94,21 @@ func (s *AuditService) DeleteLogins(ctx context.Context, ids []int) error {
|
||||
func (s *AuditRecorder) RecordDataAccess(ctx context.Context, v *biz.DataAccessLog) error {
|
||||
return s.uc.RecordDataAccess(ctx, v)
|
||||
}
|
||||
func (s *AuditRecorder) RecordDataAccessRequest(ctx context.Context, value *DataAccessRecordRequest) error {
|
||||
func (s *AuditRecorder) RecordDataAccessRequest(ctx context.Context, value *dto.DataAccessRecordRequest) error {
|
||||
return s.RecordDataAccess(ctx, &biz.DataAccessLog{EventType: value.EventType, Operation: value.Operation, UserID: value.UserID, AuthorityID: value.AuthorityID, RequestID: value.RequestID, Method: value.Method, Path: value.Path, Detail: value.Detail})
|
||||
}
|
||||
func (s *AuditService) DataAccessRequest(ctx context.Context, req *DataAccessListRequest) ([]*DataAccessLogResponse, int64, error) {
|
||||
func (s *AuditService) DataAccessRequest(ctx context.Context, req *dto.DataAccessListRequest) ([]*dto.DataAccessLogResponse, int64, error) {
|
||||
return s.DataAccess(ctx, req.Page, req.PageSize, &biz.DataAccessLog{EventType: req.EventType, TargetTable: req.TargetTable})
|
||||
}
|
||||
func dataAccessDTO(v *biz.DataAccessLog) *DataAccessLogResponse {
|
||||
return &DataAccessLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, EventType: v.EventType, TargetTable: v.TargetTable, Operation: v.Operation, UserID: v.UserID, AuthorityID: v.AuthorityID, Scope: v.Scope, RequestID: v.RequestID, Method: v.Method, Path: v.Path, Detail: v.Detail}
|
||||
func dataAccessDTO(v *biz.DataAccessLog) *dto.DataAccessLogResponse {
|
||||
return &dto.DataAccessLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, EventType: v.EventType, TargetTable: v.TargetTable, Operation: v.Operation, UserID: v.UserID, AuthorityID: v.AuthorityID, Scope: v.Scope, RequestID: v.RequestID, Method: v.Method, Path: v.Path, Detail: v.Detail}
|
||||
}
|
||||
func (s *AuditService) DataAccess(ctx context.Context, page, size int, q *biz.DataAccessLog) ([]*DataAccessLogResponse, int64, error) {
|
||||
func (s *AuditService) DataAccess(ctx context.Context, page, size int, q *biz.DataAccessLog) ([]*dto.DataAccessLogResponse, int64, error) {
|
||||
items, total, err := s.uc.ListDataAccess(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*DataAccessLogResponse, 0, len(items))
|
||||
out := make([]*dto.DataAccessLogResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, dataAccessDTO(v))
|
||||
}
|
||||
|
||||
@@ -5,15 +5,16 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func errorDTO(v *biz.ErrorRecord) *ErrorRecordResponse {
|
||||
return &ErrorRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Form: v.Form, Info: v.Info, Level: v.Level, RequestID: v.RequestID, TraceID: v.TraceID, Solution: v.Solution, Status: v.Status}
|
||||
func errorDTO(v *biz.ErrorRecord) *dto.ErrorRecordResponse {
|
||||
return &dto.ErrorRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Form: v.Form, Info: v.Info, Level: v.Level, RequestID: v.RequestID, TraceID: v.TraceID, Solution: v.Solution, Status: v.Status}
|
||||
}
|
||||
func (s *AuditRecorder) CreateError(ctx context.Context, v *biz.ErrorRecord) error {
|
||||
return s.uc.CreateError(ctx, v)
|
||||
}
|
||||
func recordedErrorDomain(value *ErrorRecordRequest) *biz.ErrorRecord {
|
||||
func recordedErrorDomain(value *dto.ErrorRecordRequest) *biz.ErrorRecord {
|
||||
form, info := value.Form, value.Info
|
||||
result := &biz.ErrorRecord{Form: &form, Info: &info, Level: value.Level, RequestID: value.RequestID, TraceID: value.TraceID, Status: value.Status}
|
||||
if value.Solution != "" {
|
||||
@@ -22,19 +23,19 @@ func recordedErrorDomain(value *ErrorRecordRequest) *biz.ErrorRecord {
|
||||
}
|
||||
return result
|
||||
}
|
||||
func mutatedErrorDomain(value *ErrorRecordMutationRequest) *biz.ErrorRecord {
|
||||
func mutatedErrorDomain(value *dto.ErrorRecordMutationRequest) *biz.ErrorRecord {
|
||||
return &biz.ErrorRecord{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, Form: value.Form, Info: value.Info, Level: value.Level, RequestID: value.RequestID, TraceID: value.TraceID, Solution: value.Solution, Status: value.Status}
|
||||
}
|
||||
func (s *AuditRecorder) CreateErrorRequest(ctx context.Context, req *ErrorRecordRequest) error {
|
||||
func (s *AuditRecorder) CreateErrorRequest(ctx context.Context, req *dto.ErrorRecordRequest) error {
|
||||
return s.CreateError(ctx, recordedErrorDomain(req))
|
||||
}
|
||||
func (s *AuditRecorder) CreateErrorMutationRequest(ctx context.Context, req *ErrorRecordMutationRequest) error {
|
||||
func (s *AuditRecorder) CreateErrorMutationRequest(ctx context.Context, req *dto.ErrorRecordMutationRequest) error {
|
||||
return s.CreateError(ctx, mutatedErrorDomain(req))
|
||||
}
|
||||
func (s *AuditService) UpdateErrorRequest(ctx context.Context, req *ErrorRecordMutationRequest) error {
|
||||
func (s *AuditService) UpdateErrorRequest(ctx context.Context, req *dto.ErrorRecordMutationRequest) error {
|
||||
return s.UpdateError(ctx, mutatedErrorDomain(req))
|
||||
}
|
||||
func (s *AuditService) ErrorsFilter(ctx context.Context, page, size int, form, info string, createdAtRange []time.Time) ([]*ErrorRecordResponse, int64, error) {
|
||||
func (s *AuditService) ErrorsFilter(ctx context.Context, page, size int, form, info string, createdAtRange []time.Time) ([]*dto.ErrorRecordResponse, int64, error) {
|
||||
query := &biz.ErrorRecord{CreatedAtRange: createdAtRange}
|
||||
if form != "" {
|
||||
query.Form = &form
|
||||
@@ -50,19 +51,19 @@ func (s *AuditService) UpdateError(ctx context.Context, v *biz.ErrorRecord) erro
|
||||
func (s *AuditService) DeleteErrors(ctx context.Context, ids []uint) error {
|
||||
return s.uc.DeleteErrors(ctx, ids)
|
||||
}
|
||||
func (s *AuditService) Error(ctx context.Context, id uint) (*ErrorRecordResponse, error) {
|
||||
func (s *AuditService) Error(ctx context.Context, id uint) (*dto.ErrorRecordResponse, error) {
|
||||
v, err := s.uc.FindError(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return errorDTO(v), nil
|
||||
}
|
||||
func (s *AuditService) Errors(ctx context.Context, page, size int, q *biz.ErrorRecord) ([]*ErrorRecordResponse, int64, error) {
|
||||
func (s *AuditService) Errors(ctx context.Context, page, size int, q *biz.ErrorRecord) ([]*dto.ErrorRecordResponse, int64, error) {
|
||||
items, total, err := s.uc.ListErrors(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*ErrorRecordResponse, 0, len(items))
|
||||
out := make([]*dto.ErrorRecordResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, errorDTO(v))
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type LogViewerService struct{ uc *biz.LogViewerUsecase }
|
||||
@@ -12,32 +13,32 @@ func NewLogViewerService(uc *biz.LogViewerUsecase) *LogViewerService {
|
||||
return &LogViewerService{uc: uc}
|
||||
}
|
||||
|
||||
func (s *LogViewerService) LogDates(ctx context.Context, month string) (*LogDatesResponse, error) {
|
||||
func (s *LogViewerService) LogDates(ctx context.Context, month string) (*dto.LogDatesResponse, error) {
|
||||
items, err := s.uc.LogDates(ctx, month)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*LogDateResponse, 0, len(items))
|
||||
out := make([]*dto.LogDateResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, &LogDateResponse{Date: v.Date, FileCount: v.FileCount})
|
||||
out = append(out, &dto.LogDateResponse{Date: v.Date, FileCount: v.FileCount})
|
||||
}
|
||||
return &LogDatesResponse{Month: month, Dates: out}, nil
|
||||
return &dto.LogDatesResponse{Month: month, Dates: out}, nil
|
||||
}
|
||||
func (s *LogViewerService) LogFiles(ctx context.Context, date string) (*LogFilesResponse, error) {
|
||||
func (s *LogViewerService) LogFiles(ctx context.Context, date string) (*dto.LogFilesResponse, error) {
|
||||
items, err := s.uc.LogFiles(ctx, date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*LogFileResponse, 0, len(items))
|
||||
out := make([]*dto.LogFileResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, &LogFileResponse{Path: v.Path, Name: v.Name, Size: v.Size, ModifiedAt: v.ModifiedAt})
|
||||
out = append(out, &dto.LogFileResponse{Path: v.Path, Name: v.Name, Size: v.Size, ModifiedAt: v.ModifiedAt})
|
||||
}
|
||||
return &LogFilesResponse{Date: date, Files: out}, nil
|
||||
return &dto.LogFilesResponse{Date: date, Files: out}, nil
|
||||
}
|
||||
func (s *LogViewerService) LogContent(ctx context.Context, date, path string, cursor *int64) (*LogContentResponse, error) {
|
||||
func (s *LogViewerService) LogContent(ctx context.Context, date, path string, cursor *int64) (*dto.LogContentResponse, error) {
|
||||
v, err := s.uc.LogContent(ctx, date, path, cursor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &LogContentResponse{Date: v.Date, Path: v.Path, Content: v.Content, LineCount: v.LineCount, NextCursor: v.NextCursor, HasMore: v.HasMore, LimitedByBytes: v.LimitedByBytes, Size: v.Size, ModifiedAt: v.ModifiedAt}, nil
|
||||
return &dto.LogContentResponse{Date: v.Date, Path: v.Path, Content: v.Content, LineCount: v.LineCount, NextCursor: v.NextCursor, HasMore: v.HasMore, LimitedByBytes: v.LimitedByBytes, Size: v.Size, ModifiedAt: v.ModifiedAt}, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type AuthService struct {
|
||||
@@ -14,11 +15,11 @@ func NewAuthService(uc *biz.AuthenticationUsecase) *AuthService {
|
||||
return &AuthService{uc: uc}
|
||||
}
|
||||
|
||||
func loginResult(value *biz.AuthenticationResult) *LoginResponse {
|
||||
return &LoginResponse{User: convertUser(value.User), Token: value.Token, ExpiresAt: value.ExpiresAt.UnixMilli(), NeedChangePassword: value.NeedChangePassword}
|
||||
func loginResult(value *biz.AuthenticationResult) *dto.LoginResponse {
|
||||
return &dto.LoginResponse{User: convertUser(value.User), Token: value.Token, ExpiresAt: value.ExpiresAt.UnixMilli(), NeedChangePassword: value.NeedChangePassword}
|
||||
}
|
||||
|
||||
func (s *AuthService) Login(ctx context.Context, req *LoginRequest, ip, agent string) (*LoginResponse, error) {
|
||||
func (s *AuthService) Login(ctx context.Context, req *dto.LoginRequest, ip, agent string) (*dto.LoginResponse, error) {
|
||||
value, err := s.uc.Login(ctx, &biz.LoginAttempt{Username: req.Username, Password: req.Password, CaptchaID: req.CaptchaID, Captcha: req.Captcha, IP: ip, Agent: agent})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -26,7 +27,7 @@ func (s *AuthService) Login(ctx context.Context, req *LoginRequest, ip, agent st
|
||||
return loginResult(value), nil
|
||||
}
|
||||
|
||||
func (s *AuthService) SwitchAuthority(ctx context.Context, claims *biz.AuthClaims, authorityID uint) (*LoginResponse, error) {
|
||||
func (s *AuthService) SwitchAuthority(ctx context.Context, claims *biz.AuthClaims, authorityID uint) (*dto.LoginResponse, error) {
|
||||
value, err := s.uc.SwitchAuthority(ctx, claims, authorityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type AuthorityService struct{ uc *biz.AuthorityUsecase }
|
||||
@@ -12,9 +13,9 @@ func NewAuthorityService(uc *biz.AuthorityUsecase) *AuthorityService {
|
||||
return &AuthorityService{uc: uc}
|
||||
}
|
||||
|
||||
func authorityDTO(value *biz.Authority) *AuthorityResponse {
|
||||
func authorityDTO(value *biz.Authority) *dto.AuthorityResponse {
|
||||
out := convertAuthority(*value)
|
||||
children := make([]*AuthorityResponse, 0, len(value.Children))
|
||||
children := make([]*dto.AuthorityResponse, 0, len(value.Children))
|
||||
for _, child := range value.Children {
|
||||
children = append(children, authorityDTO(child))
|
||||
}
|
||||
@@ -22,31 +23,31 @@ func authorityDTO(value *biz.Authority) *AuthorityResponse {
|
||||
return out
|
||||
}
|
||||
|
||||
func authorityDomain(req *AuthorityRequest) *biz.Authority {
|
||||
func authorityDomain(req *dto.AuthorityRequest) *biz.Authority {
|
||||
return &biz.Authority{AuthorityID: req.AuthorityID, AuthorityName: req.AuthorityName, ParentID: req.ParentID, DataScope: req.DataScope, DefaultRouter: req.DefaultRouter}
|
||||
}
|
||||
|
||||
func authorityResponse(value *biz.Authority) *AuthorityResponse {
|
||||
var menus []*MenuResponse
|
||||
func authorityResponse(value *biz.Authority) *dto.AuthorityResponse {
|
||||
var menus []*dto.MenuResponse
|
||||
if value.Menus != nil {
|
||||
menus = menuResponses(value.Menus)
|
||||
}
|
||||
return &AuthorityResponse{CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: value.DeletedAt, AuthorityID: value.AuthorityID, AuthorityName: value.AuthorityName, ParentID: value.ParentID, Children: nil, Menus: menus, DataScope: value.DataScope, DefaultRouter: value.DefaultRouter}
|
||||
return &dto.AuthorityResponse{CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: value.DeletedAt, AuthorityID: value.AuthorityID, AuthorityName: value.AuthorityName, ParentID: value.ParentID, Children: nil, Menus: menus, DataScope: value.DataScope, DefaultRouter: value.DefaultRouter}
|
||||
}
|
||||
|
||||
func (s *AuthorityService) Authorities(ctx context.Context) ([]*AuthorityResponse, error) {
|
||||
func (s *AuthorityService) Authorities(ctx context.Context) ([]*dto.AuthorityResponse, error) {
|
||||
items, err := s.uc.AuthorityTree(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
roots := make([]*AuthorityResponse, 0, len(items))
|
||||
roots := make([]*dto.AuthorityResponse, 0, len(items))
|
||||
for _, value := range items {
|
||||
roots = append(roots, authorityDTO(value))
|
||||
}
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
func (s *AuthorityService) CreateAuthorityRequest(ctx context.Context, req *AuthorityRequest) (*AuthorityResponse, error) {
|
||||
func (s *AuthorityService) CreateAuthorityRequest(ctx context.Context, req *dto.AuthorityRequest) (*dto.AuthorityResponse, error) {
|
||||
value := authorityDomain(req)
|
||||
if err := s.uc.CreateAuthority(ctx, value); err != nil {
|
||||
return nil, err
|
||||
@@ -54,17 +55,17 @@ func (s *AuthorityService) CreateAuthorityRequest(ctx context.Context, req *Auth
|
||||
return authorityResponse(value), nil
|
||||
}
|
||||
|
||||
func (s *AuthorityService) CopyAuthorityRequest(ctx context.Context, req *CopyAuthorityRequest) (*AuthorityResponse, error) {
|
||||
func (s *AuthorityService) CopyAuthorityRequest(ctx context.Context, req *dto.CopyAuthorityRequest) (*dto.AuthorityResponse, error) {
|
||||
value := authorityDomain(&req.Authority)
|
||||
if err := s.uc.CopyAuthority(ctx, req.OldAuthorityID, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := authorityResponse(value)
|
||||
result.Children = []*AuthorityResponse{}
|
||||
result.Children = []*dto.AuthorityResponse{}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *AuthorityService) UpdateAuthorityRequest(ctx context.Context, req *AuthorityRequest) (*AuthorityResponse, error) {
|
||||
func (s *AuthorityService) UpdateAuthorityRequest(ctx context.Context, req *dto.AuthorityRequest) (*dto.AuthorityResponse, error) {
|
||||
value := authorityDomain(req)
|
||||
if err := s.uc.UpdateAuthority(ctx, value); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type DepartmentService struct{ uc *biz.DepartmentUsecase }
|
||||
@@ -12,10 +13,10 @@ func NewDepartmentService(uc *biz.DepartmentUsecase) *DepartmentService {
|
||||
return &DepartmentService{uc: uc}
|
||||
}
|
||||
|
||||
func departmentResponse(value *biz.Department) *DepartmentResponse {
|
||||
var children []*DepartmentResponse
|
||||
func departmentResponse(value *biz.Department) *dto.DepartmentResponse {
|
||||
var children []*dto.DepartmentResponse
|
||||
if value.Children != nil {
|
||||
children = make([]*DepartmentResponse, 0, len(value.Children))
|
||||
children = make([]*dto.DepartmentResponse, 0, len(value.Children))
|
||||
for _, child := range value.Children {
|
||||
children = append(children, departmentResponse(child))
|
||||
}
|
||||
@@ -24,30 +25,30 @@ func departmentResponse(value *biz.Department) *DepartmentResponse {
|
||||
if value.Leader != nil {
|
||||
leader = convertUser(value.Leader)
|
||||
}
|
||||
return &DepartmentResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, ParentID: value.ParentID, Ancestors: value.Ancestors, Sort: value.Sort, LeaderID: value.LeaderID, Leader: leader, Status: value.Status, Children: children, NamePath: value.NamePath}
|
||||
return &dto.DepartmentResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, ParentID: value.ParentID, Ancestors: value.Ancestors, Sort: value.Sort, LeaderID: value.LeaderID, Leader: leader, Status: value.Status, Children: children, NamePath: value.NamePath}
|
||||
}
|
||||
|
||||
func departmentDomain(value *DepartmentRequest) *biz.Department {
|
||||
func departmentDomain(value *dto.DepartmentRequest) *biz.Department {
|
||||
return &biz.Department{ID: value.ID, Name: value.Name, ParentID: value.ParentID, Sort: value.Sort, LeaderID: value.LeaderID, Status: value.Status}
|
||||
}
|
||||
|
||||
func (s *DepartmentService) Departments(ctx context.Context, name string) ([]*DepartmentResponse, error) {
|
||||
func (s *DepartmentService) Departments(ctx context.Context, name string) ([]*dto.DepartmentResponse, error) {
|
||||
items, err := s.uc.Departments(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*DepartmentResponse, 0, len(items))
|
||||
out := make([]*dto.DepartmentResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, departmentResponse(item))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *DepartmentService) Create(ctx context.Context, req *DepartmentRequest) error {
|
||||
func (s *DepartmentService) Create(ctx context.Context, req *dto.DepartmentRequest) error {
|
||||
return s.uc.CreateDepartment(ctx, departmentDomain(req))
|
||||
}
|
||||
|
||||
func (s *DepartmentService) Update(ctx context.Context, req *DepartmentRequest) error {
|
||||
func (s *DepartmentService) Update(ctx context.Context, req *dto.DepartmentRequest) error {
|
||||
return s.uc.UpdateDepartment(ctx, departmentDomain(req))
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ func (s *DepartmentService) Delete(ctx context.Context, id uint) error {
|
||||
return s.uc.DeleteDepartment(ctx, id)
|
||||
}
|
||||
|
||||
func (s *DepartmentService) Department(ctx context.Context, id uint) (*DepartmentResponse, error) {
|
||||
func (s *DepartmentService) Department(ctx context.Context, id uint) (*dto.DepartmentResponse, error) {
|
||||
value, err := s.uc.Department(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -67,10 +68,10 @@ func (s *DepartmentService) UserIDs(ctx context.Context, id uint) ([]uint, error
|
||||
return s.uc.DepartmentUserIDs(ctx, id)
|
||||
}
|
||||
|
||||
func (s *DepartmentService) SetUsers(ctx context.Context, req *SetDepartmentUsersRequest) error {
|
||||
func (s *DepartmentService) SetUsers(ctx context.Context, req *dto.SetDepartmentUsersRequest) error {
|
||||
return s.uc.SetDepartmentUsers(ctx, req.DepartmentID, req.UserIDs)
|
||||
}
|
||||
|
||||
func (s *DepartmentService) SetUserDepartments(ctx context.Context, req *SetUserDepartmentsRequest) error {
|
||||
func (s *DepartmentService) SetUserDepartments(ctx context.Context, req *dto.SetUserDepartmentsRequest) error {
|
||||
return s.uc.SetUserDepartments(ctx, req.ID, req.DepartmentIDs, req.Primary)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type DictionaryService struct{ uc *biz.DictionaryUsecase }
|
||||
@@ -12,67 +13,67 @@ func NewDictionaryService(uc *biz.DictionaryUsecase) *DictionaryService {
|
||||
return &DictionaryService{uc: uc}
|
||||
}
|
||||
|
||||
func dictionaryDomain(value *DictionaryRequest) *biz.Dictionary {
|
||||
func dictionaryDomain(value *dto.DictionaryRequest) *biz.Dictionary {
|
||||
return &biz.Dictionary{ID: value.ID, Name: value.Name, Type: value.Type, Status: value.Status, Desc: value.Description, ParentID: value.ParentID}
|
||||
}
|
||||
func (s *DictionaryService) CreateDictionaryRequest(ctx context.Context, req *DictionaryRequest) (*DictionaryResponse, error) {
|
||||
func (s *DictionaryService) CreateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) (*dto.DictionaryResponse, error) {
|
||||
value := dictionaryDomain(req)
|
||||
if err := s.CreateDictionary(ctx, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dictionaryDTO(value), nil
|
||||
}
|
||||
func (s *DictionaryService) UpdateDictionaryRequest(ctx context.Context, req *DictionaryRequest) error {
|
||||
func (s *DictionaryService) UpdateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) error {
|
||||
return s.UpdateDictionary(ctx, dictionaryDomain(req))
|
||||
}
|
||||
func dictionaryDTO(v *biz.Dictionary) *DictionaryResponse {
|
||||
var children []*DictionaryResponse
|
||||
func dictionaryDTO(v *biz.Dictionary) *dto.DictionaryResponse {
|
||||
var children []*dto.DictionaryResponse
|
||||
if v.Children != nil {
|
||||
children = make([]*DictionaryResponse, 0, len(v.Children))
|
||||
children = make([]*dto.DictionaryResponse, 0, len(v.Children))
|
||||
for _, x := range v.Children {
|
||||
children = append(children, dictionaryDTO(x))
|
||||
}
|
||||
}
|
||||
var details []*DictionaryDetailResponse
|
||||
var details []*dto.DictionaryDetailResponse
|
||||
if v.Details != nil {
|
||||
details = make([]*DictionaryDetailResponse, 0, len(v.Details))
|
||||
details = make([]*dto.DictionaryDetailResponse, 0, len(v.Details))
|
||||
for _, x := range v.Details {
|
||||
details = append(details, detailDTO(x))
|
||||
}
|
||||
}
|
||||
return &DictionaryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Type: v.Type, Status: v.Status, Desc: v.Desc, ParentID: v.ParentID, Children: children, SysDictionaryDetails: details}
|
||||
return &dto.DictionaryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Type: v.Type, Status: v.Status, Desc: v.Desc, ParentID: v.ParentID, Children: children, SysDictionaryDetails: details}
|
||||
}
|
||||
func (s *DictionaryService) Dictionaries(ctx context.Context, page, size int, name, typ string, details bool) ([]*DictionaryResponse, int64, error) {
|
||||
func (s *DictionaryService) Dictionaries(ctx context.Context, page, size int, name, typ string, details bool) ([]*dto.DictionaryResponse, int64, error) {
|
||||
items, total, err := s.uc.ListDictionaries(ctx, page, size, name, typ, details)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*DictionaryResponse, 0, len(items))
|
||||
out := make([]*dto.DictionaryResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, dictionaryDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *DictionaryService) Dictionary(ctx context.Context, id uint, typ string, status *bool, details bool) (*DictionaryResponse, error) {
|
||||
func (s *DictionaryService) Dictionary(ctx context.Context, id uint, typ string, status *bool, details bool) (*dto.DictionaryResponse, error) {
|
||||
v, err := s.uc.FindDictionary(ctx, id, typ, status, details)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dictionaryDTO(v), nil
|
||||
}
|
||||
func (s *DictionaryService) ExportDictionary(ctx context.Context, id uint) (*DictionaryExportResponse, error) {
|
||||
func (s *DictionaryService) ExportDictionary(ctx context.Context, id uint) (*dto.DictionaryExportResponse, error) {
|
||||
v, err := s.uc.ExportDictionary(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var details []*DictionaryDetailExportResponse
|
||||
var details []*dto.DictionaryDetailExportResponse
|
||||
for _, detail := range v.Details {
|
||||
details = append(details, &DictionaryDetailExportResponse{
|
||||
details = append(details, &dto.DictionaryDetailExportResponse{
|
||||
Label: detail.Label, Value: detail.Value, Extend: detail.Extend,
|
||||
Status: detail.Status, Sort: detail.Sort, Level: detail.Level, Path: detail.Path,
|
||||
})
|
||||
}
|
||||
return &DictionaryExportResponse{
|
||||
return &dto.DictionaryExportResponse{
|
||||
Name: v.Name, Type: v.Type, Status: v.Status, Desc: v.Desc,
|
||||
SysDictionaryDetails: details,
|
||||
}, nil
|
||||
@@ -87,38 +88,38 @@ func (s *DictionaryService) DeleteDictionary(ctx context.Context, id uint) error
|
||||
return s.uc.DeleteDictionary(ctx, id)
|
||||
}
|
||||
|
||||
func detailDomain(value *DictionaryDetailRequest) *biz.DictionaryDetail {
|
||||
func detailDomain(value *dto.DictionaryDetailRequest) *biz.DictionaryDetail {
|
||||
return &biz.DictionaryDetail{ID: value.ID, Label: value.Label, Value: value.Value, Extend: value.Extend, Status: value.Status, Sort: value.Sort, DictionaryID: value.DictionaryID, ParentID: value.ParentID, Level: value.Level, Path: value.Path}
|
||||
}
|
||||
func (s *DictionaryService) CreateDictionaryDetailRequest(ctx context.Context, req *DictionaryDetailRequest) error {
|
||||
func (s *DictionaryService) CreateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
|
||||
return s.CreateDictionaryDetail(ctx, detailDomain(req))
|
||||
}
|
||||
func (s *DictionaryService) UpdateDictionaryDetailRequest(ctx context.Context, req *DictionaryDetailRequest) error {
|
||||
func (s *DictionaryService) UpdateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
|
||||
return s.UpdateDictionaryDetail(ctx, detailDomain(req))
|
||||
}
|
||||
func detailDTO(v *biz.DictionaryDetail) *DictionaryDetailResponse {
|
||||
var children []*DictionaryDetailResponse
|
||||
func detailDTO(v *biz.DictionaryDetail) *dto.DictionaryDetailResponse {
|
||||
var children []*dto.DictionaryDetailResponse
|
||||
if v.Children != nil {
|
||||
children = make([]*DictionaryDetailResponse, 0, len(v.Children))
|
||||
children = make([]*dto.DictionaryDetailResponse, 0, len(v.Children))
|
||||
for _, x := range v.Children {
|
||||
children = append(children, detailDTO(x))
|
||||
}
|
||||
}
|
||||
disabled := v.Status != nil && !*v.Status
|
||||
return &DictionaryDetailResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Label: v.Label, Value: v.Value, Extend: v.Extend, Status: v.Status, Sort: v.Sort, DictionaryID: v.DictionaryID, ParentID: v.ParentID, Level: v.Level, Path: v.Path, Disabled: disabled, Children: children}
|
||||
return &dto.DictionaryDetailResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Label: v.Label, Value: v.Value, Extend: v.Extend, Status: v.Status, Sort: v.Sort, DictionaryID: v.DictionaryID, ParentID: v.ParentID, Level: v.Level, Path: v.Path, Disabled: disabled, Children: children}
|
||||
}
|
||||
func (s *DictionaryService) DictionaryDetails(ctx context.Context, page, size int, filter biz.DictionaryDetailFilter) ([]*DictionaryDetailResponse, int64, error) {
|
||||
func (s *DictionaryService) DictionaryDetails(ctx context.Context, page, size int, filter biz.DictionaryDetailFilter) ([]*dto.DictionaryDetailResponse, int64, error) {
|
||||
items, total, err := s.uc.ListDictionaryDetails(ctx, page, size, filter)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*DictionaryDetailResponse, 0, len(items))
|
||||
out := make([]*dto.DictionaryDetailResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, detailDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *DictionaryService) DictionaryDetailsRequest(ctx context.Context, page, size int, request DictionaryDetailListRequest) ([]*DictionaryDetailResponse, int64, error) {
|
||||
func (s *DictionaryService) DictionaryDetailsRequest(ctx context.Context, page, size int, request dto.DictionaryDetailListRequest) ([]*dto.DictionaryDetailResponse, int64, error) {
|
||||
return s.DictionaryDetails(ctx, page, size, biz.DictionaryDetailFilter{
|
||||
DictionaryID: request.DictionaryID,
|
||||
Label: request.Label,
|
||||
@@ -128,21 +129,21 @@ func (s *DictionaryService) DictionaryDetailsRequest(ctx context.Context, page,
|
||||
Level: request.Level,
|
||||
})
|
||||
}
|
||||
func (s *DictionaryService) DictionaryDetail(ctx context.Context, id uint) (*DictionaryDetailResponse, error) {
|
||||
func (s *DictionaryService) DictionaryDetail(ctx context.Context, id uint) (*dto.DictionaryDetailResponse, error) {
|
||||
v, err := s.uc.FindDictionaryDetail(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return detailDTO(v), nil
|
||||
}
|
||||
func (s *DictionaryService) DictionaryPath(ctx context.Context, id uint) ([]*DictionaryDetailResponse, error) {
|
||||
path := make([]*DictionaryDetailResponse, 0)
|
||||
func (s *DictionaryService) DictionaryPath(ctx context.Context, id uint) ([]*dto.DictionaryDetailResponse, error) {
|
||||
path := make([]*dto.DictionaryDetailResponse, 0)
|
||||
for id != 0 {
|
||||
value, err := s.uc.FindDictionaryDetail(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
path = append([]*DictionaryDetailResponse{detailDTO(value)}, path...)
|
||||
path = append([]*dto.DictionaryDetailResponse{detailDTO(value)}, path...)
|
||||
if value.ParentID == nil {
|
||||
break
|
||||
}
|
||||
@@ -150,12 +151,12 @@ func (s *DictionaryService) DictionaryPath(ctx context.Context, id uint) ([]*Dic
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
func (s *DictionaryService) DictionaryTree(ctx context.Context, id uint, typ string) ([]*DictionaryDetailResponse, error) {
|
||||
func (s *DictionaryService) DictionaryTree(ctx context.Context, id uint, typ string) ([]*dto.DictionaryDetailResponse, error) {
|
||||
items, err := s.uc.DictionaryDetailTree(ctx, id, typ)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*DictionaryDetailResponse, 0, len(items))
|
||||
out := make([]*dto.DictionaryDetailResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, detailDTO(v))
|
||||
}
|
||||
|
||||
@@ -6,15 +6,16 @@ import (
|
||||
"errors"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func (s *DictionaryService) ImportDictionaryJSON(ctx context.Context, raw string) error {
|
||||
var payload struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Status *bool `json:"status"`
|
||||
Description string `json:"desc"`
|
||||
Details []DictionaryDetailRequest `json:"sysDictionaryDetails"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Status *bool `json:"status"`
|
||||
Description string `json:"desc"`
|
||||
Details []dto.DictionaryDetailRequest `json:"sysDictionaryDetails"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(raw), &payload); err != nil {
|
||||
return errors.New("JSON 格式错误: " + err.Error())
|
||||
@@ -25,19 +26,19 @@ func (s *DictionaryService) ImportDictionaryJSON(ctx context.Context, raw string
|
||||
if payload.Type == "" {
|
||||
return errors.New("字典类型不能为空")
|
||||
}
|
||||
dictionary := dictionaryDomain(&DictionaryRequest{Name: payload.Name, Type: payload.Type, Status: payload.Status, Description: payload.Description})
|
||||
dictionary := dictionaryDomain(&dto.DictionaryRequest{Name: payload.Name, Type: payload.Type, Status: payload.Status, Description: payload.Description})
|
||||
details := make([]*biz.DictionaryDetail, 0, len(payload.Details))
|
||||
for i := range payload.Details {
|
||||
details = append(details, detailDomain(&payload.Details[i]))
|
||||
}
|
||||
return s.uc.ImportDictionary(ctx, dictionary, details)
|
||||
}
|
||||
func (s *DictionaryService) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*DictionaryDetailResponse, error) {
|
||||
func (s *DictionaryService) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*dto.DictionaryDetailResponse, error) {
|
||||
items, err := s.uc.DictionaryDetailsByParent(ctx, dictionaryID, parentID, includeChildren)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*DictionaryDetailResponse, 0, len(items))
|
||||
out := make([]*dto.DictionaryDetailResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, detailDTO(item))
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
package service
|
||||
|
||||
// DTO aliases keep the service API stable while request/response contracts live in service/dto.
|
||||
import "kra/internal/service/dto"
|
||||
|
||||
type AnnouncementRequest = dto.AnnouncementRequest
|
||||
type AnnouncementResponse = dto.AnnouncementResponse
|
||||
type AnnouncementSearchRequest = dto.AnnouncementSearchRequest
|
||||
type APIListRequest = dto.APIListRequest
|
||||
type APIRequest = dto.APIRequest
|
||||
type APIResponse = dto.APIResponse
|
||||
type APISyncResponse = dto.APISyncResponse
|
||||
type APITokenListRequest = dto.APITokenListRequest
|
||||
type APITokenResponse = dto.APITokenResponse
|
||||
type ApplyAPISyncRequest = dto.ApplyAPISyncRequest
|
||||
type AuditIDQuery = dto.AuditIDQuery
|
||||
type AuditIDsRequest = dto.AuditIDsRequest
|
||||
type AuthorityMenuResponse = dto.AuthorityMenuResponse
|
||||
type AuthorityRequest = dto.AuthorityRequest
|
||||
type AuthorityResponse = dto.AuthorityResponse
|
||||
type CategoryRequest = dto.CategoryRequest
|
||||
type ChangePasswordRequest = dto.ChangePasswordRequest
|
||||
type CompleteUploadRequest = dto.CompleteUploadRequest
|
||||
type CopyAuthorityRequest = dto.CopyAuthorityRequest
|
||||
type CreateAPITokenRequest = dto.CreateAPITokenRequest
|
||||
type DataAccessListRequest = dto.DataAccessListRequest
|
||||
type DataAccessLogResponse = dto.DataAccessLogResponse
|
||||
type DataAccessRecordRequest = dto.DataAccessRecordRequest
|
||||
type DatabaseInitRequest = dto.DatabaseInitRequest
|
||||
type DeleteAPIRequest = dto.DeleteAPIRequest
|
||||
type DeleteAPIsRequest = dto.DeleteAPIsRequest
|
||||
type DeleteAuthorityRequest = dto.DeleteAuthorityRequest
|
||||
type DeleteDepartmentRequest = dto.DeleteDepartmentRequest
|
||||
type DeleteMenuRequest = dto.DeleteMenuRequest
|
||||
type DeletePositionRequest = dto.DeletePositionRequest
|
||||
type DeleteTaskRequest = dto.DeleteTaskRequest
|
||||
type DepartmentListRequest = dto.DepartmentListRequest
|
||||
type DepartmentRequest = dto.DepartmentRequest
|
||||
type DepartmentResponse = dto.DepartmentResponse
|
||||
type DictionaryDetailExportResponse = dto.DictionaryDetailExportResponse
|
||||
type DictionaryDetailListRequest = dto.DictionaryDetailListRequest
|
||||
type DictionaryDetailRequest = dto.DictionaryDetailRequest
|
||||
type DictionaryDetailResponse = dto.DictionaryDetailResponse
|
||||
type DictionaryDetailsByParentRequest = dto.DictionaryDetailsByParentRequest
|
||||
type DictionaryExportResponse = dto.DictionaryExportResponse
|
||||
type DictionaryRequest = dto.DictionaryRequest
|
||||
type DictionaryResponse = dto.DictionaryResponse
|
||||
type DynamicMenuResponse = dto.DynamicMenuResponse
|
||||
type ErrorRecordMutationRequest = dto.ErrorRecordMutationRequest
|
||||
type ErrorRecordRequest = dto.ErrorRecordRequest
|
||||
type ErrorRecordResponse = dto.ErrorRecordResponse
|
||||
type ExportConditionRequest = dto.ExportConditionRequest
|
||||
type ExportConditionResponse = dto.ExportConditionResponse
|
||||
type ExportJoinRequest = dto.ExportJoinRequest
|
||||
type ExportJoinResponse = dto.ExportJoinResponse
|
||||
type ExportTemplateRequest = dto.ExportTemplateRequest
|
||||
type ExportTemplateResponse = dto.ExportTemplateResponse
|
||||
type ExportVersionRequest = dto.ExportVersionRequest
|
||||
type GetAPIRequest = dto.GetAPIRequest
|
||||
type GetAuthorityButtonsRequest = dto.GetAuthorityButtonsRequest
|
||||
type GetAuthorityMenusRequest = dto.GetAuthorityMenusRequest
|
||||
type GetMenuRequest = dto.GetMenuRequest
|
||||
type GetPolicyPathsRequest = dto.GetPolicyPathsRequest
|
||||
type IDRequest = dto.IDRequest
|
||||
type IDsRequest = dto.IDsRequest
|
||||
type IgnoreAPIRequest = dto.IgnoreAPIRequest
|
||||
type ImportDictionaryRequest = dto.ImportDictionaryRequest
|
||||
type ImportMediaRequest = dto.ImportMediaRequest
|
||||
type ImportVersionRequest = dto.ImportVersionRequest
|
||||
type InitUploadRequest = dto.InitUploadRequest
|
||||
type InitUploadResponse = dto.InitUploadResponse
|
||||
type LogContentResponse = dto.LogContentResponse
|
||||
type LogDateResponse = dto.LogDateResponse
|
||||
type LogDatesResponse = dto.LogDatesResponse
|
||||
type LogFileResponse = dto.LogFileResponse
|
||||
type LogFilesResponse = dto.LogFilesResponse
|
||||
type LoginLogRequest = dto.LoginLogRequest
|
||||
type LoginLogResponse = dto.LoginLogResponse
|
||||
type LoginLogSearchRequest = dto.LoginLogSearchRequest
|
||||
type LoginRequest = dto.LoginRequest
|
||||
type LoginResponse = dto.LoginResponse
|
||||
type MediaBatchDeleteRequest = dto.MediaBatchDeleteRequest
|
||||
type MediaCategoryResponse = dto.MediaCategoryResponse
|
||||
type MediaListRequest = dto.MediaListRequest
|
||||
type MediaResponse = dto.MediaResponse
|
||||
type MenuButtonRequest = dto.MenuButtonRequest
|
||||
type MenuButtonResponse = dto.MenuButtonResponse
|
||||
type MenuMetaRequest = dto.MenuMetaRequest
|
||||
type MenuMetaResponse = dto.MenuMetaResponse
|
||||
type MenuParameterRequest = dto.MenuParameterRequest
|
||||
type MenuParameterResponse = dto.MenuParameterResponse
|
||||
type MenuRequest = dto.MenuRequest
|
||||
type MenuResponse = dto.MenuResponse
|
||||
type OperationRecordRequest = dto.OperationRecordRequest
|
||||
type OperationRecordResponse = dto.OperationRecordResponse
|
||||
type OperationRecordSearchRequest = dto.OperationRecordSearchRequest
|
||||
type PaymentCallbackAck = dto.PaymentCallbackAck
|
||||
type PaymentCallbackRequest = dto.PaymentCallbackRequest
|
||||
type IntegrationConfigRequest = dto.IntegrationConfigRequest
|
||||
type IntegrationConfigResponse = dto.IntegrationConfigResponse
|
||||
type PaymentFulfillRequest = dto.PaymentFulfillRequest
|
||||
type PaymentOrderListRequest = dto.PaymentOrderListRequest
|
||||
type PaymentOrderResponse = dto.PaymentOrderResponse
|
||||
type PaymentQueryRequest = dto.PaymentQueryRequest
|
||||
type PaymentRefundRequest = dto.PaymentRefundRequest
|
||||
type PaymentRequest = dto.PaymentRequest
|
||||
type PaymentResultResponse = dto.PaymentResultResponse
|
||||
type PaymentTestResult = dto.PaymentTestResult
|
||||
type PaymentTestStage = dto.PaymentTestStage
|
||||
type PolicyPathRequest = dto.PolicyPathRequest
|
||||
type PositionListRequest = dto.PositionListRequest
|
||||
type PositionRequest = dto.PositionRequest
|
||||
type PositionResponse = dto.PositionResponse
|
||||
type RenameMediaRequest = dto.RenameMediaRequest
|
||||
type ResetPasswordRequest = dto.ResetPasswordRequest
|
||||
type Route = dto.Route
|
||||
type SecurityConfigRequest = dto.SecurityConfigRequest
|
||||
type SecurityConfigResponse = dto.SecurityConfigResponse
|
||||
type SelectOptionResponse = dto.SelectOptionResponse
|
||||
type SelfUserRequest = dto.SelfUserRequest
|
||||
type SendEmailRequest = dto.SendEmailRequest
|
||||
type ServerCPUResponse = dto.ServerCPUResponse
|
||||
type ServerDiskResponse = dto.ServerDiskResponse
|
||||
type ServerInfoResponse = dto.ServerInfoResponse
|
||||
type ServerOSResponse = dto.ServerOSResponse
|
||||
type ServerRAMResponse = dto.ServerRAMResponse
|
||||
type SetAPIRolesRequest = dto.SetAPIRolesRequest
|
||||
type SetAuthorityButtonsRequest = dto.SetAuthorityButtonsRequest
|
||||
type SetAuthorityMenusRequest = dto.SetAuthorityMenusRequest
|
||||
type SetDataScopeRequest = dto.SetDataScopeRequest
|
||||
type SetDepartmentUsersRequest = dto.SetDepartmentUsersRequest
|
||||
type SetMenuRolesRequest = dto.SetMenuRolesRequest
|
||||
type SetPolicyPathsRequest = dto.SetPolicyPathsRequest
|
||||
type SetPositionUsersRequest = dto.SetPositionUsersRequest
|
||||
type SetRoleUsersRequest = dto.SetRoleUsersRequest
|
||||
type SetSystemConfigRequest = dto.SetSystemConfigRequest
|
||||
type SetUserDepartmentsRequest = dto.SetUserDepartmentsRequest
|
||||
type SetUserPositionsRequest = dto.SetUserPositionsRequest
|
||||
type StorageListRequest = dto.StorageListRequest
|
||||
type StorageObjectResponse = dto.StorageObjectResponse
|
||||
type SwitchAuthorityRequest = dto.SwitchAuthorityRequest
|
||||
type SystemParameterRequest = dto.SystemParameterRequest
|
||||
type SystemParameterResponse = dto.SystemParameterResponse
|
||||
type SystemParameterSearchRequest = dto.SystemParameterSearchRequest
|
||||
type TaskListRequest = dto.TaskListRequest
|
||||
type TaskLogListRequest = dto.TaskLogListRequest
|
||||
type TaskLogResponse = dto.TaskLogResponse
|
||||
type TaskMethodResponse = dto.TaskMethodResponse
|
||||
type TaskRequest = dto.TaskRequest
|
||||
type TaskResponse = dto.TaskResponse
|
||||
type ToggleTaskRequest = dto.ToggleTaskRequest
|
||||
type UserAuthoritiesRequest = dto.UserAuthoritiesRequest
|
||||
type UserListRequest = dto.UserListRequest
|
||||
type UserRequest = dto.UserRequest
|
||||
type UserResponse = dto.UserResponse
|
||||
type VersionAPIRequest = dto.VersionAPIRequest
|
||||
type VersionDictionaryDetailRequest = dto.VersionDictionaryDetailRequest
|
||||
type VersionDictionaryRequest = dto.VersionDictionaryRequest
|
||||
type VersionMenuButtonRequest = dto.VersionMenuButtonRequest
|
||||
type VersionMenuMetaRequest = dto.VersionMenuMetaRequest
|
||||
type VersionMenuParameterRequest = dto.VersionMenuParameterRequest
|
||||
type VersionMenuRequest = dto.VersionMenuRequest
|
||||
type VersionResponse = dto.VersionResponse
|
||||
type VersionSearchRequest = dto.VersionSearchRequest
|
||||
+16
-15
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -66,7 +67,7 @@ func (s *ExportService) ConsumeToken(ctx context.Context, token string, expectBl
|
||||
_ = s.cache.Delete(ctx, "export:"+token)
|
||||
return &ExportToken{TemplateID: value.TemplateID, Params: value.Params, Blank: value.Blank}, nil
|
||||
}
|
||||
func exportTemplateDomain(value *ExportTemplateRequest) *biz.ExportTemplate {
|
||||
func exportTemplateDomain(value *dto.ExportTemplateRequest) *biz.ExportTemplate {
|
||||
out := &biz.ExportTemplate{ID: value.ID, DBName: value.DBName, Name: value.Name, TableName: value.TableName, TemplateID: value.TemplateID, TemplateInfo: value.TemplateInfo, SQL: value.SQL, ImportSQL: value.ImportSQL, Limit: value.Limit, Order: value.Order}
|
||||
for _, item := range value.Conditions {
|
||||
out.Conditions = append(out.Conditions, biz.ExportCondition{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, TemplateID: item.TemplateID, From: item.From, Column: item.Column, Operator: item.Operator})
|
||||
@@ -76,31 +77,31 @@ func exportTemplateDomain(value *ExportTemplateRequest) *biz.ExportTemplate {
|
||||
}
|
||||
return out
|
||||
}
|
||||
func (s *ExportService) CreateRequest(ctx context.Context, req *ExportTemplateRequest) error {
|
||||
func (s *ExportService) CreateRequest(ctx context.Context, req *dto.ExportTemplateRequest) error {
|
||||
return s.Create(ctx, exportTemplateDomain(req))
|
||||
}
|
||||
func (s *ExportService) UpdateRequest(ctx context.Context, req *ExportTemplateRequest) error {
|
||||
func (s *ExportService) UpdateRequest(ctx context.Context, req *dto.ExportTemplateRequest) error {
|
||||
return s.Update(ctx, exportTemplateDomain(req))
|
||||
}
|
||||
func (s *ExportService) TemplatesFilter(ctx context.Context, page, size int, name, tableName, templateID string, start, end *time.Time) ([]*ExportTemplateResponse, int64, error) {
|
||||
func (s *ExportService) TemplatesFilter(ctx context.Context, page, size int, name, tableName, templateID string, start, end *time.Time) ([]*dto.ExportTemplateResponse, int64, error) {
|
||||
return s.Templates(ctx, page, size, &biz.ExportTemplate{Name: name, TableName: tableName, TemplateID: templateID, StartCreatedAt: start, EndCreatedAt: end})
|
||||
}
|
||||
func exportDTO(v *biz.ExportTemplate) *ExportTemplateResponse {
|
||||
var conditions []ExportConditionResponse
|
||||
func exportDTO(v *biz.ExportTemplate) *dto.ExportTemplateResponse {
|
||||
var conditions []dto.ExportConditionResponse
|
||||
if v.Conditions != nil {
|
||||
conditions = make([]ExportConditionResponse, 0, len(v.Conditions))
|
||||
conditions = make([]dto.ExportConditionResponse, 0, len(v.Conditions))
|
||||
for _, x := range v.Conditions {
|
||||
conditions = append(conditions, ExportConditionResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, From: x.From, Column: x.Column, Operator: x.Operator})
|
||||
conditions = append(conditions, dto.ExportConditionResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, From: x.From, Column: x.Column, Operator: x.Operator})
|
||||
}
|
||||
}
|
||||
var joins []ExportJoinResponse
|
||||
var joins []dto.ExportJoinResponse
|
||||
if v.Joins != nil {
|
||||
joins = make([]ExportJoinResponse, 0, len(v.Joins))
|
||||
joins = make([]dto.ExportJoinResponse, 0, len(v.Joins))
|
||||
for _, x := range v.Joins {
|
||||
joins = append(joins, ExportJoinResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, Join: x.Join, Table: x.Table, On: x.On})
|
||||
joins = append(joins, dto.ExportJoinResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, Join: x.Join, Table: x.Table, On: x.On})
|
||||
}
|
||||
}
|
||||
return &ExportTemplateResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, DBName: v.DBName, Name: v.Name, TableName: v.TableName, TemplateID: v.TemplateID, TemplateInfo: v.TemplateInfo, SQL: v.SQL, ImportSQL: v.ImportSQL, Limit: v.Limit, Order: v.Order, Conditions: conditions, Joins: joins}
|
||||
return &dto.ExportTemplateResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, DBName: v.DBName, Name: v.Name, TableName: v.TableName, TemplateID: v.TemplateID, TemplateInfo: v.TemplateInfo, SQL: v.SQL, ImportSQL: v.ImportSQL, Limit: v.Limit, Order: v.Order, Conditions: conditions, Joins: joins}
|
||||
}
|
||||
func (s *ExportService) Create(ctx context.Context, v *biz.ExportTemplate) error {
|
||||
return s.uc.CreateExportTemplate(ctx, v)
|
||||
@@ -111,19 +112,19 @@ func (s *ExportService) Update(ctx context.Context, v *biz.ExportTemplate) error
|
||||
func (s *ExportService) Delete(ctx context.Context, ids []uint) error {
|
||||
return s.uc.DeleteExportTemplates(ctx, ids)
|
||||
}
|
||||
func (s *ExportService) Template(ctx context.Context, id uint, tid string) (*ExportTemplateResponse, error) {
|
||||
func (s *ExportService) Template(ctx context.Context, id uint, tid string) (*dto.ExportTemplateResponse, error) {
|
||||
v, err := s.uc.FindExportTemplate(ctx, id, tid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return exportDTO(v), nil
|
||||
}
|
||||
func (s *ExportService) Templates(ctx context.Context, page, size int, q *biz.ExportTemplate) ([]*ExportTemplateResponse, int64, error) {
|
||||
func (s *ExportService) Templates(ctx context.Context, page, size int, q *biz.ExportTemplate) ([]*dto.ExportTemplateResponse, int64, error) {
|
||||
items, total, err := s.uc.ListExportTemplates(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*ExportTemplateResponse, 0, len(items))
|
||||
out := make([]*dto.ExportTemplateResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, exportDTO(v))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type IntegrationConfigService struct{ uc *biz.IntegrationConfigUsecase }
|
||||
@@ -13,7 +14,7 @@ func NewIntegrationConfigService(uc *biz.IntegrationConfigUsecase) *IntegrationC
|
||||
return &IntegrationConfigService{uc: uc}
|
||||
}
|
||||
|
||||
func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*IntegrationConfigResponse, error) {
|
||||
func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*dto.IntegrationConfigResponse, error) {
|
||||
configs, err := s.uc.List(ctx, kind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -25,7 +26,7 @@ func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*In
|
||||
}
|
||||
}
|
||||
definitions := biz.IntegrationDefinitions(kind)
|
||||
result := make([]*IntegrationConfigResponse, 0, len(definitions)+len(configs))
|
||||
result := make([]*dto.IntegrationConfigResponse, 0, len(definitions)+len(configs))
|
||||
for _, definition := range definitions {
|
||||
config, configured := byProvider[definition.Provider]
|
||||
values := mergeConfigJSON(definition.Defaults, nil)
|
||||
@@ -35,24 +36,24 @@ func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*In
|
||||
enabled = config.Enabled
|
||||
delete(byProvider, definition.Provider)
|
||||
}
|
||||
result = append(result, &IntegrationConfigResponse{Kind: definition.Kind, Provider: definition.Provider, Name: definition.Name, Description: definition.Description, Enabled: enabled, Configured: configured, Config: values, Fields: definition.Fields})
|
||||
result = append(result, &dto.IntegrationConfigResponse{Kind: definition.Kind, Provider: definition.Provider, Name: definition.Name, Description: definition.Description, Enabled: enabled, Configured: configured, Config: values, Fields: definition.Fields})
|
||||
}
|
||||
for _, config := range configs {
|
||||
if _, exists := byProvider[config.Provider]; !exists {
|
||||
continue
|
||||
}
|
||||
result = append(result, &IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values})
|
||||
result = append(result, &dto.IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider string) (*IntegrationConfigResponse, error) {
|
||||
func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider string) (*dto.IntegrationConfigResponse, error) {
|
||||
config, err := s.uc.Find(ctx, kind, provider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
definition, found := biz.IntegrationDefinition(config.Kind, config.Provider)
|
||||
response := &IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values}
|
||||
response := &dto.IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values}
|
||||
if found {
|
||||
response.Name = definition.Name
|
||||
response.Description = definition.Description
|
||||
@@ -62,7 +63,7 @@ func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider stri
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *IntegrationConfigService) Save(ctx context.Context, kind, provider string, req *IntegrationConfigRequest) error {
|
||||
func (s *IntegrationConfigService) Save(ctx context.Context, kind, provider string, req *dto.IntegrationConfigRequest) error {
|
||||
if req == nil {
|
||||
return s.uc.Save(ctx, nil)
|
||||
}
|
||||
|
||||
+19
-18
@@ -5,6 +5,7 @@ import (
|
||||
"io"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type MediaService struct {
|
||||
@@ -18,45 +19,45 @@ func NewMediaService(uc *biz.MediaUsecase, settings biz.RuntimeSettings) *MediaS
|
||||
func (s *MediaService) MediaConfig() biz.MediaSettings {
|
||||
return s.settings.MediaSettings()
|
||||
}
|
||||
func mediaDTO(v *biz.MediaFile) *MediaResponse {
|
||||
return &MediaResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, ClassID: v.CategoryID, URL: v.URL, Tag: v.Tag, Key: v.Key, Size: v.Size, Mime: v.Mime, MD5: v.MD5, UserID: v.UserID}
|
||||
func mediaDTO(v *biz.MediaFile) *dto.MediaResponse {
|
||||
return &dto.MediaResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, ClassID: v.CategoryID, URL: v.URL, Tag: v.Tag, Key: v.Key, Size: v.Size, Mime: v.Mime, MD5: v.MD5, UserID: v.UserID}
|
||||
}
|
||||
func categoryDTO(v *biz.AttachmentCategory) *MediaCategoryResponse {
|
||||
var children []*MediaCategoryResponse
|
||||
func categoryDTO(v *biz.AttachmentCategory) *dto.MediaCategoryResponse {
|
||||
var children []*dto.MediaCategoryResponse
|
||||
if v.Children != nil {
|
||||
children = make([]*MediaCategoryResponse, 0, len(v.Children))
|
||||
children = make([]*dto.MediaCategoryResponse, 0, len(v.Children))
|
||||
for _, x := range v.Children {
|
||||
children = append(children, categoryDTO(x))
|
||||
}
|
||||
}
|
||||
return &MediaCategoryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, PID: v.ParentID, Children: children}
|
||||
return &dto.MediaCategoryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, PID: v.ParentID, Children: children}
|
||||
}
|
||||
func (s *MediaService) Upload(ctx context.Context, userID uint, name, mime string, categoryID int, reader io.Reader, save bool) (*MediaResponse, error) {
|
||||
func (s *MediaService) Upload(ctx context.Context, userID uint, name, mime string, categoryID int, reader io.Reader, save bool) (*dto.MediaResponse, error) {
|
||||
v, err := s.uc.Upload(ctx, userID, name, mime, categoryID, reader, save)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mediaDTO(v), nil
|
||||
}
|
||||
func (s *MediaService) Media(ctx context.Context, id uint) (*MediaResponse, error) {
|
||||
func (s *MediaService) Media(ctx context.Context, id uint) (*dto.MediaResponse, error) {
|
||||
v, err := s.uc.FindMedia(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mediaDTO(v), nil
|
||||
}
|
||||
func (s *MediaService) MediaList(ctx context.Context, filter biz.MediaFilter) ([]*MediaResponse, int64, error) {
|
||||
func (s *MediaService) MediaList(ctx context.Context, filter biz.MediaFilter) ([]*dto.MediaResponse, int64, error) {
|
||||
items, total, err := s.uc.ListMedia(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*MediaResponse, 0, len(items))
|
||||
out := make([]*dto.MediaResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, mediaDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *MediaService) MediaListRequest(ctx context.Context, request *MediaListRequest) ([]*MediaResponse, int64, error) {
|
||||
func (s *MediaService) MediaListRequest(ctx context.Context, request *dto.MediaListRequest) ([]*dto.MediaResponse, int64, error) {
|
||||
return s.MediaList(ctx, biz.MediaFilter{
|
||||
Page: request.Page, PageSize: request.PageSize, Keyword: request.Keyword,
|
||||
CategoryID: request.ClassID, Tag: request.Tag, UserID: request.UserID,
|
||||
@@ -71,30 +72,30 @@ func (s *MediaService) Rename(ctx context.Context, id uint, name string) error {
|
||||
func (s *MediaService) ImportURLs(ctx context.Context, items []*biz.MediaFile) error {
|
||||
return s.uc.CreateMediaBatch(ctx, items)
|
||||
}
|
||||
func (s *MediaService) ImportURLRequests(ctx context.Context, values []ImportMediaRequest) error {
|
||||
func (s *MediaService) ImportURLRequests(ctx context.Context, values []dto.ImportMediaRequest) error {
|
||||
items := make([]*biz.MediaFile, 0, len(values))
|
||||
for _, value := range values {
|
||||
items = append(items, &biz.MediaFile{Name: value.Name, CategoryID: value.ClassID, URL: value.URL, Tag: value.Tag, Key: value.Key, Size: value.Size, Mime: value.Mime, MD5: value.MD5, UserID: value.UserID})
|
||||
}
|
||||
return s.ImportURLs(ctx, items)
|
||||
}
|
||||
func (s *MediaService) Storage(ctx context.Context, prefix, cursor string, limit int) ([]*StorageObjectResponse, string, bool, error) {
|
||||
func (s *MediaService) Storage(ctx context.Context, prefix, cursor string, limit int) ([]*dto.StorageObjectResponse, string, bool, error) {
|
||||
items, next, more, err := s.uc.ListStorage(ctx, prefix, cursor, limit)
|
||||
if err != nil {
|
||||
return nil, "", false, err
|
||||
}
|
||||
out := make([]*StorageObjectResponse, 0, len(items))
|
||||
out := make([]*dto.StorageObjectResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, &StorageObjectResponse{Key: v.Path, Size: v.Size, LastModified: v.LastModified, ContentType: v.ContentType})
|
||||
out = append(out, &dto.StorageObjectResponse{Key: v.Path, Size: v.Size, LastModified: v.LastModified, ContentType: v.ContentType})
|
||||
}
|
||||
return out, next, more, nil
|
||||
}
|
||||
func (s *MediaService) Categories(ctx context.Context) ([]*MediaCategoryResponse, error) {
|
||||
func (s *MediaService) Categories(ctx context.Context) ([]*dto.MediaCategoryResponse, error) {
|
||||
items, err := s.uc.ListCategories(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*MediaCategoryResponse, 0, len(items))
|
||||
out := make([]*dto.MediaCategoryResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, categoryDTO(v))
|
||||
}
|
||||
@@ -103,7 +104,7 @@ func (s *MediaService) Categories(ctx context.Context) ([]*MediaCategoryResponse
|
||||
func (s *MediaService) SaveCategory(ctx context.Context, v *biz.AttachmentCategory) error {
|
||||
return s.uc.SaveCategory(ctx, v)
|
||||
}
|
||||
func (s *MediaService) SaveCategoryRequest(ctx context.Context, value *CategoryRequest) error {
|
||||
func (s *MediaService) SaveCategoryRequest(ctx context.Context, value *dto.CategoryRequest) error {
|
||||
return s.SaveCategory(ctx, &biz.AttachmentCategory{ID: value.ID, Name: value.Name, ParentID: value.PID})
|
||||
}
|
||||
func (s *MediaService) DeleteCategory(ctx context.Context, id uint) error {
|
||||
|
||||
@@ -3,9 +3,11 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func (s *MediaService) InitUpload(ctx context.Context, userID uint, name, hash string, size, chunkSize int64, total int) (*InitUploadResponse, error) {
|
||||
func (s *MediaService) InitUpload(ctx context.Context, userID uint, name, hash string, size, chunkSize int64, total int) (*dto.InitUploadResponse, error) {
|
||||
session, media, chunks, err := s.uc.InitUpload(ctx, userID, name, hash, size, chunkSize, total)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -13,14 +15,14 @@ func (s *MediaService) InitUpload(ctx context.Context, userID uint, name, hash s
|
||||
if media != nil {
|
||||
// The compatible response leaves UploadedChunks nil on an instant-upload hit, producing
|
||||
// JSON null while still returning uploadId: 0.
|
||||
return &InitUploadResponse{Instant: true, Media: mediaDTO(media)}, nil
|
||||
return &dto.InitUploadResponse{Instant: true, Media: mediaDTO(media)}, nil
|
||||
}
|
||||
return &InitUploadResponse{Instant: false, UploadID: session.ID, UploadedChunks: chunks, Media: nil}, nil
|
||||
return &dto.InitUploadResponse{Instant: false, UploadID: session.ID, UploadedChunks: chunks, Media: nil}, nil
|
||||
}
|
||||
func (s *MediaService) SaveChunk(ctx context.Context, userID, uploadID uint, index int, hash string, reader io.Reader) error {
|
||||
return s.uc.SaveChunk(ctx, userID, uploadID, index, hash, reader)
|
||||
}
|
||||
func (s *MediaService) CompleteUpload(ctx context.Context, userID, uploadID uint) (*MediaResponse, error) {
|
||||
func (s *MediaService) CompleteUpload(ctx context.Context, userID, uploadID uint) (*dto.MediaResponse, error) {
|
||||
v, err := s.uc.CompleteUpload(ctx, userID, uploadID, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+33
-32
@@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type MenuService struct{ uc *biz.MenuUsecase }
|
||||
|
||||
func NewMenuService(uc *biz.MenuUsecase) *MenuService { return &MenuService{uc: uc} }
|
||||
|
||||
func (s *MenuService) List(ctx context.Context) ([]*MenuResponse, error) {
|
||||
func (s *MenuService) List(ctx context.Context) ([]*dto.MenuResponse, error) {
|
||||
items, err := s.uc.List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -18,7 +19,7 @@ func (s *MenuService) List(ctx context.Context) ([]*MenuResponse, error) {
|
||||
return menuResponses(items), nil
|
||||
}
|
||||
|
||||
func (s *MenuService) Tree(ctx context.Context) ([]*MenuResponse, error) {
|
||||
func (s *MenuService) Tree(ctx context.Context) ([]*dto.MenuResponse, error) {
|
||||
items, err := s.uc.Tree(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -26,15 +27,15 @@ func (s *MenuService) Tree(ctx context.Context) ([]*MenuResponse, error) {
|
||||
return menuResponses(items), nil
|
||||
}
|
||||
|
||||
func (s *MenuService) Create(ctx context.Context, req *MenuRequest) error {
|
||||
func (s *MenuService) Create(ctx context.Context, req *dto.MenuRequest) error {
|
||||
return s.uc.Create(ctx, menuDomain(req))
|
||||
}
|
||||
func (s *MenuService) Update(ctx context.Context, req *MenuRequest) error {
|
||||
func (s *MenuService) Update(ctx context.Context, req *dto.MenuRequest) error {
|
||||
return s.uc.Update(ctx, menuDomain(req))
|
||||
}
|
||||
func (s *MenuService) Delete(ctx context.Context, id uint) error { return s.uc.Delete(ctx, id) }
|
||||
|
||||
func (s *MenuService) Find(ctx context.Context, id uint) (*MenuResponse, error) {
|
||||
func (s *MenuService) Find(ctx context.Context, id uint) (*dto.MenuResponse, error) {
|
||||
item, err := s.uc.Find(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -42,7 +43,7 @@ func (s *MenuService) Find(ctx context.Context, id uint) (*MenuResponse, error)
|
||||
return menuResponse(item), nil
|
||||
}
|
||||
|
||||
func (s *MenuService) SetAuthorityMenus(ctx context.Context, req *SetAuthorityMenusRequest) error {
|
||||
func (s *MenuService) SetAuthorityMenus(ctx context.Context, req *dto.SetAuthorityMenusRequest) error {
|
||||
ids := make([]uint, 0, len(req.Menus))
|
||||
for _, menu := range req.Menus {
|
||||
ids = append(ids, menu.ID)
|
||||
@@ -50,15 +51,15 @@ func (s *MenuService) SetAuthorityMenus(ctx context.Context, req *SetAuthorityMe
|
||||
return s.uc.SetAuthorityMenus(ctx, req.AuthorityID, ids)
|
||||
}
|
||||
|
||||
func (s *MenuService) AuthorityMenus(ctx context.Context, authorityID uint) ([]*AuthorityMenuResponse, error) {
|
||||
func (s *MenuService) AuthorityMenus(ctx context.Context, authorityID uint) ([]*dto.AuthorityMenuResponse, error) {
|
||||
items, err := s.uc.AuthorityMenus(ctx, authorityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []*AuthorityMenuResponse
|
||||
var out []*dto.AuthorityMenuResponse
|
||||
for _, item := range items {
|
||||
item.MenuID = item.ID
|
||||
out = append(out, &AuthorityMenuResponse{DynamicMenuResponse: dynamicMenuResponse(item), AuthorityID: authorityID})
|
||||
out = append(out, &dto.AuthorityMenuResponse{DynamicMenuResponse: dynamicMenuResponse(item), AuthorityID: authorityID})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -69,11 +70,11 @@ func (s *MenuService) RoleIDs(ctx context.Context, menuID uint) ([]uint, error)
|
||||
func (s *MenuService) DefaultRouterRoleIDs(ctx context.Context, menuID uint) ([]uint, error) {
|
||||
return s.uc.DefaultRouterRoleIDs(ctx, menuID)
|
||||
}
|
||||
func (s *MenuService) SetRoles(ctx context.Context, req *SetMenuRolesRequest) error {
|
||||
func (s *MenuService) SetRoles(ctx context.Context, req *dto.SetMenuRolesRequest) error {
|
||||
return s.uc.SetRoles(ctx, req.MenuID, req.AuthorityIDs)
|
||||
}
|
||||
|
||||
func menuDomain(v *MenuRequest) *biz.Menu {
|
||||
func menuDomain(v *dto.MenuRequest) *biz.Menu {
|
||||
menu := &biz.Menu{CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, ID: v.ID, ParentID: v.ParentID, Path: v.Path, Name: v.Name, Hidden: v.Hidden, Component: v.Component, Sort: v.Sort, ActiveName: v.Meta.ActiveName, KeepAlive: v.Meta.KeepAlive, DefaultMenu: v.Meta.DefaultMenu, Title: v.Meta.Title, Icon: v.Meta.Icon, CloseTab: v.Meta.CloseTab, TransitionType: v.Meta.TransitionType}
|
||||
menu.Buttons = make([]*biz.MenuButton, 0, len(v.MenuButtons))
|
||||
for _, button := range v.MenuButtons {
|
||||
@@ -86,44 +87,44 @@ func menuDomain(v *MenuRequest) *biz.Menu {
|
||||
return menu
|
||||
}
|
||||
|
||||
func menuResponse(menu *biz.Menu) *MenuResponse {
|
||||
var children []*MenuResponse
|
||||
func menuResponse(menu *biz.Menu) *dto.MenuResponse {
|
||||
var children []*dto.MenuResponse
|
||||
if menu.Children != nil {
|
||||
children = make([]*MenuResponse, 0, len(menu.Children))
|
||||
children = make([]*dto.MenuResponse, 0, len(menu.Children))
|
||||
for _, child := range menu.Children {
|
||||
children = append(children, menuResponse(child))
|
||||
}
|
||||
}
|
||||
var buttons []MenuButtonResponse
|
||||
var buttons []dto.MenuButtonResponse
|
||||
if menu.Buttons != nil {
|
||||
buttons = make([]MenuButtonResponse, 0, len(menu.Buttons))
|
||||
buttons = make([]dto.MenuButtonResponse, 0, len(menu.Buttons))
|
||||
for _, button := range menu.Buttons {
|
||||
buttons = append(buttons, MenuButtonResponse{CreatedAt: button.CreatedAt, UpdatedAt: button.UpdatedAt, ID: button.ID, Name: button.Name, Description: button.Description, SysBaseMenuID: button.MenuID})
|
||||
buttons = append(buttons, dto.MenuButtonResponse{CreatedAt: button.CreatedAt, UpdatedAt: button.UpdatedAt, ID: button.ID, Name: button.Name, Description: button.Description, SysBaseMenuID: button.MenuID})
|
||||
}
|
||||
}
|
||||
var parameters []MenuParameterResponse
|
||||
var parameters []dto.MenuParameterResponse
|
||||
if menu.Parameters != nil {
|
||||
parameters = make([]MenuParameterResponse, 0, len(menu.Parameters))
|
||||
parameters = make([]dto.MenuParameterResponse, 0, len(menu.Parameters))
|
||||
for _, parameter := range menu.Parameters {
|
||||
parameters = append(parameters, MenuParameterResponse{CreatedAt: parameter.CreatedAt, UpdatedAt: parameter.UpdatedAt, ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
|
||||
parameters = append(parameters, dto.MenuParameterResponse{CreatedAt: parameter.CreatedAt, UpdatedAt: parameter.UpdatedAt, ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
|
||||
}
|
||||
}
|
||||
return &MenuResponse{CreatedAt: menu.CreatedAt, UpdatedAt: menu.UpdatedAt, ID: menu.ID, MenuID: menu.MenuID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: buttons}
|
||||
return &dto.MenuResponse{CreatedAt: menu.CreatedAt, UpdatedAt: menu.UpdatedAt, ID: menu.ID, MenuID: menu.MenuID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: dto.MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: buttons}
|
||||
}
|
||||
|
||||
func dynamicMenuResponse(menu *biz.Menu) *DynamicMenuResponse {
|
||||
var children []*DynamicMenuResponse
|
||||
func dynamicMenuResponse(menu *biz.Menu) *dto.DynamicMenuResponse {
|
||||
var children []*dto.DynamicMenuResponse
|
||||
if menu.Children != nil {
|
||||
children = make([]*DynamicMenuResponse, 0, len(menu.Children))
|
||||
children = make([]*dto.DynamicMenuResponse, 0, len(menu.Children))
|
||||
for _, child := range menu.Children {
|
||||
children = append(children, dynamicMenuResponse(child))
|
||||
}
|
||||
}
|
||||
var parameters []MenuParameterResponse
|
||||
var parameters []dto.MenuParameterResponse
|
||||
if menu.Parameters != nil {
|
||||
parameters = make([]MenuParameterResponse, 0, len(menu.Parameters))
|
||||
parameters = make([]dto.MenuParameterResponse, 0, len(menu.Parameters))
|
||||
for _, parameter := range menu.Parameters {
|
||||
parameters = append(parameters, MenuParameterResponse{CreatedAt: parameter.CreatedAt, UpdatedAt: parameter.UpdatedAt, ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
|
||||
parameters = append(parameters, dto.MenuParameterResponse{CreatedAt: parameter.CreatedAt, UpdatedAt: parameter.UpdatedAt, ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
|
||||
}
|
||||
}
|
||||
var buttonAuthorities map[string]uint
|
||||
@@ -136,22 +137,22 @@ func dynamicMenuResponse(menu *biz.Menu) *DynamicMenuResponse {
|
||||
}
|
||||
buttonAuthorities[button.Name] = button.AuthorityID
|
||||
}
|
||||
return &DynamicMenuResponse{CreatedAt: menu.CreatedAt, UpdatedAt: menu.UpdatedAt, ID: menu.ID, MenuID: menu.MenuID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: nil, Buttons: buttonAuthorities}
|
||||
return &dto.DynamicMenuResponse{CreatedAt: menu.CreatedAt, UpdatedAt: menu.UpdatedAt, ID: menu.ID, MenuID: menu.MenuID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: dto.MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: nil, Buttons: buttonAuthorities}
|
||||
}
|
||||
|
||||
func menuResponses(items []*biz.Menu) []*MenuResponse {
|
||||
func menuResponses(items []*biz.Menu) []*dto.MenuResponse {
|
||||
if items == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]*MenuResponse, 0, len(items))
|
||||
out := make([]*dto.MenuResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, menuResponse(item))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func dynamicMenuResponses(items []*biz.Menu) []*DynamicMenuResponse {
|
||||
out := make([]*DynamicMenuResponse, 0, len(items))
|
||||
func dynamicMenuResponses(items []*biz.Menu) []*dto.DynamicMenuResponse {
|
||||
out := make([]*dto.DynamicMenuResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, dynamicMenuResponse(item))
|
||||
}
|
||||
|
||||
@@ -6,19 +6,20 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func TestMenuDomainPreservesRelationIdentity(t *testing.T) {
|
||||
createdAt := time.Date(2025, time.March, 4, 5, 6, 7, 0, time.UTC)
|
||||
updatedAt := time.Date(2025, time.April, 5, 6, 7, 8, 0, time.UTC)
|
||||
menu := menuDomain(&MenuRequest{
|
||||
menu := menuDomain(&dto.MenuRequest{
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
ID: 10,
|
||||
MenuButtons: []MenuButtonRequest{{
|
||||
MenuButtons: []dto.MenuButtonRequest{{
|
||||
CreatedAt: createdAt, UpdatedAt: updatedAt, ID: 31, Name: "edit", Description: "编辑",
|
||||
}},
|
||||
Parameters: []MenuParameterRequest{{
|
||||
Parameters: []dto.MenuParameterRequest{{
|
||||
CreatedAt: createdAt, UpdatedAt: updatedAt, ID: 21, Type: "query", Key: "id", Value: "1",
|
||||
}},
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type ParameterService struct{ uc *biz.ParameterUsecase }
|
||||
@@ -13,40 +14,40 @@ func NewParameterService(uc *biz.ParameterUsecase) *ParameterService {
|
||||
return &ParameterService{uc: uc}
|
||||
}
|
||||
|
||||
func parameterDomain(value *SystemParameterRequest) *biz.SystemParameter {
|
||||
func parameterDomain(value *dto.SystemParameterRequest) *biz.SystemParameter {
|
||||
return &biz.SystemParameter{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, Name: value.Name, Key: value.Key, Value: value.Value, Desc: value.Description}
|
||||
}
|
||||
func (s *ParameterService) CreateParameterRequest(ctx context.Context, req *SystemParameterRequest) error {
|
||||
func (s *ParameterService) CreateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
|
||||
return s.CreateParameter(ctx, parameterDomain(req))
|
||||
}
|
||||
func (s *ParameterService) UpdateParameterRequest(ctx context.Context, req *SystemParameterRequest) error {
|
||||
func (s *ParameterService) UpdateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
|
||||
return s.UpdateParameter(ctx, parameterDomain(req))
|
||||
}
|
||||
func (s *ParameterService) ParametersFilter(ctx context.Context, page, size int, name, key string, start, end *time.Time) ([]*SystemParameterResponse, int64, error) {
|
||||
func (s *ParameterService) ParametersFilter(ctx context.Context, page, size int, name, key string, start, end *time.Time) ([]*dto.SystemParameterResponse, int64, error) {
|
||||
return s.Parameters(ctx, page, size, &biz.SystemParameter{Name: name, Key: key, StartCreatedAt: start, EndCreatedAt: end})
|
||||
}
|
||||
func parameterDTO(v *biz.SystemParameter) *SystemParameterResponse {
|
||||
return &SystemParameterResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Key: v.Key, Value: v.Value, Desc: v.Desc}
|
||||
func parameterDTO(v *biz.SystemParameter) *dto.SystemParameterResponse {
|
||||
return &dto.SystemParameterResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Key: v.Key, Value: v.Value, Desc: v.Desc}
|
||||
}
|
||||
func (s *ParameterService) Parameters(ctx context.Context, page, size int, q *biz.SystemParameter) ([]*SystemParameterResponse, int64, error) {
|
||||
func (s *ParameterService) Parameters(ctx context.Context, page, size int, q *biz.SystemParameter) ([]*dto.SystemParameterResponse, int64, error) {
|
||||
items, total, err := s.uc.ListParameters(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*SystemParameterResponse, 0, len(items))
|
||||
out := make([]*dto.SystemParameterResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, parameterDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *ParameterService) ParameterByID(ctx context.Context, id string) (*SystemParameterResponse, error) {
|
||||
func (s *ParameterService) ParameterByID(ctx context.Context, id string) (*dto.SystemParameterResponse, error) {
|
||||
v, err := s.uc.FindParameterByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parameterDTO(v), nil
|
||||
}
|
||||
func (s *ParameterService) ParameterByKey(ctx context.Context, key string) (*SystemParameterResponse, error) {
|
||||
func (s *ParameterService) ParameterByKey(ctx context.Context, key string) (*dto.SystemParameterResponse, error) {
|
||||
v, err := s.uc.FindParameterByKey(ctx, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+20
-19
@@ -5,17 +5,18 @@ import (
|
||||
"errors"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type PaymentService struct{ uc *biz.PaymentUsecase }
|
||||
|
||||
func NewPaymentService(uc *biz.PaymentUsecase) *PaymentService { return &PaymentService{uc: uc} }
|
||||
func (s *PaymentService) Order(ctx context.Context, provider, tradeNo string) (*PaymentOrderResponse, error) {
|
||||
func (s *PaymentService) Order(ctx context.Context, provider, tradeNo string) (*dto.PaymentOrderResponse, error) {
|
||||
order, err := s.uc.Order(ctx, provider, tradeNo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &PaymentOrderResponse{
|
||||
return &dto.PaymentOrderResponse{
|
||||
ID: order.ID,
|
||||
Provider: order.Provider, TradeNo: order.TradeNo, ProviderTradeNo: order.ProviderTradeNo,
|
||||
BusinessType: order.BusinessType, BusinessID: order.BusinessID, Subject: order.Subject,
|
||||
@@ -32,7 +33,7 @@ func (s *PaymentService) Order(ctx context.Context, provider, tradeNo string) (*
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *PaymentService) Orders(ctx context.Context, req *PaymentOrderListRequest) ([]*PaymentOrderResponse, int64, int, int, error) {
|
||||
func (s *PaymentService) Orders(ctx context.Context, req *dto.PaymentOrderListRequest) ([]*dto.PaymentOrderResponse, int64, int, int, error) {
|
||||
if req == nil {
|
||||
return nil, 0, 1, 10, errors.New("支付订单列表请求为空")
|
||||
}
|
||||
@@ -50,7 +51,7 @@ func (s *PaymentService) Orders(ctx context.Context, req *PaymentOrderListReques
|
||||
if err != nil {
|
||||
return nil, 0, page, pageSize, err
|
||||
}
|
||||
result := make([]*PaymentOrderResponse, 0, len(items))
|
||||
result := make([]*dto.PaymentOrderResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
converted, convertErr := paymentOrderResponse(item)
|
||||
if convertErr != nil {
|
||||
@@ -61,11 +62,11 @@ func (s *PaymentService) Orders(ctx context.Context, req *PaymentOrderListReques
|
||||
return result, total, page, pageSize, nil
|
||||
}
|
||||
|
||||
func paymentOrderResponse(order *biz.PaymentOrder) (*PaymentOrderResponse, error) {
|
||||
func paymentOrderResponse(order *biz.PaymentOrder) (*dto.PaymentOrderResponse, error) {
|
||||
if order == nil {
|
||||
return nil, errors.New("支付订单为空")
|
||||
}
|
||||
return &PaymentOrderResponse{
|
||||
return &dto.PaymentOrderResponse{
|
||||
ID: order.ID, Provider: order.Provider, TradeNo: order.TradeNo, ProviderTradeNo: order.ProviderTradeNo,
|
||||
BusinessType: order.BusinessType, BusinessID: order.BusinessID, Subject: order.Subject,
|
||||
PaymentMode: order.PaymentMode, OriginalAmount: order.OriginalAmount, Amount: order.Amount, PaidAmount: order.PaidAmount,
|
||||
@@ -79,7 +80,7 @@ func paymentOrderResponse(order *biz.PaymentOrder) (*PaymentOrderResponse, error
|
||||
PaidAt: order.PaidAt, FulfilledAt: order.FulfilledAt, RefundedAt: order.RefundedAt,
|
||||
}, nil
|
||||
}
|
||||
func (s *PaymentService) Create(ctx context.Context, req *PaymentRequest) (*PaymentResultResponse, error) {
|
||||
func (s *PaymentService) Create(ctx context.Context, req *dto.PaymentRequest) (*dto.PaymentResultResponse, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("支付请求为空")
|
||||
}
|
||||
@@ -92,14 +93,14 @@ func (s *PaymentService) Create(ctx context.Context, req *PaymentRequest) (*Paym
|
||||
})
|
||||
return paymentResultResponse(result), err
|
||||
}
|
||||
func (s *PaymentService) Query(ctx context.Context, req *PaymentQueryRequest) (*PaymentResultResponse, error) {
|
||||
func (s *PaymentService) Query(ctx context.Context, req *dto.PaymentQueryRequest) (*dto.PaymentResultResponse, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("支付查询请求为空")
|
||||
}
|
||||
result, err := s.uc.Query(ctx, req.Provider, req.TradeNo)
|
||||
return paymentResultResponse(result), err
|
||||
}
|
||||
func (s *PaymentService) Refund(ctx context.Context, req *PaymentRefundRequest) (*PaymentResultResponse, error) {
|
||||
func (s *PaymentService) Refund(ctx context.Context, req *dto.PaymentRefundRequest) (*dto.PaymentResultResponse, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("支付退款请求为空")
|
||||
}
|
||||
@@ -107,27 +108,27 @@ func (s *PaymentService) Refund(ctx context.Context, req *PaymentRefundRequest)
|
||||
return paymentResultResponse(result), err
|
||||
}
|
||||
|
||||
func (s *PaymentService) TestProvider(ctx context.Context, provider string) (*PaymentTestResult, error) {
|
||||
func (s *PaymentService) TestProvider(ctx context.Context, provider string) (*dto.PaymentTestResult, error) {
|
||||
result, err := s.uc.TestProvider(ctx, provider)
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
response := &PaymentTestResult{Provider: result.Provider, TradeNo: result.TradeNo, Passed: result.Passed, FullFlow: result.FullFlow, Mode: result.Mode, Stages: make([]*PaymentTestStage, 0, len(result.Stages))}
|
||||
response := &dto.PaymentTestResult{Provider: result.Provider, TradeNo: result.TradeNo, Passed: result.Passed, FullFlow: result.FullFlow, Mode: result.Mode, Stages: make([]*dto.PaymentTestStage, 0, len(result.Stages))}
|
||||
for _, stage := range result.Stages {
|
||||
response.Stages = append(response.Stages, &PaymentTestStage{Name: stage.Name, Status: stage.Status, Message: stage.Message, TradeNo: stage.TradeNo, Duration: stage.Duration})
|
||||
response.Stages = append(response.Stages, &dto.PaymentTestStage{Name: stage.Name, Status: stage.Status, Message: stage.Message, TradeNo: stage.TradeNo, Duration: stage.Duration})
|
||||
}
|
||||
response.Result = paymentResultResponse(result.Result)
|
||||
return response, err
|
||||
}
|
||||
|
||||
func (s *PaymentService) Fulfill(ctx context.Context, req *PaymentFulfillRequest) (*PaymentResultResponse, error) {
|
||||
func (s *PaymentService) Fulfill(ctx context.Context, req *dto.PaymentFulfillRequest) (*dto.PaymentResultResponse, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New("支付发货请求为空")
|
||||
}
|
||||
result, err := s.uc.Fulfill(ctx, req.Provider, req.TradeNo)
|
||||
return paymentResultResponse(result), err
|
||||
}
|
||||
func (s *PaymentService) Callback(ctx context.Context, req *PaymentCallbackRequest) (PaymentCallbackAck, error) {
|
||||
func (s *PaymentService) Callback(ctx context.Context, req *dto.PaymentCallbackRequest) (dto.PaymentCallbackAck, error) {
|
||||
if req == nil {
|
||||
return paymentCallbackAckResponse(biz.DefaultPaymentCallbackAck("", false)), errors.New("支付回调请求为空")
|
||||
}
|
||||
@@ -142,15 +143,15 @@ func (s *PaymentService) Callback(ctx context.Context, req *PaymentCallbackReque
|
||||
return paymentCallbackAckResponse(ack), nil
|
||||
}
|
||||
|
||||
func DefaultPaymentCallbackAck(provider string, success bool) PaymentCallbackAck {
|
||||
func DefaultPaymentCallbackAck(provider string, success bool) dto.PaymentCallbackAck {
|
||||
return paymentCallbackAckResponse(biz.DefaultPaymentCallbackAck(provider, success))
|
||||
}
|
||||
|
||||
func paymentResultResponse(result *biz.PaymentResult) *PaymentResultResponse {
|
||||
func paymentResultResponse(result *biz.PaymentResult) *dto.PaymentResultResponse {
|
||||
if result == nil {
|
||||
return nil
|
||||
}
|
||||
return &PaymentResultResponse{
|
||||
return &dto.PaymentResultResponse{
|
||||
Provider: result.Provider, Status: result.Status, TradeNo: result.TradeNo,
|
||||
ProviderTradeNo: result.ProviderTradeNo, Amount: result.Amount,
|
||||
PayerPaidAmount: result.PayerPaidAmount, CashPaidAmount: result.CashPaidAmount,
|
||||
@@ -164,6 +165,6 @@ func paymentResultResponse(result *biz.PaymentResult) *PaymentResultResponse {
|
||||
}
|
||||
}
|
||||
|
||||
func paymentCallbackAckResponse(ack biz.PaymentCallbackAck) PaymentCallbackAck {
|
||||
return PaymentCallbackAck{StatusCode: ack.StatusCode, ContentType: ack.ContentType, Body: ack.Body}
|
||||
func paymentCallbackAckResponse(ack biz.PaymentCallbackAck) dto.PaymentCallbackAck {
|
||||
return dto.PaymentCallbackAck{StatusCode: ack.StatusCode, ContentType: ack.ContentType, Body: ack.Body}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type PositionService struct{ uc *biz.PositionUsecase }
|
||||
@@ -12,31 +13,31 @@ func NewPositionService(uc *biz.PositionUsecase) *PositionService {
|
||||
return &PositionService{uc: uc}
|
||||
}
|
||||
|
||||
func positionDomain(value *PositionRequest) *biz.Position {
|
||||
func positionDomain(value *dto.PositionRequest) *biz.Position {
|
||||
return &biz.Position{ID: value.ID, Name: value.Name, Code: value.Code, Sort: value.Sort, Status: value.Status, Remark: value.Remark}
|
||||
}
|
||||
|
||||
func positionResponse(value *biz.Position) *PositionResponse {
|
||||
return &PositionResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, Code: value.Code, Sort: value.Sort, Status: value.Status, Remark: value.Remark}
|
||||
func positionResponse(value *biz.Position) *dto.PositionResponse {
|
||||
return &dto.PositionResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, Code: value.Code, Sort: value.Sort, Status: value.Status, Remark: value.Remark}
|
||||
}
|
||||
|
||||
func (s *PositionService) Positions(ctx context.Context, req *PositionListRequest) ([]*PositionResponse, int64, error) {
|
||||
func (s *PositionService) Positions(ctx context.Context, req *dto.PositionListRequest) ([]*dto.PositionResponse, int64, error) {
|
||||
items, total, err := s.uc.Positions(ctx, req.Page, req.PageSize, &biz.PositionListFilter{Name: req.Name, Code: req.Code, Status: req.Status})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*PositionResponse, 0, len(items))
|
||||
out := make([]*dto.PositionResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
out = append(out, positionResponse(item))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
|
||||
func (s *PositionService) Create(ctx context.Context, req *PositionRequest) error {
|
||||
func (s *PositionService) Create(ctx context.Context, req *dto.PositionRequest) error {
|
||||
return s.uc.CreatePosition(ctx, positionDomain(req))
|
||||
}
|
||||
|
||||
func (s *PositionService) Update(ctx context.Context, req *PositionRequest) error {
|
||||
func (s *PositionService) Update(ctx context.Context, req *dto.PositionRequest) error {
|
||||
return s.uc.UpdatePosition(ctx, positionDomain(req))
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ func (s *PositionService) Delete(ctx context.Context, id uint) error {
|
||||
return s.uc.DeletePosition(ctx, id)
|
||||
}
|
||||
|
||||
func (s *PositionService) Position(ctx context.Context, id uint) (*PositionResponse, error) {
|
||||
func (s *PositionService) Position(ctx context.Context, id uint) (*dto.PositionResponse, error) {
|
||||
value, err := s.uc.Position(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -56,10 +57,10 @@ func (s *PositionService) UserIDs(ctx context.Context, id uint) ([]uint, error)
|
||||
return s.uc.PositionUserIDs(ctx, id)
|
||||
}
|
||||
|
||||
func (s *PositionService) SetUsers(ctx context.Context, req *SetPositionUsersRequest) error {
|
||||
func (s *PositionService) SetUsers(ctx context.Context, req *dto.SetPositionUsersRequest) error {
|
||||
return s.uc.SetPositionUsers(ctx, req.PositionID, req.UserIDs)
|
||||
}
|
||||
|
||||
func (s *PositionService) SetUserPositions(ctx context.Context, req *SetUserPositionsRequest) error {
|
||||
func (s *PositionService) SetUserPositions(ctx context.Context, req *dto.SetUserPositionsRequest) error {
|
||||
return s.uc.SetUserPositions(ctx, req.ID, req.PositionIDs)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type PasswordPolicyError struct{ Err error }
|
||||
@@ -17,26 +18,26 @@ func IsPasswordPolicyError(err error) bool {
|
||||
return errors.As(err, &policyErr)
|
||||
}
|
||||
|
||||
func securityDTO(v *biz.SecurityConfig) *SecurityConfigResponse {
|
||||
return &SecurityConfigResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, CaptchaOpen: v.CaptchaOpen, CaptchaTimeout: v.CaptchaTimeout, KeyLong: v.KeyLong, ImgWidth: v.ImgWidth, ImgHeight: v.ImgHeight, PwdMinLength: v.PwdMinLength, PwdRequireUpper: v.PwdRequireUpper, PwdRequireLower: v.PwdRequireLower, PwdRequireDigit: v.PwdRequireDigit, PwdRequireSpecial: v.PwdRequireSpecial, LimitEnable: v.LimitEnable, LimitWindow: v.LimitWindow, LimitCount: v.LimitCount, LockEnable: v.LockEnable, LockThreshold: v.LockThreshold, LockDuration: v.LockDuration, PwdExpireEnable: v.PwdExpireEnable, PwdExpireDays: v.PwdExpireDays, ForceNewUserChangePassword: v.ForceNewUserChangePassword}
|
||||
func securityDTO(v *biz.SecurityConfig) *dto.SecurityConfigResponse {
|
||||
return &dto.SecurityConfigResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, CaptchaOpen: v.CaptchaOpen, CaptchaTimeout: v.CaptchaTimeout, KeyLong: v.KeyLong, ImgWidth: v.ImgWidth, ImgHeight: v.ImgHeight, PwdMinLength: v.PwdMinLength, PwdRequireUpper: v.PwdRequireUpper, PwdRequireLower: v.PwdRequireLower, PwdRequireDigit: v.PwdRequireDigit, PwdRequireSpecial: v.PwdRequireSpecial, LimitEnable: v.LimitEnable, LimitWindow: v.LimitWindow, LimitCount: v.LimitCount, LockEnable: v.LockEnable, LockThreshold: v.LockThreshold, LockDuration: v.LockDuration, PwdExpireEnable: v.PwdExpireEnable, PwdExpireDays: v.PwdExpireDays, ForceNewUserChangePassword: v.ForceNewUserChangePassword}
|
||||
}
|
||||
func (s *SecurityService) CurrentSecurity(ctx context.Context) (*biz.SecurityConfig, error) {
|
||||
return s.uc.Current(ctx)
|
||||
}
|
||||
func (s *SecurityService) Security(ctx context.Context) (*SecurityConfigResponse, error) {
|
||||
func (s *SecurityService) Security(ctx context.Context) (*dto.SecurityConfigResponse, error) {
|
||||
value, err := s.uc.Security(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return securityDTO(value), nil
|
||||
}
|
||||
func (s *SecurityService) SaveSecurity(ctx context.Context, value *biz.SecurityConfig) (*SecurityConfigResponse, error) {
|
||||
func (s *SecurityService) SaveSecurity(ctx context.Context, value *biz.SecurityConfig) (*dto.SecurityConfigResponse, error) {
|
||||
if err := s.uc.UpdateSecurity(ctx, value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return securityDTO(value), nil
|
||||
}
|
||||
func (s *SecurityService) SaveSecurityRequest(ctx context.Context, value *SecurityConfigRequest) (*SecurityConfigResponse, error) {
|
||||
func (s *SecurityService) SaveSecurityRequest(ctx context.Context, value *dto.SecurityConfigRequest) (*dto.SecurityConfigResponse, error) {
|
||||
return s.SaveSecurity(ctx, &biz.SecurityConfig{
|
||||
ID: value.ID, CaptchaOpen: value.CaptchaOpen, CaptchaTimeout: value.CaptchaTimeout,
|
||||
KeyLong: value.KeyLong, ImgWidth: value.ImgWidth, ImgHeight: value.ImgHeight,
|
||||
|
||||
@@ -3,6 +3,8 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func (s *SystemConfigService) PersistConfig(ctx context.Context) error {
|
||||
@@ -19,6 +21,6 @@ func (s *SystemConfigService) SystemConfig() (json.RawMessage, error) {
|
||||
return s.uc.ConfigurationJSON()
|
||||
}
|
||||
|
||||
func (s *SystemConfigService) SaveSystemConfig(ctx context.Context, req *SetSystemConfigRequest) error {
|
||||
func (s *SystemConfigService) SaveSystemConfig(ctx context.Context, req *dto.SetSystemConfigRequest) error {
|
||||
return s.uc.SaveConfigurationJSON(ctx, req.Config)
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/shirou/gopsutil/v4/cpu"
|
||||
"github.com/shirou/gopsutil/v4/disk"
|
||||
"github.com/shirou/gopsutil/v4/mem"
|
||||
)
|
||||
|
||||
func (s *SystemConfigService) ServerInfo() (*ServerInfoResponse, error) {
|
||||
func (s *SystemConfigService) ServerInfo() (*dto.ServerInfoResponse, error) {
|
||||
physicalCores, err := cpu.Counts(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -22,19 +24,19 @@ func (s *SystemConfigService) ServerInfo() (*ServerInfoResponse, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
diskInfo := make([]ServerDiskResponse, 0)
|
||||
diskInfo := make([]dto.ServerDiskResponse, 0)
|
||||
for _, mountPoint := range s.DiskMountPoints() {
|
||||
usage, usageErr := disk.Usage(mountPoint)
|
||||
if usageErr != nil {
|
||||
return nil, usageErr
|
||||
}
|
||||
diskInfo = append(diskInfo, ServerDiskResponse{MountPoint: mountPoint, UsedMB: usage.Used / 1024 / 1024, UsedGB: usage.Used / 1024 / 1024 / 1024, TotalMB: usage.Total / 1024 / 1024, TotalGB: usage.Total / 1024 / 1024 / 1024, UsedPercent: int(usage.UsedPercent)})
|
||||
diskInfo = append(diskInfo, dto.ServerDiskResponse{MountPoint: mountPoint, UsedMB: usage.Used / 1024 / 1024, UsedGB: usage.Used / 1024 / 1024 / 1024, TotalMB: usage.Total / 1024 / 1024, TotalGB: usage.Total / 1024 / 1024 / 1024, UsedPercent: int(usage.UsedPercent)})
|
||||
}
|
||||
usedMB, totalMB := memory.Used/1024/1024, memory.Total/1024/1024
|
||||
return &ServerInfoResponse{
|
||||
OS: ServerOSResponse{GOOS: runtime.GOOS, NumCPU: runtime.NumCPU(), Compiler: runtime.Compiler, GoVersion: runtime.Version(), NumGoroutine: runtime.NumGoroutine()},
|
||||
CPU: ServerCPUResponse{CPUs: cpuPercent, Cores: physicalCores},
|
||||
RAM: ServerRAMResponse{UsedMB: usedMB, TotalMB: totalMB, UsedPercent: int(memory.UsedPercent)},
|
||||
return &dto.ServerInfoResponse{
|
||||
OS: dto.ServerOSResponse{GOOS: runtime.GOOS, NumCPU: runtime.NumCPU(), Compiler: runtime.Compiler, GoVersion: runtime.Version(), NumGoroutine: runtime.NumGoroutine()},
|
||||
CPU: dto.ServerCPUResponse{CPUs: cpuPercent, Cores: physicalCores},
|
||||
RAM: dto.ServerRAMResponse{UsedMB: usedMB, TotalMB: totalMB, UsedPercent: int(memory.UsedPercent)},
|
||||
Disk: diskInfo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func (s *SystemConfigService) Initialize(ctx context.Context, input *DatabaseInitRequest, apis []*biz.API) error {
|
||||
func (s *SystemConfigService) Initialize(ctx context.Context, input *dto.DatabaseInitRequest, apis []*biz.API) error {
|
||||
driver, config := input.DBType, ""
|
||||
switch driver {
|
||||
case "mysql":
|
||||
@@ -23,7 +24,7 @@ func (s *SystemConfigService) Initialize(ctx context.Context, input *DatabaseIni
|
||||
return s.uc.Initialize(ctx, &biz.DatabaseConfig{Driver: driver, Host: input.Host, Port: input.Port, User: input.UserName, Password: input.Password, Name: input.DBName, Path: input.DBPath, Config: config, Template: input.Template, AdminPassword: input.AdminPassword, APIs: apis})
|
||||
}
|
||||
|
||||
func (s *SystemConfigService) InitializeRoutes(ctx context.Context, input *DatabaseInitRequest, routes []Route) error {
|
||||
func (s *SystemConfigService) InitializeRoutes(ctx context.Context, input *dto.DatabaseInitRequest, routes []dto.Route) error {
|
||||
apis := make([]*biz.API, 0, len(routes))
|
||||
for _, route := range routes {
|
||||
path := NormalizeRoutePath(route.Path, s.settings.RouterPrefix())
|
||||
|
||||
+15
-14
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type TaskService struct {
|
||||
@@ -15,20 +16,20 @@ type TaskService struct {
|
||||
func NewTaskService(uc *biz.TaskApplicationUsecase) *TaskService {
|
||||
return &TaskService{uc: uc}
|
||||
}
|
||||
func taskDomain(v *TaskRequest) *biz.TimedTask {
|
||||
func taskDomain(v *dto.TaskRequest) *biz.TimedTask {
|
||||
return &biz.TimedTask{ID: v.ID, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: v.Params, HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: v.HTTPHeader, HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled}
|
||||
}
|
||||
func (s *TaskService) CreateRequest(ctx context.Context, req *TaskRequest) (uint, error) {
|
||||
func (s *TaskService) CreateRequest(ctx context.Context, req *dto.TaskRequest) (uint, error) {
|
||||
value := taskDomain(req)
|
||||
if err := s.Create(ctx, value); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return value.ID, nil
|
||||
}
|
||||
func (s *TaskService) UpdateRequest(ctx context.Context, req *TaskRequest) error {
|
||||
func (s *TaskService) UpdateRequest(ctx context.Context, req *dto.TaskRequest) error {
|
||||
return s.Update(ctx, taskDomain(req))
|
||||
}
|
||||
func (s *TaskService) ListRequest(ctx context.Context, page, size int, name, executorType string, enabled *bool) ([]*TaskResponse, int64, error) {
|
||||
func (s *TaskService) ListRequest(ctx context.Context, page, size int, name, executorType string, enabled *bool) ([]*dto.TaskResponse, int64, error) {
|
||||
return s.Tasks(ctx, page, size, &biz.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled})
|
||||
}
|
||||
func (s *TaskService) Create(ctx context.Context, v *biz.TimedTask) error {
|
||||
@@ -43,15 +44,15 @@ func (s *TaskService) Delete(ctx context.Context, id uint) error {
|
||||
func (s *TaskService) Toggle(ctx context.Context, id uint, enabled bool) error {
|
||||
return s.uc.Toggle(ctx, id, enabled)
|
||||
}
|
||||
func taskDTO(v *biz.TimedTask, next *time.Time) *TaskResponse {
|
||||
return &TaskResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: json.RawMessage(v.Params), HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: json.RawMessage(v.HTTPHeader), HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled, NextRunAt: next}
|
||||
func taskDTO(v *biz.TimedTask, next *time.Time) *dto.TaskResponse {
|
||||
return &dto.TaskResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: json.RawMessage(v.Params), HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: json.RawMessage(v.HTTPHeader), HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled, NextRunAt: next}
|
||||
}
|
||||
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTask) ([]*TaskResponse, int64, error) {
|
||||
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTask) ([]*dto.TaskResponse, int64, error) {
|
||||
items, total, next, err := s.uc.List(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*TaskResponse, 0, len(items))
|
||||
out := make([]*dto.TaskResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
var ptr *time.Time
|
||||
if value, ok := next[v.ID]; ok {
|
||||
@@ -63,14 +64,14 @@ func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTas
|
||||
return out, total, nil
|
||||
}
|
||||
|
||||
func (s *TaskService) Logs(ctx context.Context, page, size int, taskID uint, status string) ([]*TaskLogResponse, int64, error) {
|
||||
func (s *TaskService) Logs(ctx context.Context, page, size int, taskID uint, status string) ([]*dto.TaskLogResponse, int64, error) {
|
||||
items, total, err := s.uc.Logs(ctx, page, size, taskID, status)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*TaskLogResponse, 0, len(items))
|
||||
out := make([]*dto.TaskLogResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, &TaskLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, TaskID: v.TaskID, TaskName: v.TaskName, TriggerType: v.TriggerType, StartedAt: v.StartedAt, FinishedAt: v.FinishedAt, DurationMS: v.DurationMS, Status: v.Status, ErrorMsg: v.ErrorMsg, Output: v.Output})
|
||||
out = append(out, &dto.TaskLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, TaskID: v.TaskID, TaskName: v.TaskName, TriggerType: v.TriggerType, StartedAt: v.StartedAt, FinishedAt: v.FinishedAt, DurationMS: v.DurationMS, Status: v.Status, ErrorMsg: v.ErrorMsg, Output: v.Output})
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
@@ -80,11 +81,11 @@ func (s *TaskService) Reload(ctx context.Context) error { return s.uc
|
||||
func (s *TaskService) Subscribe(userID uint) chan []byte { return s.uc.Subscribe(userID) }
|
||||
func (s *TaskService) Unsubscribe(userID uint, events chan []byte) { s.uc.Unsubscribe(userID, events) }
|
||||
|
||||
func (s *TaskService) RegisteredMethods() []*TaskMethodResponse {
|
||||
func (s *TaskService) RegisteredMethods() []*dto.TaskMethodResponse {
|
||||
methods := s.uc.RegisteredMethods()
|
||||
out := make([]*TaskMethodResponse, 0, len(methods))
|
||||
out := make([]*dto.TaskMethodResponse, 0, len(methods))
|
||||
for _, method := range methods {
|
||||
out = append(out, &TaskMethodResponse{Name: method.Name, Description: method.Description})
|
||||
out = append(out, &dto.TaskMethodResponse{Name: method.Name, Description: method.Description})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
+14
-13
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type userInput struct {
|
||||
@@ -23,23 +24,23 @@ func NewUserService(uc *biz.UserUsecase, settings *SecurityService) *UserService
|
||||
return &UserService{uc: uc, settings: settings}
|
||||
}
|
||||
|
||||
func userRequestInput(value *UserRequest) userInput {
|
||||
func userRequestInput(value *dto.UserRequest) userInput {
|
||||
return userInput{ID: value.ID, Username: value.Username, Password: value.Password, NickName: value.NickName, HeaderImg: value.HeaderImg, AuthorityID: value.AuthorityID, AuthorityIDs: value.AuthorityIDs, Enable: value.Enable, Phone: value.Phone, Email: value.Email}
|
||||
}
|
||||
func (s *UserService) ListUsersRequest(ctx context.Context, value *UserListRequest) ([]*UserResponse, int64, error) {
|
||||
func (s *UserService) ListUsersRequest(ctx context.Context, value *dto.UserListRequest) ([]*dto.UserResponse, int64, error) {
|
||||
return s.ListUsers(ctx, value.Page, value.PageSize, &biz.UserListFilter{Username: value.Username, NickName: value.NickName, Phone: value.Phone, Email: value.Email, OrderKey: value.OrderKey, Desc: value.Desc})
|
||||
}
|
||||
func (s *UserService) CreateUserRequest(ctx context.Context, value *UserRequest) (*UserResponse, error) {
|
||||
func (s *UserService) CreateUserRequest(ctx context.Context, value *dto.UserRequest) (*dto.UserResponse, error) {
|
||||
return s.createUser(ctx, userRequestInput(value))
|
||||
}
|
||||
func (s *UserService) UpdateUserRequest(ctx context.Context, value *UserRequest) error {
|
||||
func (s *UserService) UpdateUserRequest(ctx context.Context, value *dto.UserRequest) error {
|
||||
return s.updateUser(ctx, userRequestInput(value))
|
||||
}
|
||||
func (s *UserService) UpdateSelfUserRequest(ctx context.Context, id uint, value *SelfUserRequest) error {
|
||||
func (s *UserService) UpdateSelfUserRequest(ctx context.Context, id uint, value *dto.SelfUserRequest) error {
|
||||
return s.updateSelfUser(ctx, userInput{ID: id, NickName: value.NickName, HeaderImg: value.HeaderImg, Phone: value.Phone, Email: value.Email, Enable: value.Enable})
|
||||
}
|
||||
|
||||
func (s *UserService) User(ctx context.Context, id uint) (*UserResponse, error) {
|
||||
func (s *UserService) User(ctx context.Context, id uint) (*dto.UserResponse, error) {
|
||||
value, err := s.uc.User(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -47,7 +48,7 @@ func (s *UserService) User(ctx context.Context, id uint) (*UserResponse, error)
|
||||
return convertUser(value), nil
|
||||
}
|
||||
|
||||
func (s *UserService) UserByUUID(ctx context.Context, uuid string) (*UserResponse, error) {
|
||||
func (s *UserService) UserByUUID(ctx context.Context, uuid string) (*dto.UserResponse, error) {
|
||||
value, err := s.uc.UserByUUID(ctx, uuid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -55,7 +56,7 @@ func (s *UserService) UserByUUID(ctx context.Context, uuid string) (*UserRespons
|
||||
return convertUser(value), nil
|
||||
}
|
||||
|
||||
func (s *UserService) Menus(ctx context.Context, authorityID uint) ([]*DynamicMenuResponse, error) {
|
||||
func (s *UserService) Menus(ctx context.Context, authorityID uint) ([]*dto.DynamicMenuResponse, error) {
|
||||
menus, err := s.uc.Menus(ctx, authorityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -63,31 +64,31 @@ func (s *UserService) Menus(ctx context.Context, authorityID uint) ([]*DynamicMe
|
||||
return dynamicMenuResponses(menus), nil
|
||||
}
|
||||
|
||||
func (s *UserService) ListUsers(ctx context.Context, page, pageSize int, filter *biz.UserListFilter) ([]*UserResponse, int64, error) {
|
||||
func (s *UserService) ListUsers(ctx context.Context, page, pageSize int, filter *biz.UserListFilter) ([]*dto.UserResponse, int64, error) {
|
||||
users, total, err := s.uc.ListUsers(ctx, page, pageSize, filter)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
result := make([]*UserResponse, 0, len(users))
|
||||
result := make([]*dto.UserResponse, 0, len(users))
|
||||
for _, user := range users {
|
||||
result = append(result, convertUser(user))
|
||||
}
|
||||
return result, total, nil
|
||||
}
|
||||
|
||||
func (s *UserService) Authorities(ctx context.Context) ([]*AuthorityResponse, error) {
|
||||
func (s *UserService) Authorities(ctx context.Context) ([]*dto.AuthorityResponse, error) {
|
||||
values, err := s.uc.Authorities(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*AuthorityResponse, 0, len(values))
|
||||
result := make([]*dto.AuthorityResponse, 0, len(values))
|
||||
for _, value := range values {
|
||||
result = append(result, convertAuthority(*value))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *UserService) createUser(ctx context.Context, input userInput) (*UserResponse, error) {
|
||||
func (s *UserService) createUser(ctx context.Context, input userInput) (*dto.UserResponse, error) {
|
||||
if err := s.settings.ValidatePassword(ctx, input.Password); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,42 +2,43 @@ package service
|
||||
|
||||
import (
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
func convertAuthority(value biz.Authority) *AuthorityResponse {
|
||||
var menus []*MenuResponse
|
||||
func convertAuthority(value biz.Authority) *dto.AuthorityResponse {
|
||||
var menus []*dto.MenuResponse
|
||||
if value.Menus != nil {
|
||||
menus = menuResponses(value.Menus)
|
||||
}
|
||||
return &AuthorityResponse{CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: value.DeletedAt, AuthorityID: value.AuthorityID, AuthorityName: value.AuthorityName, ParentID: value.ParentID, Children: nil, Menus: menus, DataScope: value.DataScope, DefaultRouter: value.DefaultRouter}
|
||||
return &dto.AuthorityResponse{CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: value.DeletedAt, AuthorityID: value.AuthorityID, AuthorityName: value.AuthorityName, ParentID: value.ParentID, Children: nil, Menus: menus, DataScope: value.DataScope, DefaultRouter: value.DefaultRouter}
|
||||
}
|
||||
func convertUser(user *biz.User) *UserResponse {
|
||||
var authorities []*AuthorityResponse
|
||||
func convertUser(user *biz.User) *dto.UserResponse {
|
||||
var authorities []*dto.AuthorityResponse
|
||||
if user.Authorities != nil {
|
||||
authorities = make([]*AuthorityResponse, 0, len(user.Authorities))
|
||||
authorities = make([]*dto.AuthorityResponse, 0, len(user.Authorities))
|
||||
for _, value := range user.Authorities {
|
||||
authorities = append(authorities, convertAuthority(value))
|
||||
}
|
||||
}
|
||||
var departments []*DepartmentResponse
|
||||
var departments []*dto.DepartmentResponse
|
||||
if user.Departments != nil {
|
||||
departments = make([]*DepartmentResponse, 0, len(user.Departments))
|
||||
departments = make([]*dto.DepartmentResponse, 0, len(user.Departments))
|
||||
for i := range user.Departments {
|
||||
departments = append(departments, departmentResponse(&user.Departments[i]))
|
||||
}
|
||||
}
|
||||
var positions []*PositionResponse
|
||||
var positions []*dto.PositionResponse
|
||||
if user.Positions != nil {
|
||||
positions = make([]*PositionResponse, 0, len(user.Positions))
|
||||
positions = make([]*dto.PositionResponse, 0, len(user.Positions))
|
||||
for i := range user.Positions {
|
||||
positions = append(positions, positionResponse(&user.Positions[i]))
|
||||
}
|
||||
}
|
||||
// The primary department is represented by a zero-value object when it is
|
||||
// absent, preserving the response shape expected by the administration UI.
|
||||
var department any = DepartmentResponse{}
|
||||
var department any = dto.DepartmentResponse{}
|
||||
if user.Department != nil {
|
||||
department = departmentResponse(user.Department)
|
||||
}
|
||||
return &UserResponse{ID: user.ID, CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt, DeletedAt: nil, UUID: user.UUID, Username: user.Username, NickName: user.NickName, HeaderImg: user.HeaderImg, AuthorityID: user.AuthorityID, Authority: convertAuthority(user.Authority), Authorities: authorities, DeptID: user.DeptID, Department: department, Departments: departments, Positions: positions, Phone: user.Phone, Email: user.Email, Enable: user.Enable, OriginSetting: user.OriginSetting, PasswordUpdatedAt: user.PasswordUpdatedAt}
|
||||
return &dto.UserResponse{ID: user.ID, CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt, DeletedAt: nil, UUID: user.UUID, Username: user.Username, NickName: user.NickName, HeaderImg: user.HeaderImg, AuthorityID: user.AuthorityID, Authority: convertAuthority(user.Authority), Authorities: authorities, DeptID: user.DeptID, Department: department, Departments: departments, Positions: positions, Phone: user.Phone, Email: user.Email, Enable: user.Enable, OriginSetting: user.OriginSetting, PasswordUpdatedAt: user.PasswordUpdatedAt}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"kra/internal/service/dto"
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
@@ -48,7 +49,7 @@ type versionExportMenu struct {
|
||||
Hidden bool `json:"hidden"`
|
||||
Component string `json:"component"`
|
||||
Sort int `json:"sort"`
|
||||
Meta VersionMenuMetaRequest `json:"meta"`
|
||||
Meta dto.VersionMenuMetaRequest `json:"meta"`
|
||||
Authorities []any `json:"authoritys"`
|
||||
Children []*versionExportMenu `json:"children"`
|
||||
Parameters []versionExportMenuParameter `json:"parameters"`
|
||||
@@ -105,7 +106,7 @@ type versionExportDocument struct {
|
||||
func exportMenu(value *biz.Menu) *versionExportMenu {
|
||||
menu := &versionExportMenu{
|
||||
Path: value.Path, Name: value.Name, Hidden: value.Hidden, Component: value.Component, Sort: value.Sort,
|
||||
Meta: VersionMenuMetaRequest{ActiveName: value.ActiveName, KeepAlive: value.KeepAlive, DefaultMenu: value.DefaultMenu, Title: value.Title, Icon: value.Icon, CloseTab: value.CloseTab, TransitionType: value.TransitionType},
|
||||
Meta: dto.VersionMenuMetaRequest{ActiveName: value.ActiveName, KeepAlive: value.KeepAlive, DefaultMenu: value.DefaultMenu, Title: value.Title, Icon: value.Icon, CloseTab: value.CloseTab, TransitionType: value.TransitionType},
|
||||
}
|
||||
if len(value.Parameters) > 0 {
|
||||
menu.Parameters = make([]versionExportMenuParameter, 0, len(value.Parameters))
|
||||
@@ -128,8 +129,8 @@ func exportMenu(value *biz.Menu) *versionExportMenu {
|
||||
return menu
|
||||
}
|
||||
|
||||
func versionDTO(v *biz.Version) *VersionResponse {
|
||||
return &VersionResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, VersionName: v.Name, VersionCode: v.Code, Description: v.Description, VersionData: v.Data}
|
||||
func versionDTO(v *biz.Version) *dto.VersionResponse {
|
||||
return &dto.VersionResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, VersionName: v.Name, VersionCode: v.Code, Description: v.Description, VersionData: v.Data}
|
||||
}
|
||||
|
||||
func versionValue(value *string) string {
|
||||
@@ -140,18 +141,18 @@ func versionValue(value *string) string {
|
||||
}
|
||||
|
||||
func versionPointer(value string) *string { return &value }
|
||||
func (s *VersionService) Versions(ctx context.Context, page, size int, name, code string, createdAtRange []*time.Time) ([]*VersionResponse, int64, error) {
|
||||
func (s *VersionService) Versions(ctx context.Context, page, size int, name, code string, createdAtRange []*time.Time) ([]*dto.VersionResponse, int64, error) {
|
||||
items, total, err := s.uc.ListVersions(ctx, page, size, name, code, createdAtRange)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*VersionResponse, 0, len(items))
|
||||
out := make([]*dto.VersionResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, versionDTO(v))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *VersionService) Version(ctx context.Context, id uint) (*VersionResponse, error) {
|
||||
func (s *VersionService) Version(ctx context.Context, id uint) (*dto.VersionResponse, error) {
|
||||
v, err := s.uc.FindVersion(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -222,7 +223,7 @@ func (s *VersionService) Export(ctx context.Context, name, code, description str
|
||||
func (s *VersionService) Import(ctx context.Context, bundle *biz.VersionBundle) error {
|
||||
return s.uc.ImportVersionBundle(ctx, bundle)
|
||||
}
|
||||
func versionMenuDomain(value VersionMenuRequest) *biz.Menu {
|
||||
func versionMenuDomain(value dto.VersionMenuRequest) *biz.Menu {
|
||||
menu := &biz.Menu{Path: value.Path, Name: value.Name, Hidden: value.Hidden, Component: value.Component, Sort: value.Sort, ActiveName: value.Meta.ActiveName, KeepAlive: value.Meta.KeepAlive, DefaultMenu: value.Meta.DefaultMenu, Title: value.Meta.Title, Icon: value.Meta.Icon, CloseTab: value.Meta.CloseTab, TransitionType: value.Meta.TransitionType}
|
||||
for _, button := range value.MenuButtons {
|
||||
menu.Buttons = append(menu.Buttons, &biz.MenuButton{Name: button.Name, Description: button.Description})
|
||||
@@ -235,7 +236,7 @@ func versionMenuDomain(value VersionMenuRequest) *biz.Menu {
|
||||
}
|
||||
return menu
|
||||
}
|
||||
func (s *VersionService) ImportRequest(ctx context.Context, req *ImportVersionRequest) error {
|
||||
func (s *VersionService) ImportRequest(ctx context.Context, req *dto.ImportVersionRequest) error {
|
||||
if req.Version.Name == "" || req.Version.Code == "" {
|
||||
return biz.ErrInvalidVersion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user