feat: update model

v3
veypi 3 weeks ago
parent 11521b4b1c
commit 1ad9cb686f

@ -251,7 +251,7 @@ func tokenList(x *rest.X) (any, error) {
query := cfg.DB()
query = query.Where("user_id = ?", opts.UserID)
query = query.Where("app_id = ?", opts.AppID)
err = query.Find(&data).Error
err = query.Limit(opts.Limit).Find(&data).Error
return data, err
}

@ -41,8 +41,10 @@ func runWeb() error {
builtin.Enable(app)
app.Router().Any("/media/*", http.StripPrefix("/media", http.FileServer(http.Dir("/home/v/cache/"))).ServeHTTP)
apiRouter := app.Router().SubRouter("api")
api.Use(apiRouter)
apiRouter.Use(errs.JsonResponse)
apiRouter.SetErrFunc(errs.JsonErrorResponse)
app.Router().EmbedDir("/", staticFs, "static/", "static/index.html")
app.Router().Print()

@ -5,11 +5,11 @@ import "time"
type AccessList struct {
CreatedAt *time.Time `json:"created_at" parse:"query"`
UpdatedAt *time.Time `json:"updated_at" parse:"query"`
AppID string `json:"app_id" gorm:"index;type:varchar(32)" parse:"json"`
UserID *string `json:"user_id" gorm:"index;type:varchar(32);default: null" parse:"json"`
RoleID *string `json:"role_id" gorm:"index;type:varchar(32);default: null" parse:"json"`
Name *string `json:"name" parse:"json"`
ResourceID *string `json:"resource_id" gorm:"index;type:varchar(32);default: null" parse:"json"`
AppID string `json:"app_id" gorm:"index;type:varchar(32)" parse:"query"`
UserID *string `json:"user_id" gorm:"index;type:varchar(32);default: null" parse:"query"`
RoleID *string `json:"role_id" gorm:"index;type:varchar(32);default: null" parse:"query"`
ResourceID *string `json:"resource_id" gorm:"index;type:varchar(32);default: null" parse:"query"`
Name *string `json:"name" parse:"query"`
}
type AccessPost struct {

@ -27,13 +27,13 @@ type AppPost struct {
}
type AppList struct {
Name *string `json:"name" parse:"json"`
Name *string `json:"name" parse:"query"`
}
type AppUserGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"`
UserID string `json:"user_id" parse:"json"`
AppID string `json:"app_id" parse:"path"`
UserID string `json:"user_id" parse:"query"`
}
type AppUserPatch struct {
@ -49,8 +49,8 @@ type AppUserDelete struct {
type AppUserList struct {
AppID *string `json:"app_id" parse:"path"`
UserID *string `json:"user_id" parse:"json"`
Status *string `json:"status" parse:"json"`
UserID *string `json:"user_id" parse:"query"`
Status *string `json:"status" parse:"query"`
}
type AppUserPost struct {

@ -22,5 +22,5 @@ type RolePost struct {
}
type RoleList struct {
Name *string `json:"name" parse:"json"`
Name *string `json:"name" parse:"query"`
}

@ -38,6 +38,7 @@ type TokenDelete struct {
}
type TokenList struct {
UserID string `json:"user_id" gorm:"index;type:varchar(32)" parse:"json"`
AppID string `json:"app_id" gorm:"index;type:varchar(32)" parse:"json"`
Limit int `json:"limit"`
UserID string `json:"user_id" gorm:"index;type:varchar(32)" parse:"query"`
AppID string `json:"app_id" gorm:"index;type:varchar(32)" parse:"query"`
}

@ -31,11 +31,11 @@ type UserPost struct {
}
type UserList struct {
Username *string `json:"username" gorm:"varchar(100);unique;default:not null" parse:"json"`
Nickname *string `json:"nickname" parse:"json"`
Email *string `json:"email" gorm:"varchar(20);unique;default:null" parse:"json"`
Phone *string `json:"phone" gorm:"varchar(50);unique;default:null" parse:"json"`
Status *uint `json:"status" parse:"json"`
Username *string `json:"username" gorm:"type:varchar(100);unique;default:not null" parse:"query"`
Nickname *string `json:"nickname" gorm:"type:varchar(100)" parse:"query"`
Email *string `json:"email" gorm:"unique;type:varchar(50);default:null" parse:"query"`
Phone *string `json:"phone" gorm:"type:varchar(30);unique;default:null" parse:"query"`
Status *uint `json:"status" parse:"query"`
}
type UserRoleGet struct {
@ -64,6 +64,6 @@ type UserRolePost struct {
}
type UserRoleList struct {
Status *string `json:"status" parse:"json"`
UserID string `json:"user_id" parse:"path"`
Status *string `json:"status" parse:"query"`
}

@ -6,18 +6,17 @@
import webapi from "./webapi"
import * as models from "./models"
export interface ListOpts {
export interface ListQuery {
created_at?: Date
updated_at?: Date
app_id: string
user_id?: string
role_id?: string
resource_id?: string
name?: string
}
export interface ListQuery {
created_at?: Date
updated_at?: Date
}
export function List(json: ListOpts, query: ListQuery) {
return webapi.Get<models.Access[]>(`/access`, { json, query })
export function List(query: ListQuery) {
return webapi.Get<models.Access[]>(`/access`, { query })
}
export interface PostOpts {
@ -27,8 +26,21 @@ export interface PostOpts {
name: string
t_id: string
level: number
resource_id?: string
}
export function Post(json: PostOpts) {
return webapi.Post<models.Access>(`/access`, { json })
}
export function Get(access_id: string) {
return webapi.Get<models.Access>(`/access/${access_id}`, {})
}
export function Patch(access_id: string) {
return webapi.Patch<models.Access>(`/access/${access_id}`, {})
}
export function Delete(access_id: string) {
return webapi.Delete<models.Access>(`/access/${access_id}`, {})
}

@ -14,8 +14,9 @@ export interface PatchOpts {
name?: string
icon?: string
des?: string
participate?: string
init_role_id?: string
typ?: string
status?: string
}
export function Patch(app_id: string, json: PatchOpts) {
return webapi.Patch<models.App>(`/app/${app_id}`, { json })
@ -28,8 +29,9 @@ export function Delete(app_id: string) {
export interface PostOpts {
name: string
icon: string
des: string
participate: string
des?: string
typ: string
status: string
}
export function Post(json: PostOpts) {
return webapi.Post<models.App>(`/app`, { json })
@ -38,25 +40,25 @@ export function Post(json: PostOpts) {
export interface ListOpts {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<models.App[]>(`/app`, { json })
export function List(query: ListQuery) {
return webapi.Get<models.App[]>(`/app`, { query })
}
export interface AppUserGetOpts {
user_id: string
}
export function AppUserGet(app_user_id: string, app_id: string, json: AppUserGetOpts) {
return webapi.Get<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { json })
export function AppUserGet(app_id: string, app_user_id: string, query: AppUserGetQuery) {
return webapi.Get<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { query })
}
export interface AppUserPatchOpts {
status?: string
}
export function AppUserPatch(app_user_id: string, app_id: string, json: AppUserPatchOpts) {
export function AppUserPatch(app_id: string, app_user_id: string, json: AppUserPatchOpts) {
return webapi.Patch<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { json })
}
export function AppUserDelete(app_user_id: string, app_id: string) {
export function AppUserDelete(app_id: string, app_user_id: string) {
return webapi.Delete<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, {})
}
@ -64,8 +66,8 @@ export interface AppUserListOpts {
user_id?: string
status?: string
}
export function AppUserList(app_id: string, json: AppUserListOpts) {
return webapi.Get<models.AppUser[]>(`/app/${app_id}/app_user`, { json })
export function AppUserList(app_id: string, query: AppUserListQuery) {
return webapi.Get<models.AppUser[]>(`/app/${app_id}/app_user`, { query })
}
export interface AppUserPostOpts {
@ -76,12 +78,8 @@ export function AppUserPost(app_id: string, json: AppUserPostOpts) {
return webapi.Post<models.AppUser>(`/app/${app_id}/app_user`, { json })
}
export interface ResourceListQuery {
created_at?: Date
updated_at?: Date
}
export function ResourceList(app_id: string, query: ResourceListQuery) {
return webapi.Get<models.Resource[]>(`/app/${app_id}/resource`, { query })
export function ResourceList(app_id: string) {
return webapi.Get<models.Resource[]>(`/app/${app_id}/resource`, {})
}
export interface ResourcePostOpts {
@ -95,15 +93,28 @@ export function ResourcePost(app_id: string, json: ResourcePostOpts) {
export interface ResourceDeleteOpts {
name: string
}
export function ResourceDelete(app_id: string, json: ResourceDeleteOpts) {
return webapi.Delete<models.Resource>(`/app/${app_id}/resource`, { json })
export function ResourceGet(app_id: string, resource_id: string) {
return webapi.Get<models.Resource>(`/app/${app_id}/resource/${resource_id}`, {})
}
export function ResourceGet(app_id: string) {
return webapi.Get<models.Resource>(`/app/${app_id}/resource`, {})
export interface ResourcePatchOpts {
des?: string
}
export function ResourcePatch(app_id: string, resource_id: string, json: ResourcePatchOpts) {
return webapi.Patch<models.Resource>(`/app/${app_id}/resource/${resource_id}`, { json })
}
export function ResourcePatch(app_id: string) {
return webapi.Patch<models.Resource>(`/app/${app_id}/resource`, {})
export function ResourceDelete(app_id: string, resource_id: string) {
return webapi.Delete<models.Resource>(`/app/${app_id}/resource/${resource_id}`, {})
}
export interface ListQuery {
name?: string
}
export interface AppUserGetQuery {
user_id: string
}
export interface AppUserListQuery {
user_id?: string
status?: string
}

@ -1,12 +1,14 @@
export interface Access {
created_at: Date
updated_at: Date
app_id: string
id: string
user_id?: string
role_id?: string
name: string
tid: string
level: number
resource_id?: string
app_id: string
}
export interface App {
id: string
@ -23,6 +25,9 @@ export interface App {
status: string
user_status: string
}
export const AppTyp = ['public', 'apply', 'private']
export interface AppUser {
id: string
created_at: Date
@ -36,9 +41,10 @@ export interface AppUser {
export interface Resource {
created_at: Date
updated_at: Date
app_id: string
id: string
name: string
des: string
app_id: string
}
export interface Role {
id: string

@ -6,6 +6,7 @@
import webapi from "./webapi"
import * as models from "./models"
export function Get(role_id: string) {
return webapi.Get<models.Role>(`/role/${role_id}`, {})
}
@ -32,10 +33,10 @@ export function Post(json: PostOpts) {
return webapi.Post<models.Role>(`/role`, { json })
}
export interface ListOpts {
export interface ListQuery {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<models.Role[]>(`/role`, { json })
export function List(query: ListQuery) {
return webapi.Get<models.Role[]>(`/role`, { query })
}

@ -12,7 +12,7 @@ export interface TokenSaltOpts {
}
// keep
export function TokenSalt(json: TokenSaltOpts) {
return webapi.Post<{ id: string, salt: string }>(`/token/salt`, { json })
return webapi.Get<{ id: string, salt: string }>(`/token/TokenSalt`, { json })
}
export interface PostOpts {
refresh?: string
@ -46,11 +46,11 @@ export function Delete(token_id: string) {
return webapi.Delete<models.Token>(`/token/${token_id}`, {})
}
export interface ListOpts {
export interface ListQuery {
user_id: string
app_id: string
}
export function List(json: ListOpts) {
return webapi.Get<models.Token[]>(`/token`, { json })
export function List(query: ListQuery) {
return webapi.Get<models.Token[]>(`/token`, { query })
}

@ -39,25 +39,25 @@ export function Post(json: PostOpts) {
return webapi.Post<models.User>(`/user`, { json })
}
export interface ListOpts {
export interface ListQuery {
username?: string
nickname?: string
email?: string
phone?: string
status?: number
}
export function List(json: ListOpts) {
return webapi.Get<models.User[]>(`/user`, { json })
export function List(query: ListQuery) {
return webapi.Get<models.User[]>(`/user`, { query })
}
export function UserRoleGet(user_role_id: string, user_id: string) {
export function UserRoleGet(user_id: string, user_role_id: string) {
return webapi.Get<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, {})
}
export interface UserRolePatchOpts {
status?: string
}
export function UserRolePatch(user_role_id: string, user_id: string, json: UserRolePatchOpts) {
export function UserRolePatch(user_id: string, user_role_id: string, json: UserRolePatchOpts) {
return webapi.Patch<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, { json })
}
@ -65,7 +65,7 @@ export interface UserRoleDeleteOpts {
role_id: string
app_id: string
}
export function UserRoleDelete(user_role_id: string, user_id: string, json: UserRoleDeleteOpts) {
export function UserRoleDelete(user_id: string, user_role_id: string, json: UserRoleDeleteOpts) {
return webapi.Delete<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, { json })
}
@ -78,10 +78,10 @@ export function UserRolePost(user_id: string, json: UserRolePostOpts) {
return webapi.Post<models.UserRole>(`/user/${user_id}/user_role`, { json })
}
export interface UserRoleListOpts {
export interface UserRoleListQuery {
status?: string
}
export function UserRoleList(user_id: string, json: UserRoleListOpts) {
return webapi.Get<models.UserRole[]>(`/user/${user_id}/user_role`, { json })
export function UserRoleList(user_id: string, query: UserRoleListQuery) {
return webapi.Get<models.UserRole[]>(`/user/${user_id}/user_role`, { query })
}

@ -10,7 +10,7 @@ import * as typs from './typs'
import { proxy } from './v2dom'
class Token {
iat?: string
iat?: number
// oa_id
iss?: string
// token id
@ -63,7 +63,8 @@ class Token {
if (!logic.token.refresh.isVaild() || this._typ === 'refresh') {
reject()
}
if (this.isVaild()) {
let now = Math.floor(Date.now() / 1000)
if (this.isVaild() && this.iat && now - this.iat < 10) {
return resolve(this)
}
let aid = logic.oa_id

@ -86,9 +86,6 @@ export default new class {
app: {
Get: api.app.Get,
List: api.app.List,
},
token: {
Post: api.token.Post
}
}
}

@ -6,18 +6,17 @@
import webapi from "./webapi"
import * as models from "./models"
export interface ListOpts {
export interface ListQuery {
created_at?: Date
updated_at?: Date
app_id: string
user_id?: string
role_id?: string
resource_id?: string
name?: string
}
export interface ListQuery {
created_at?: Date
updated_at?: Date
}
export function List(json: ListOpts, query: ListQuery) {
return webapi.Get<models.Access[]>(`/access`, { json, query })
export function List(query: ListQuery) {
return webapi.Get<models.Access[]>(`/access`, { query })
}
export interface PostOpts {
@ -27,8 +26,21 @@ export interface PostOpts {
name: string
t_id: string
level: number
resource_id?: string
}
export function Post(json: PostOpts) {
return webapi.Post<models.Access>(`/access`, { json })
}
export function Get(access_id: string) {
return webapi.Get<models.Access>(`/access/${access_id}`, {})
}
export function Patch(access_id: string) {
return webapi.Patch<models.Access>(`/access/${access_id}`, {})
}
export function Delete(access_id: string) {
return webapi.Delete<models.Access>(`/access/${access_id}`, {})
}

@ -40,25 +40,25 @@ export function Post(json: PostOpts) {
export interface ListOpts {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<models.App[]>(`/app`, { json })
export function List(query: ListQuery) {
return webapi.Get<models.App[]>(`/app`, { query })
}
export interface AppUserGetOpts {
user_id: string
}
export function AppUserGet(app_user_id: string, app_id: string, json: AppUserGetOpts) {
return webapi.Get<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { json })
export function AppUserGet(app_id: string, app_user_id: string, query: AppUserGetQuery) {
return webapi.Get<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { query })
}
export interface AppUserPatchOpts {
status?: string
}
export function AppUserPatch(app_user_id: string, app_id: string, json: AppUserPatchOpts) {
export function AppUserPatch(app_id: string, app_user_id: string, json: AppUserPatchOpts) {
return webapi.Patch<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { json })
}
export function AppUserDelete(app_user_id: string, app_id: string) {
export function AppUserDelete(app_id: string, app_user_id: string) {
return webapi.Delete<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, {})
}
@ -66,8 +66,8 @@ export interface AppUserListOpts {
user_id?: string
status?: string
}
export function AppUserList(app_id: string, json: AppUserListOpts) {
return webapi.Get<models.AppUser[]>(`/app/${app_id}/app_user`, { json })
export function AppUserList(app_id: string, query: AppUserListQuery) {
return webapi.Get<models.AppUser[]>(`/app/${app_id}/app_user`, { query })
}
export interface AppUserPostOpts {
@ -78,12 +78,8 @@ export function AppUserPost(app_id: string, json: AppUserPostOpts) {
return webapi.Post<models.AppUser>(`/app/${app_id}/app_user`, { json })
}
export interface ResourceListQuery {
created_at?: Date
updated_at?: Date
}
export function ResourceList(app_id: string, query: ResourceListQuery) {
return webapi.Get<models.Resource[]>(`/app/${app_id}/resource`, { query })
export function ResourceList(app_id: string) {
return webapi.Get<models.Resource[]>(`/app/${app_id}/resource`, {})
}
export interface ResourcePostOpts {
@ -97,15 +93,28 @@ export function ResourcePost(app_id: string, json: ResourcePostOpts) {
export interface ResourceDeleteOpts {
name: string
}
export function ResourceDelete(app_id: string, json: ResourceDeleteOpts) {
return webapi.Delete<models.Resource>(`/app/${app_id}/resource`, { json })
export function ResourceGet(app_id: string, resource_id: string) {
return webapi.Get<models.Resource>(`/app/${app_id}/resource/${resource_id}`, {})
}
export function ResourceGet(app_id: string) {
return webapi.Get<models.Resource>(`/app/${app_id}/resource`, {})
export interface ResourcePatchOpts {
des?: string
}
export function ResourcePatch(app_id: string, resource_id: string, json: ResourcePatchOpts) {
return webapi.Patch<models.Resource>(`/app/${app_id}/resource/${resource_id}`, { json })
}
export function ResourcePatch(app_id: string) {
return webapi.Patch<models.Resource>(`/app/${app_id}/resource`, {})
export function ResourceDelete(app_id: string, resource_id: string) {
return webapi.Delete<models.Resource>(`/app/${app_id}/resource/${resource_id}`, {})
}
export interface ListQuery {
name?: string
}
export interface AppUserGetQuery {
user_id: string
}
export interface AppUserListQuery {
user_id?: string
status?: string
}

@ -1,12 +1,14 @@
export interface Access {
created_at: Date
updated_at: Date
app_id: string
id: string
user_id?: string
role_id?: string
name: string
tid: string
level: number
resource_id?: string
app_id: string
}
export interface App {
id: string
@ -39,9 +41,10 @@ export interface AppUser {
export interface Resource {
created_at: Date
updated_at: Date
app_id: string
id: string
name: string
des: string
app_id: string
}
export interface Role {
id: string

@ -6,6 +6,7 @@
import webapi from "./webapi"
import * as models from "./models"
export function Get(role_id: string) {
return webapi.Get<models.Role>(`/role/${role_id}`, {})
}
@ -32,10 +33,10 @@ export function Post(json: PostOpts) {
return webapi.Post<models.Role>(`/role`, { json })
}
export interface ListOpts {
export interface ListQuery {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<models.Role[]>(`/role`, { json })
export function List(query: ListQuery) {
return webapi.Get<models.Role[]>(`/role`, { query })
}

@ -12,11 +12,11 @@ export interface TokenSaltOpts {
}
// keep
export function TokenSalt(json: TokenSaltOpts) {
return webapi.Post<{ id: string, salt: string }>(`/token/salt`, { json })
return webapi.Get<{ id: string, salt: string }>(`/token/TokenSalt`, { json })
}
export interface PostOpts {
refresh?: string
typ?: 'app' | 'ufs'
typ?: string
user_id?: string
salt?: string
code?: string
@ -46,12 +46,11 @@ export function Delete(token_id: string) {
return webapi.Delete<models.Token>(`/token/${token_id}`, {})
}
export interface ListOpts {
export interface ListQuery {
user_id: string
app_id: string
limit: number
}
export function List(json: ListOpts) {
return webapi.Get<models.Token[]>(`/token`, { json })
export function List(query: ListQuery) {
return webapi.Get<models.Token[]>(`/token`, { query })
}

@ -39,25 +39,25 @@ export function Post(json: PostOpts) {
return webapi.Post<models.User>(`/user`, { json })
}
export interface ListOpts {
export interface ListQuery {
username?: string
nickname?: string
email?: string
phone?: string
status?: number
}
export function List(json: ListOpts) {
return webapi.Get<models.User[]>(`/user`, { json })
export function List(query: ListQuery) {
return webapi.Get<models.User[]>(`/user`, { query })
}
export function UserRoleGet(user_role_id: string, user_id: string) {
export function UserRoleGet(user_id: string, user_role_id: string) {
return webapi.Get<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, {})
}
export interface UserRolePatchOpts {
status?: string
}
export function UserRolePatch(user_role_id: string, user_id: string, json: UserRolePatchOpts) {
export function UserRolePatch(user_id: string, user_role_id: string, json: UserRolePatchOpts) {
return webapi.Patch<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, { json })
}
@ -65,7 +65,7 @@ export interface UserRoleDeleteOpts {
role_id: string
app_id: string
}
export function UserRoleDelete(user_role_id: string, user_id: string, json: UserRoleDeleteOpts) {
export function UserRoleDelete(user_id: string, user_role_id: string, json: UserRoleDeleteOpts) {
return webapi.Delete<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, { json })
}
@ -78,10 +78,10 @@ export function UserRolePost(user_id: string, json: UserRolePostOpts) {
return webapi.Post<models.UserRole>(`/user/${user_id}/user_role`, { json })
}
export interface UserRoleListOpts {
export interface UserRoleListQuery {
status?: string
}
export function UserRoleList(user_id: string, json: UserRoleListOpts) {
return webapi.Get<models.UserRole[]>(`/user/${user_id}/user_role`, { json })
export function UserRoleList(user_id: string, query: UserRoleListQuery) {
return webapi.Get<models.UserRole[]>(`/user/${user_id}/user_role`, { query })
}

Loading…
Cancel
Save