优化
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func bindErrorMutation(t *testing.T, body string) (ErrorRecordMutationRequest, error) {
|
||||
t.Helper()
|
||||
context, _ := gin.CreateTestContext(httptest.NewRecorder())
|
||||
context.Request = httptest.NewRequest("PUT", "/sysError/updateSysError", strings.NewReader(body))
|
||||
context.Request.Header.Set("Content-Type", "application/json")
|
||||
var request ErrorRecordMutationRequest
|
||||
return request, context.ShouldBindJSON(&request)
|
||||
}
|
||||
|
||||
func TestErrorRecordMutationAcceptsExplicitEmptyPointerFields(t *testing.T) {
|
||||
request, err := bindErrorMutation(t, `{"ID":1,"form":"","info":"","solution":""}`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if request.Form == nil || *request.Form != "" || request.Info == nil || *request.Info != "" || request.Solution == nil || *request.Solution != "" {
|
||||
t.Fatalf("explicit empty values lost: form=%#v info=%#v solution=%#v", request.Form, request.Info, request.Solution)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorRecordMutationRequiresFormButKeepsOtherFieldsOmittable(t *testing.T) {
|
||||
request, err := bindErrorMutation(t, `{"ID":1}`)
|
||||
if err == nil {
|
||||
t.Fatal("missing form unexpectedly accepted")
|
||||
}
|
||||
if request.Info != nil || request.Solution != nil {
|
||||
t.Fatalf("omitted fields = (%#v, %#v), want nil", request.Info, request.Solution)
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,12 @@ type DeleteAuthorityRequest struct {
|
||||
}
|
||||
type SetRoleUsersRequest struct {
|
||||
AuthorityID uint `json:"authorityId" form:"authorityId"`
|
||||
UserIDs []uint `json:"userIds"`
|
||||
UserIDs []uint `json:"userIds" form:"userIds"`
|
||||
}
|
||||
type SetDataScopeRequest struct {
|
||||
AuthorityID uint `json:"authorityId" form:"authorityId"`
|
||||
DataScope int `json:"dataScope"`
|
||||
DepartmentIDs []uint `json:"deptIds"`
|
||||
DataScope int `json:"dataScope" form:"dataScope"`
|
||||
DepartmentIDs []uint `json:"deptIds" form:"deptIds"`
|
||||
}
|
||||
|
||||
type AuthorityResponse struct {
|
||||
@@ -36,7 +36,7 @@ type AuthorityResponse struct {
|
||||
AuthorityName string `json:"authorityName"`
|
||||
ParentID *uint `json:"parentId"`
|
||||
Children []*AuthorityResponse `json:"children"`
|
||||
Menus []any `json:"menus"`
|
||||
Menus []*MenuResponse `json:"menus"`
|
||||
DataScope int `json:"dataScope"`
|
||||
DefaultRouter string `json:"defaultRouter"`
|
||||
}
|
||||
|
||||
@@ -61,6 +61,9 @@ type IDRequest struct {
|
||||
type IDsRequest struct {
|
||||
IDs []uint `json:"ids"`
|
||||
}
|
||||
type MediaBatchDeleteRequest struct {
|
||||
IDs []uint `json:"ids" binding:"required"`
|
||||
}
|
||||
type RenameMediaRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -13,19 +13,27 @@ type MenuMetaRequest struct {
|
||||
}
|
||||
|
||||
type MenuButtonRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"desc"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
ID uint `json:"ID"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"desc"`
|
||||
SysBaseMenuID uint `json:"sysBaseMenuID"`
|
||||
}
|
||||
|
||||
type MenuParameterRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Type string `json:"type"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
ID uint `json:"ID"`
|
||||
SysBaseMenuID uint `json:"SysBaseMenuID"`
|
||||
Type string `json:"type"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type MenuRequest struct {
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
ID uint `json:"ID"`
|
||||
ParentID uint `json:"parentId"`
|
||||
Path string `json:"path"`
|
||||
@@ -39,20 +47,16 @@ type MenuRequest struct {
|
||||
}
|
||||
|
||||
type DeleteMenuRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
ID int `json:"id"`
|
||||
}
|
||||
|
||||
type GetMenuRequest struct {
|
||||
ID uint `json:"id"`
|
||||
}
|
||||
|
||||
type AuthorityMenuItemRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
ID int `json:"id"`
|
||||
}
|
||||
|
||||
type SetAuthorityMenusRequest struct {
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
Menus []AuthorityMenuItemRequest `json:"menus"`
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
Menus []MenuRequest `json:"menus"`
|
||||
}
|
||||
|
||||
type GetAuthorityMenusRequest struct {
|
||||
@@ -108,14 +112,32 @@ type MenuResponse struct {
|
||||
Children []*MenuResponse `json:"children"`
|
||||
Parameters []MenuParameterResponse `json:"parameters"`
|
||||
MenuButtons []MenuButtonResponse `json:"menuBtn"`
|
||||
Authorities []*AuthorityResponse `json:"authoritys"`
|
||||
}
|
||||
|
||||
type DynamicMenuResponse struct {
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
ID uint `json:"ID"`
|
||||
MenuID uint `json:"menuId"`
|
||||
ParentID uint `json:"parentId"`
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Hidden bool `json:"hidden"`
|
||||
Component string `json:"component"`
|
||||
Sort int `json:"sort"`
|
||||
Meta MenuMetaResponse `json:"meta"`
|
||||
Children []*DynamicMenuResponse `json:"children"`
|
||||
Parameters []MenuParameterResponse `json:"parameters"`
|
||||
MenuButtons []MenuButtonResponse `json:"menuBtn"`
|
||||
Buttons map[string]uint `json:"btns"`
|
||||
Authorities []*AuthorityResponse `json:"authoritys"`
|
||||
}
|
||||
|
||||
type AuthorityMenuResponse struct {
|
||||
// The administration response embeds the base-menu fields, so menu fields are
|
||||
// flat in the response (there is no sysBaseMenu envelope). Keep the
|
||||
// authority ID internal, matching the compatible json:"-" field.
|
||||
*MenuResponse
|
||||
MenuID uint `json:"menuId"`
|
||||
*DynamicMenuResponse
|
||||
AuthorityID uint `json:"-"`
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package dto
|
||||
|
||||
type GetAuthorityButtonsRequest struct {
|
||||
MenuID uint `json:"menuID"`
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
MenuID uint `json:"menuID"`
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
Selected []uint `json:"selected"`
|
||||
}
|
||||
|
||||
type SetAuthorityButtonsRequest struct {
|
||||
|
||||
@@ -31,11 +31,13 @@ type DictionaryDetailsByParentRequest struct {
|
||||
IncludeChildren bool `json:"includeChildren" form:"includeChildren"`
|
||||
}
|
||||
type SystemParameterRequest struct {
|
||||
ID uint `json:"ID" form:"ID"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Key string `json:"key" form:"key" binding:"required"`
|
||||
Value string `json:"value" form:"value" binding:"required"`
|
||||
Description string `json:"desc" form:"desc"`
|
||||
ID uint `json:"ID" form:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt" form:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt" form:"UpdatedAt"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Key string `json:"key" form:"key" binding:"required"`
|
||||
Value string `json:"value" form:"value" binding:"required"`
|
||||
Description string `json:"desc" form:"desc"`
|
||||
}
|
||||
|
||||
type SystemParameterSearchRequest struct {
|
||||
|
||||
@@ -75,25 +75,26 @@ type LoginLogRequest struct {
|
||||
}
|
||||
|
||||
type UserResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt any `json:"-"`
|
||||
UUID string `json:"uuid"`
|
||||
Username string `json:"userName"`
|
||||
NickName string `json:"nickName"`
|
||||
HeaderImg string `json:"headerImg"`
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
Authority *AuthorityResponse `json:"authority"`
|
||||
Authorities []*AuthorityResponse `json:"authorities"`
|
||||
DeptID uint `json:"deptId"`
|
||||
Department any `json:"dept"`
|
||||
Departments []*DepartmentResponse `json:"departments"`
|
||||
Positions []*PositionResponse `json:"positions"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Enable int `json:"enable"`
|
||||
OriginSetting map[string]any `json:"originSetting"`
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt any `json:"-"`
|
||||
UUID string `json:"uuid"`
|
||||
Username string `json:"userName"`
|
||||
NickName string `json:"nickName"`
|
||||
HeaderImg string `json:"headerImg"`
|
||||
AuthorityID uint `json:"authorityId"`
|
||||
Authority *AuthorityResponse `json:"authority"`
|
||||
Authorities []*AuthorityResponse `json:"authorities"`
|
||||
DeptID uint `json:"deptId"`
|
||||
Department any `json:"dept"`
|
||||
Departments []*DepartmentResponse `json:"departments"`
|
||||
Positions []*PositionResponse `json:"positions"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Enable int `json:"enable"`
|
||||
OriginSetting map[string]any `json:"originSetting"`
|
||||
PasswordUpdatedAt *time.Time `json:"passwordUpdatedAt"`
|
||||
}
|
||||
|
||||
type ServerInfoResponse struct {
|
||||
|
||||
@@ -7,10 +7,10 @@ type VersionResponse struct {
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt any `json:"-"`
|
||||
VersionName string `json:"versionName"`
|
||||
VersionCode string `json:"versionCode"`
|
||||
Description string `json:"description"`
|
||||
VersionData string `json:"versionData"`
|
||||
VersionName *string `json:"versionName"`
|
||||
VersionCode *string `json:"versionCode"`
|
||||
Description *string `json:"description"`
|
||||
VersionData *string `json:"versionData"`
|
||||
}
|
||||
|
||||
type VersionSearchRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user