feat: update api interface

v3
veypi 2 months ago
parent 3e744e4d9f
commit dcce188e7a

@ -90,12 +90,6 @@ func appUserPatch(x *rest.X) (any, error) {
return nil, err
}
optsMap := make(map[string]interface{})
if opts.AppID != nil {
optsMap["app_id"] = opts.AppID
}
if opts.UserID != nil {
optsMap["user_id"] = opts.UserID
}
if opts.Status != nil {
optsMap["status"] = opts.Status
}

@ -31,6 +31,7 @@ func JsonErrorResponse(x *rest.X, err error) {
func errIter(err error) (code int, msg string) {
code = 50000
msg = err.Error()
switch e := err.(type) {
case *CodeErr:
code = e.Code
@ -44,7 +45,7 @@ func errIter(err error) (code int, msg string) {
msg = "db error"
}
case interface{ Unwrap() error }:
return errIter(e.Unwrap())
code, _ = errIter(e.Unwrap())
default:
if errors.Is(e, gorm.ErrRecordNotFound) {
code = NotFound.Code

@ -33,46 +33,54 @@ type AppList struct {
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:"path"`
}
type AppUserPatch struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"`
AppID *string `json:"app_id" parse:"path"`
UserID *string `json:"user_id" parse:"path"`
Status *string `json:"status" parse:"json"`
AppID string `json:"app_id" parse:"path"`
}
type AppUserDelete struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"`
AppID string `json:"app_id" parse:"path"`
}
type AppUserList struct {
AppID *string `json:"app_id" parse:"path"`
UserID *string `json:"user_id" parse:"path"`
UserID *string `json:"user_id" parse:"json"`
Status *string `json:"status" parse:"json"`
}
type AppUserPost struct {
AppID string `json:"app_id" parse:"path"`
UserID string `json:"user_id" parse:"path"`
Status string `json:"status" parse:"json"`
UserID string `json:"user_id" parse:"json"`
AppID string `json:"app_id" parse:"path"`
}
type ResourceList struct {
CreatedAt *time.Time `json:"created_at" parse:"query"`
UpdatedAt *time.Time `json:"updated_at" parse:"query"`
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"`
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"path"`
}
type ResourcePost struct {
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"`
Name string `json:"name" gorm:"primaryKey" parse:"json"`
Des string `json:"des" parse:"json"`
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"path"`
}
type ResourceDelete struct {
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"`
Name string `json:"name" gorm:"primaryKey" parse:"json"`
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"path"`
}
type ResourceGet struct {
AppID string `json:"app_id" parse:"path"`
}
type ResourcePatch struct {
AppID string `json:"app_id" parse:"path"`
}

@ -20,10 +20,10 @@ type App struct {
type AppUser struct {
BaseModel
AppID string `json:"app_id" methods:"get,*list,post" parse:"path"`
AppID string `json:"app_id" methods:"get,list,post,patch,delete" parse:"path"`
App *App `json:"-" gorm:"foreignKey:AppID;references:ID"`
UserID string `json:"user_id" methods:"get,*list,post" parse:"path"`
UserID string `json:"user_id" methods:"get,*list,post" parse:"json"`
User *User `json:"-" gorm:"foreignKey:UserID;references:ID"`
Status string `json:"status" methods:"post,*patch,*list" parse:"json"`
@ -63,7 +63,7 @@ func (m *AppUser) AfterUpdate(tx *gorm.DB) error {
type Resource struct {
BaseDate
AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" methods:"post,list,delete" parse:"json"`
AppID string `json:"app_id" methods:"get,list,post,patch,delete" parse:"path"`
App *App `json:"-" gorm:"foreignKey:AppID;references:ID"`
Name string `json:"name" gorm:"primaryKey" methods:"post,delete" parse:"json"`
Des string `json:"des" methods:"post" parse:"json"`

@ -2,12 +2,6 @@ package models
import ()
type UserLogin struct {
ID string `json:"id" parse:"path@user_id"`
Pwd string `json:"pwd" parse:"json"`
Typ string `json:"typ" parse:"json"`
}
type UserGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_id"`
}
@ -46,27 +40,30 @@ type UserList struct {
type UserRoleGet struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"`
UserID string `json:"user_id" parse:"path"`
}
type UserRolePatch struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"`
Status *string `json:"status" parse:"json"`
UserID string `json:"user_id" parse:"path"`
}
type UserRoleDelete struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"`
UserID string `json:"user_id" parse:"path"`
RoleID string `json:"role_id" parse:"path"`
RoleID string `json:"role_id" parse:"json"`
AppID string `json:"app_id" parse:"json"`
}
type UserRolePost struct {
UserID string `json:"user_id" parse:"path"`
RoleID string `json:"role_id" parse:"path"`
Status string `json:"status" parse:"json"`
RoleID string `json:"role_id" parse:"json"`
AppID string `json:"app_id" parse:"json"`
UserID string `json:"user_id" parse:"path"`
}
type UserRoleList struct {
Status *string `json:"status" parse:"json"`
UserID string `json:"user_id" parse:"path"`
}

@ -24,7 +24,7 @@ type User struct {
type UserRole struct {
BaseModel
UserID string `json:"user_id" methods:"post,delete" parse:"json"`
UserID string `json:"user_id" methods:"get,list,post,patch,delete" parse:"path"`
User *User `json:"-" gorm:"foreignKey:UserID;references:ID"`
RoleID string `json:"role_id" methods:"post,delete" parse:"json"`

1
oaweb/.gitignore vendored

@ -1,4 +1,5 @@
# Nuxt dev/build outputs
.nuxt
.output
.data
.nuxt

@ -0,0 +1,34 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-11 00:18:06
// Distributed under terms of the MIT license.
//
import webapi from "./webapi"
import * as models from "./models"
export interface ListOpts {
app_id: String
user_id?: String
role_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 interface PostOpts {
app_id: String
user_id?: String
role_id?: String
name: String
t_id: String
level: Number
}
export function Post(json: PostOpts) {
return webapi.Post<models.Access>(`/access`, { json })
}

@ -1,12 +1,112 @@
import webapi from "./gocliRequest"
import * as components from "./mainComponents"
export * from "./mainComponents"
/**
* @description
* @param params
* @param req
*/
export function login(pa: string, req: components.AppReq, params: components.AppReqParams) {
return webapi.get<components.AppResp>(`/api/app/login/${pa}`, {"params":params, "req":req})
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-11 00:18:06
// Distributed under terms of the MIT license.
//
import webapi from "./webapi"
import * as models from "./models"
export interface GetOpts {
name: String
}
export function Get(app_id: String, json: GetOpts) {
return webapi.Get<models.App>(`/app/${app_id}`, { json })
}
export function AppUserDelete(app_user_id: String, app_id: String) {
return webapi.Delete<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { })
}
export function ResourcePatch(app_id: String) {
return webapi.Patch<models.Resource>(`/app/${app_id}/resource`, { })
}
export interface PatchOpts {
name?: String
icon?: String
des?: String
participate?: String
init_role_id?: String
}
export function Patch(app_id: String, json: PatchOpts) {
return webapi.Patch<models.App>(`/app/${app_id}`, { json })
}
export interface PostOpts {
name: String
icon: String
des: String
participate: String
}
export function Post(json: PostOpts) {
return webapi.Post<models.App>(`/app`, { json })
}
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 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 interface ResourcePostOpts {
name: String
des: String
}
export function ResourcePost(app_id: String, json: ResourcePostOpts) {
return webapi.Post<models.Resource>(`/app/${app_id}/resource`, { json })
}
export function Delete(app_id: String) {
return webapi.Delete<models.App>(`/app/${app_id}`, { })
}
export interface ListOpts {
name?: String
}
export function List(json: ListOpts) {
return webapi.Get<models.App>(`/app`, { json })
}
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 ResourceGet(app_id: String) {
return webapi.Get<models.Resource>(`/app/${app_id}/resource`, { })
}
export interface AppUserPatchOpts {
status?: String
}
export function AppUserPatch(app_user_id: String, app_id: String, json: AppUserPatchOpts) {
return webapi.Patch<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { json })
}
export interface AppUserPostOpts {
status: String
user_id: String
}
export function AppUserPost(app_id: String, json: AppUserPostOpts) {
return webapi.Post<models.AppUser>(`/app/${app_id}/app_user`, { json })
}
export interface ResourceDeleteOpts {
name: String
}
export function ResourceDelete(app_id: String, json: ResourceDeleteOpts) {
return webapi.Delete<models.Resource>(`/app/${app_id}/resource`, { json })
}

@ -1,14 +1,13 @@
/*
* index.ts
* Copyright (C) 2024 veypi <i@veypi.com>
* 2024-08-02 17:40
* Distributed under terms of the MIT license.
*/
import * as user from './user'
import * as app from './app'
import * as user from "./user"
import * as token from "./token"
import * as role from "./role"
import * as app from "./app"
import * as access from "./access"
export default {
user,
app
token,
role,
app,
access
}

@ -1,47 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
export interface AppReq {
password: string
}
export interface AppReqParams {
username: string
}
export interface AppResp {
id: number
name: string
token: string
expireAt: string
}
export interface LoginReqParams {
pwd: string
client: string
typ: string
}
export interface RegReq {
username: string
pwd: string
}
export interface AuthHeaders {
authorization: string
}
export interface UserResp {
id: string
created: number
updated: number
username: string
nickname: string
email: string
phone: string
icon: string
status: number // 状态0ok1disabled
used: number
space: number
}

@ -0,0 +1,79 @@
export interface Access {
app_id: String
app?: App
user_id?: String
user?: User
role_id?: String
role?: Role
name: String
t_id: String
level: Number
}
export interface App {
name: String
icon: String
des: String
participate: String
init_role_id?: String
init_role?: Role
init_url: String
user_count: Number
key: String
}
export interface AppUser {
app_id: String
app?: App
user_id: String
user?: User
status: String
}
export interface Resource {
app_id: String
app?: App
name: String
des: String
}
export interface Role {
name: String
des: String
app_id: String
app?: App
user_count: Number
access: any
}
export interface Testb {
test_id: String
test?: Test
name: String
}
export interface Test {
name: String
}
export interface Token {
user_id: String
user?: User
app_id: String
app?: App
expired_at: Date
over_perm: String
device: String
}
export interface User {
username: String
nickname: String
icon: String
email: String
phone: String
status: Number
salt: String
code: String
}
export interface UserRole {
user_id: String
user?: User
role_id: String
role?: Role
app_id: String
app?: App
status: String
}

@ -0,0 +1,41 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-11 00:18:06
// Distributed under terms of the MIT license.
//
import webapi from "./webapi"
import * as models from "./models"
export interface ListOpts {
name?: String
}
export function List(json: ListOpts) {
return webapi.Get<models.Role>(`/role`, { json })
}
export function Get(role_id: String) {
return webapi.Get<models.Role>(`/role/${role_id}`, { })
}
export interface PatchOpts {
name?: String
des?: String
app_id?: String
}
export function Patch(role_id: String, json: PatchOpts) {
return webapi.Patch<models.Role>(`/role/${role_id}`, { json })
}
export function Delete(role_id: String) {
return webapi.Delete<models.Role>(`/role/${role_id}`, { })
}
export interface PostOpts {
name: String
des: String
app_id: String
}
export function Post(json: PostOpts) {
return webapi.Post<models.Role>(`/role`, { json })
}

@ -0,0 +1,56 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-11 00:18:06
// Distributed under terms of the MIT license.
//
import webapi from "./webapi"
import * as models from "./models"
export function Delete(token_id: String) {
return webapi.Delete<models.Token>(`/token/${token_id}`, {})
}
export interface ListOpts {
user_id: String
app_id: String
}
export function List(json: ListOpts) {
return webapi.Get<models.Token>(`/token`, { json })
}
export interface TokenSaltOpts {
username: String
typ?: String
}
// keep
export function TokenSalt(json: TokenSaltOpts) {
return webapi.Post<String>(`/token/salt`, { json })
}
export interface PostOpts {
user_id: String
token?: String
salt?: String
code?: String
app_id?: String
expired_at?: Date
over_perm?: String
device?: String
}
export function Post(json: PostOpts) {
return webapi.Post<models.Token>(`/token`, { json })
}
export function Get(token_id: String) {
return webapi.Get<models.Token>(`/token/${token_id}`, {})
}
export interface PatchOpts {
expired_at?: Date
over_perm?: String
}
export function Patch(token_id: String, json: PatchOpts) {
return webapi.Patch<models.Token>(`/token/${token_id}`, { json })
}

@ -1,33 +1,92 @@
import webapi from "./gocliRequest"
import * as components from "./mainComponents"
export * from "./mainComponents"
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-11 00:18:06
// Distributed under terms of the MIT license.
//
/**
* @description
* @param req
*/
export function reg(req: components.RegReq) {
return webapi.post<null>(`/api/user`, {"req":req})
import webapi from "./webapi"
import * as models from "./models"
export interface PostOpts {
username: String
nickname?: String
icon?: String
email?: String
phone?: String
salt: String
code: String
}
export function Post(json: PostOpts) {
return webapi.Post<models.User>(`/user`, { json })
}
export function UserRoleGet(user_role_id: String, user_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) {
return webapi.Patch<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, { json })
}
export interface UserRoleDeleteOpts {
role_id: String
app_id: String
}
export function UserRoleDelete(user_role_id: String, user_id: String, json: UserRoleDeleteOpts) {
return webapi.Delete<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, { json })
}
export interface UserRolePostOpts {
status: String
role_id: String
app_id: String
}
export function UserRolePost(user_id: String, json: UserRolePostOpts) {
return webapi.Post<models.UserRole>(`/user/${user_id}/user_role`, { json })
}
export interface UserLoginOpts {
pwd: String
typ: String
}
/**
* @description
* @param params
*/
export function login(id: string, params: components.LoginReqParams) {
return webapi.head<null>(`/api/user/${id}`, {"params":params})
export function Get(user_id: String) {
return webapi.Get<models.User>(`/user/${user_id}`, {})
}
/**
* @description
*/
export function list() {
return webapi.get<Array<components.UserResp>>(`/api/user`, {})
export function Delete(user_id: String) {
return webapi.Delete<models.User>(`/user/${user_id}`, {})
}
export interface UserRoleListOpts {
status?: String
}
export function UserRoleList(user_id: String, json: UserRoleListOpts) {
return webapi.Get<models.UserRole>(`/user/${user_id}/user_role`, { json })
}
/**
* @description
*/
export function get(id: number) {
return webapi.get<components.UserResp>(`/api/user/${id}`, {})
export interface PatchOpts {
username?: String
nickname?: String
icon?: String
email?: String
phone?: String
status?: Number
}
export function Patch(user_id: String, json: PatchOpts) {
return webapi.Patch<models.User>(`/user/${user_id}`, { json })
}
export interface ListOpts {
username?: String
nickname?: String
email?: String
phone?: String
status?: Number
}
export function List(json: ListOpts) {
return webapi.Get<models.User>(`/user`, { json })
}

@ -1,10 +1,8 @@
/*
* gocliRequest.ts
* Copyright (C) 2024 veypi <i@veypi.com>
* 2024-08-02 17:14
* Distributed under terms of the MIT license.
*/
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-11 00:21:45
// Distributed under terms of the MIT license.
//
import axios, { AxiosError, type AxiosResponse } from 'axios';
@ -18,6 +16,7 @@ import axios, { AxiosError, type AxiosResponse } from 'axios';
axios.defaults.withCredentials = true
const proxy = axios.create({
withCredentials: true,
baseURL: "/api/",
headers: {
'content-type': 'application/json;charset=UTF-8',
},
@ -84,36 +83,49 @@ const responseFailed = (error: AxiosError) => {
proxy.interceptors.response.use(responseSuccess, responseFailed)
interface data {
params?: any
req?: any
headers?: any
json?: any
query?: any
form?: any
header?: any
}
function transData(d: data) {
let opts = { params: d.query, data: {}, headers: {} as any }
if (d.form) {
opts.data = d.form
opts.headers['content-type'] = 'application/x-www-form-urlencoded'
}
if (d.json) {
opts.data = d.json
opts.headers['content-type'] = 'application/json'
}
if (d.header) {
opts.headers = Object.assign(opts.headers, d.header)
}
return opts
}
export const webapi = {
get<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>({ method: 'get', url: url, headers: req.headers, data: req.req, params: req.params })
Get<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>(Object.assign({ method: 'get', url: url }, transData(req)))
},
head<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>({ method: 'head', url: url, headers: req.headers, data: req.req, params: req.params })
Head<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>(Object.assign({ method: 'head', url: url }, transData(req)))
},
delete<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>({ method: 'delete', url: url, headers: req.headers, data: req.req, params: req.params })
Delete<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>(Object.assign({ method: 'delete', url: url }, transData(req)))
},
post<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>({ method: 'post', url: url, headers: req.headers, data: req.req, params: req.params })
Post<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>(Object.assign({ method: 'post', url: url }, transData(req)))
},
put<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>({ method: 'put', url: url, headers: req.headers, data: req.req, params: req.params })
Put<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>(Object.assign({ method: 'put', url: url }, transData(req)))
},
patch<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>({ method: 'patch', url: url, headers: req.headers, data: req.req, params: req.params })
Patch<T>(url: string, req: data): Promise<T> {
return proxy.request<T, any>(Object.assign({ method: 'patch', url: url }, transData(req)))
},
}
export default webapi

@ -6,7 +6,6 @@
*/
import api from './api'
export * from './models'
export { type Auths, type modelsSimpleAuth } from './models'
export { api }

@ -4,7 +4,14 @@ export default defineNuxtConfig({
css: [
'~/assets/css/app.scss',
'~/assets/css/tailwind.css',
],
postcss: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
ssr: false,
@ -46,5 +53,5 @@ export default defineNuxtConfig({
]
},
},
modules: ["@pinia/nuxt", "@nuxt/ui"]
modules: ["@pinia/nuxt"]
})

Loading…
Cancel
Save