chore: initial commit
This commit is contained in:
6
internal/model/common/request.go
Normal file
6
internal/model/common/request.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package common
|
||||
|
||||
type Pagination struct {
|
||||
Page int32 `form:"page,default=1" validate:"gte=1"`
|
||||
PageSize int32 `form:"page_size,default=10" validate:"gte=1,lte=100"`
|
||||
}
|
||||
16
internal/model/common/response.go
Normal file
16
internal/model/common/response.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package common
|
||||
|
||||
// Response 通用响应结构体
|
||||
type Response struct {
|
||||
Message string `json:"msg,omitempty"` // 消息说明
|
||||
Data interface{} `json:"data,omitempty"` // 业务数据
|
||||
}
|
||||
|
||||
// PageResponse 分页查询通用相应结构体
|
||||
type PageResponse struct {
|
||||
Message string `json:"msg,omitempty"` // 消息说明
|
||||
Page int32 `json:"page"` // 当前页码
|
||||
PageSize int32 `json:"page_size"` // 每页数量
|
||||
List interface{} `json:"list,omitempty"` // 业务数据
|
||||
Total int64 `json:"total"` // 总记录数
|
||||
}
|
||||
33
internal/model/enum/enum.go
Normal file
33
internal/model/enum/enum.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package enum
|
||||
|
||||
// Status 通用状态枚举
|
||||
type Status int16
|
||||
|
||||
const (
|
||||
StatusDisabled Status = iota // 0
|
||||
StatusEnabled // 1
|
||||
)
|
||||
|
||||
// MenuType 菜单类型枚举
|
||||
type MenuType int16
|
||||
|
||||
const (
|
||||
MenuTypeDirectory MenuType = iota // 0
|
||||
MenuTypeMenu // 1
|
||||
MenuTypeButton // 2
|
||||
)
|
||||
|
||||
type PermissionType int16
|
||||
|
||||
const (
|
||||
PermissionTypeMenu PermissionType = iota // 0
|
||||
PermissionTypeApi // 1
|
||||
)
|
||||
|
||||
type PostStatus int16
|
||||
|
||||
const (
|
||||
PostStatusDraft PostStatus = iota // 0: 草稿
|
||||
PostStatusPublished // 1: 已发布
|
||||
PostStatusOffline // 2: 已下线
|
||||
)
|
||||
11
internal/model/request/category.go
Normal file
11
internal/model/request/category.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package request
|
||||
|
||||
type CreateCategoryRequest struct {
|
||||
Name string `json:"name" validate:"required,min=1"`
|
||||
Code string `json:"code" validate:"required,min=1"`
|
||||
}
|
||||
|
||||
type UpdateCategoryRequest struct {
|
||||
Name *string `json:"name" validate:"omitempty,min=1"`
|
||||
Code *string `json:"code" validate:"omitempty,min=1"`
|
||||
}
|
||||
30
internal/model/request/post.go
Normal file
30
internal/model/request/post.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type CreatePostRequest struct {
|
||||
Title string `json:"title" validate:"required,min=1"`
|
||||
CoverID *int32 `json:"cover_id" validate:"required,min=1"`
|
||||
Slug string `json:"slug" validate:"required,min=0"`
|
||||
Content string `json:"content" validate:"required,min=0"`
|
||||
Summary string `json:"summary" validate:"required,min=0"`
|
||||
Status *int16 `json:"status" validate:"required,oneof=0 1 2"`
|
||||
Sort *int32 `json:"sort" validate:"required,min=0"`
|
||||
PublishedAt time.Time `json:"published_at" validate:"required"`
|
||||
CategoryID *int32 `json:"category_id" validate:"required,min=1"`
|
||||
}
|
||||
|
||||
type UpdatePostRequest struct {
|
||||
Title *string `json:"title" validate:"omitempty,min=1"`
|
||||
CoverID *int32 `json:"cover_id" validate:"omitempty,min=1"`
|
||||
Slug *string `json:"slug" validate:"omitempty,min=1"`
|
||||
Content *string `json:"content" validate:"required,min=0"`
|
||||
Summary *string `json:"summary" validate:"omitempty,min=1"`
|
||||
Status *int16 `json:"status" validate:"omitempty,oneof=0 1 2"`
|
||||
View *int32 `json:"view" validate:"omitempty,min=1"`
|
||||
Sort *int32 `json:"sort" validate:"omitempty,min=0"`
|
||||
PublishedAt *time.Time `json:"published_at" validate:"omitempty"`
|
||||
CategoryID *int32 `json:"category_id" validate:"required,min=1"`
|
||||
}
|
||||
17
internal/model/request/sys_api.go
Normal file
17
internal/model/request/sys_api.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package request
|
||||
|
||||
type CreateSysApiRequest struct {
|
||||
Name string `json:"name" validate:"required,min=1,max=100"`
|
||||
GroupName string `json:"group_name" validate:"required,min=1,max=100"`
|
||||
Path string `json:"path" validate:"required,min=1,max=100"`
|
||||
Method string `json:"method" validate:"required,oneof=GET POST PUT PATCH DELETE"`
|
||||
Sort *int32 `json:"sort" validate:"required,min=0"`
|
||||
}
|
||||
|
||||
type UpdateSysApiRequest struct {
|
||||
Name string `json:"name" validate:"required,min=1,max=100"`
|
||||
GroupName string `json:"group_name" validate:"required,min=1,max=100"`
|
||||
Path string `json:"path" validate:"required,min=1,max=100"`
|
||||
Method string `json:"method" validate:"required,oneof=GET POST PUT PATCH DELETE"`
|
||||
Sort *int32 `json:"sort" validate:"required,min=0"`
|
||||
}
|
||||
31
internal/model/request/sys_menu.go
Normal file
31
internal/model/request/sys_menu.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"server/internal/pkg/validator"
|
||||
)
|
||||
|
||||
type CreateSysMenuRequest struct {
|
||||
Name string `json:"name" validate:"required,min=1,max=100"`
|
||||
Path string `json:"path" validate:"required,min=1,max=100"`
|
||||
Type *int16 `json:"type" validate:"required,oneof=0 1 2"`
|
||||
Component *string `json:"component" validate:"omitempty"`
|
||||
Hidden *bool `json:"hidden" validate:"omitempty"`
|
||||
Sort *int32 `json:"sort" validate:"required,min=0"`
|
||||
Status *int16 `json:"status" validate:"required,oneof=0 1"`
|
||||
ParentID *int32 `json:"parent_id" validate:"omitempty,gt=0"`
|
||||
Icon *int32 `json:"icon" validate:"omitempty"`
|
||||
PermissionCode string `json:"permission_code" validate:"required,min=1,max=100"`
|
||||
}
|
||||
|
||||
type UpdateSysMenuRequest struct {
|
||||
Name *string `json:"name" validate:"omitempty,min=1,max=100"`
|
||||
Path *string `json:"path" validate:"omitempty,min=1,max=100"`
|
||||
Type *int16 `json:"type" validate:"omitempty,oneof=0 1 2"`
|
||||
Component *string `json:"component" validate:"omitempty"`
|
||||
Hidden *bool `json:"hidden" validate:"omitempty"`
|
||||
Sort *int32 `json:"sort" validate:"omitempty,min=0"`
|
||||
Status *int16 `json:"status" validate:"omitempty,oneof=0 1"`
|
||||
ParentID validator.NullInt32 `json:"parent_id" validate:"omitempty"`
|
||||
Icon *int32 `json:"icon" validate:"omitempty"`
|
||||
PermissionCode *string `json:"permission_code" validate:"omitempty,min=1,max=100"`
|
||||
}
|
||||
1
internal/model/request/sys_permission.go
Normal file
1
internal/model/request/sys_permission.go
Normal file
@@ -0,0 +1 @@
|
||||
package request
|
||||
18
internal/model/request/sys_role.go
Normal file
18
internal/model/request/sys_role.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package request
|
||||
|
||||
type CreateSysRoleRequest struct {
|
||||
Name string `json:"name" validate:"required,min=1,max=100"`
|
||||
Code string `json:"code" validate:"required,max=100"`
|
||||
}
|
||||
|
||||
type UpdateSysRoleRequest struct {
|
||||
Name *string `json:"name" validate:"min=1,max=100"`
|
||||
}
|
||||
|
||||
type SetSysRoleMenusRequest struct {
|
||||
MenuIDs []int32 `json:"menu_ids" validate:"required,dive,gt=0"`
|
||||
}
|
||||
|
||||
type SetSysRoleApisRequest struct {
|
||||
ApiIDs []int32 `json:"api_ids" validate:"required,dive,gt=0"`
|
||||
}
|
||||
30
internal/model/request/sys_user.go
Normal file
30
internal/model/request/sys_user.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"server/internal/pkg/validator"
|
||||
)
|
||||
|
||||
type CreateSysUserRequest struct {
|
||||
Username string `json:"username" validate:"required"`
|
||||
Account string `json:"account" validate:"required,min=5,max=100"`
|
||||
Password string `json:"password" validate:"required,min=6,max=255"`
|
||||
AvatarID *int32 `json:"avatar_id" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type UpdateSysUserRequest struct {
|
||||
Username *string `json:"username" validate:"omitempty,min=0,max=50"`
|
||||
AvatarID validator.NullInt32 `json:"avatar_id" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type UpdateSysUserPassword struct {
|
||||
Password string `json:"password" validate:"required,min=6,max=255"`
|
||||
}
|
||||
|
||||
type SetSysUserRolesRequest struct {
|
||||
RoleIDs []int32 `json:"role_ids" validate:"required,dive,gt=0"`
|
||||
}
|
||||
|
||||
type LoginRequest struct {
|
||||
Account string `json:"account" validate:"required,min=5,max=100"`
|
||||
Password string `json:"password" validate:"required,min=6,max=255"`
|
||||
}
|
||||
25
internal/model/response/post.go
Normal file
25
internal/model/response/post.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type ArchivePost struct {
|
||||
ID int32 `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
Title string `json:"title"`
|
||||
PublishedAt time.Time `json:"published_at"`
|
||||
PublishedAtDisplay string `json:"published_at_display"`
|
||||
CategoryName string `json:"category_name"`
|
||||
}
|
||||
|
||||
type ArchiveMonth struct {
|
||||
Month int `json:"month"`
|
||||
Archive []ArchivePost `json:"list"`
|
||||
}
|
||||
|
||||
type ArchiveYear struct {
|
||||
Year int `json:"year"`
|
||||
Total int `json:"total"`
|
||||
ArchiveMonth []ArchiveMonth `json:"list"`
|
||||
}
|
||||
15
internal/model/response/sys_file.go
Normal file
15
internal/model/response/sys_file.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
db "server/internal/db/sqlc"
|
||||
"server/internal/pkg/httputil"
|
||||
)
|
||||
|
||||
func ToFiles(files []db.File) []db.File {
|
||||
result := make([]db.File, len(files))
|
||||
for i := range files {
|
||||
result[i] = files[i]
|
||||
result[i].FilePath = httputil.BuildFileUrl(&files[i].FilePath)
|
||||
}
|
||||
return result
|
||||
}
|
||||
45
internal/model/response/sys_user.go
Normal file
45
internal/model/response/sys_user.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
db "server/internal/db/sqlc"
|
||||
"server/internal/pkg/httputil"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SysUserRolesResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type SysUserInfo struct {
|
||||
ID int32 `json:"id"`
|
||||
Account string `json:"account"`
|
||||
Username string `json:"username"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
Roles []string `json:"roles"`
|
||||
Menus []db.SysMenu `json:"menus"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
AccessTokenExp time.Time `json:"access_token_exp"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
RefreshTokenExp time.Time `json:"refresh_token_exp"`
|
||||
}
|
||||
|
||||
func NewSysUserInfo(user db.GetSysUserByIDRow, roles []db.SysRole, menus []db.SysMenu) *SysUserInfo {
|
||||
roleCodes := make([]string, len(roles))
|
||||
for i, role := range roles {
|
||||
roleCodes[i] = role.Code
|
||||
}
|
||||
|
||||
return &SysUserInfo{
|
||||
ID: user.ID,
|
||||
Account: user.Account,
|
||||
Username: user.Username,
|
||||
AvatarUrl: httputil.BuildFileUrl(user.AvatarUrl),
|
||||
Roles: roleCodes,
|
||||
Menus: menus,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user