改进 swag doc

增加 创建和列出 library
This commit is contained in:
Twilight 2024-07-15 01:22:40 +08:00
parent 0d613d24dd
commit df929aa104
31 changed files with 436 additions and 146 deletions

View File

@ -8,5 +8,8 @@ grpc-web:
grpcwebproxy --backend_addr=localhost:8081 --run_http_server --run_tls_server=false --server_http_debug_port 18081 --allow_all_origins --server_bind_address 127.0.0.1 grpcwebproxy --backend_addr=localhost:8081 --run_http_server --run_tls_server=false --server_http_debug_port 18081 --allow_all_origins --server_bind_address 127.0.0.1
install-deps: install-deps:
go install github.com/swaggo/swag/cmd/swag@latest go install github.com/swaggo/swag/cmd/swag@latest
curl -sSf https://atlasgo.sh | sh
swag: swag:
swag init -g internal/routes/router.go --parseDependency swag init -g internal/routes/router.go --parseDependency
hash-migration:
atlas migrate hash --dir "file://internal/migrations"

View File

@ -24,24 +24,86 @@ const docTemplate = `{
"host": "{{.Host}}", "host": "{{.Host}}",
"basePath": "{{.BasePath}}", "basePath": "{{.BasePath}}",
"paths": { "paths": {
"/": { "/library": {
"get": { "get": {
"summary": "获取当前用户的请求", "summary": "获取当前用户的资料库",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/models.CurrentUserResponse" "$ref": "#/definitions/models.ListLibraryResponse"
} }
} }
} }
} }
},
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"summary": "创建一个资料库",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.CreateLibraryResponse"
}
}
}
}
},
"/user": {
"get": {
"summary": "获取当前用户的请求",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.CurrentUserResponse"
}
}
}
} }
} }
}, },
"definitions": { "definitions": {
"ent.Library": {
"type": "object",
"properties": {
"created_at": {
"description": "CreatedAt holds the value of the \"created_at\" field.",
"type": "string"
},
"id": {
"description": "ID of the ent.",
"type": "integer"
},
"name": {
"description": "Name holds the value of the \"name\" field.",
"type": "string"
},
"updated_at": {
"description": "UpdatedAt holds the value of the \"updated_at\" field.",
"type": "string"
},
"user_id": {
"description": "UserID holds the value of the \"user_id\" field.",
"type": "string"
}
}
},
"models.CreateLibraryResponse": {
"type": "object",
"properties": {
"library": {
"$ref": "#/definitions/ent.Library"
}
}
},
"models.CurrentUserResponse": { "models.CurrentUserResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -58,6 +120,17 @@ const docTemplate = `{
"type": "boolean" "type": "boolean"
} }
} }
},
"models.ListLibraryResponse": {
"type": "object",
"properties": {
"libraries": {
"type": "array",
"items": {
"$ref": "#/definitions/ent.Library"
}
}
}
} }
}, },
"securityDefinitions": { "securityDefinitions": {
@ -74,7 +147,7 @@ const docTemplate = `{
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "1.0", Version: "1.0",
Host: "localhost:8080", Host: "localhost:8080",
BasePath: "/", BasePath: "/api/v1",
Schemes: []string{}, Schemes: []string{},
Title: "Swagger Example API", Title: "Swagger Example API",
Description: "This is a sample server celler server.", Description: "This is a sample server celler server.",

View File

@ -16,26 +16,88 @@
"version": "1.0" "version": "1.0"
}, },
"host": "localhost:8080", "host": "localhost:8080",
"basePath": "/", "basePath": "/api/v1",
"paths": { "paths": {
"/": { "/library": {
"get": { "get": {
"summary": "获取当前用户的请求", "summary": "获取当前用户的资料库",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/models.CurrentUserResponse" "$ref": "#/definitions/models.ListLibraryResponse"
} }
} }
} }
} }
},
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"summary": "创建一个资料库",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.CreateLibraryResponse"
}
}
}
}
},
"/user": {
"get": {
"summary": "获取当前用户的请求",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.CurrentUserResponse"
}
}
}
} }
} }
}, },
"definitions": { "definitions": {
"ent.Library": {
"type": "object",
"properties": {
"created_at": {
"description": "CreatedAt holds the value of the \"created_at\" field.",
"type": "string"
},
"id": {
"description": "ID of the ent.",
"type": "integer"
},
"name": {
"description": "Name holds the value of the \"name\" field.",
"type": "string"
},
"updated_at": {
"description": "UpdatedAt holds the value of the \"updated_at\" field.",
"type": "string"
},
"user_id": {
"description": "UserID holds the value of the \"user_id\" field.",
"type": "string"
}
}
},
"models.CreateLibraryResponse": {
"type": "object",
"properties": {
"library": {
"$ref": "#/definitions/ent.Library"
}
}
},
"models.CurrentUserResponse": { "models.CurrentUserResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -52,6 +114,17 @@
"type": "boolean" "type": "boolean"
} }
} }
},
"models.ListLibraryResponse": {
"type": "object",
"properties": {
"libraries": {
"type": "array",
"items": {
"$ref": "#/definitions/ent.Library"
}
}
}
} }
}, },
"securityDefinitions": { "securityDefinitions": {

View File

@ -1,5 +1,28 @@
basePath: / basePath: /api/v1
definitions: definitions:
ent.Library:
properties:
created_at:
description: CreatedAt holds the value of the "created_at" field.
type: string
id:
description: ID of the ent.
type: integer
name:
description: Name holds the value of the "name" field.
type: string
updated_at:
description: UpdatedAt holds the value of the "updated_at" field.
type: string
user_id:
description: UserID holds the value of the "user_id" field.
type: string
type: object
models.CreateLibraryResponse:
properties:
library:
$ref: '#/definitions/ent.Library'
type: object
models.CurrentUserResponse: models.CurrentUserResponse:
properties: properties:
ip: ip:
@ -11,6 +34,13 @@ definitions:
valid: valid:
type: boolean type: boolean
type: object type: object
models.ListLibraryResponse:
properties:
libraries:
items:
$ref: '#/definitions/ent.Library'
type: array
type: object
host: localhost:8080 host: localhost:8080
info: info:
contact: contact:
@ -25,15 +55,32 @@ info:
title: Swagger Example API title: Swagger Example API
version: "1.0" version: "1.0"
paths: paths:
/: /library:
get: get:
responses: responses:
"200": "200":
description: OK description: OK
schema: schema:
items: items:
$ref: '#/definitions/models.CurrentUserResponse' $ref: '#/definitions/models.ListLibraryResponse'
type: array type: array
summary: 获取当前用户的资料库
post:
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.CreateLibraryResponse'
security:
- ApiKeyAuth: []
summary: 创建一个资料库
/user:
get:
responses:
"200":
description: OK
schema:
$ref: '#/definitions/models.CurrentUserResponse'
summary: 获取当前用户的请求 summary: 获取当前用户的请求
securityDefinitions: securityDefinitions:
ApiKeyAuth: ApiKeyAuth:

View File

@ -11,11 +11,10 @@ import (
"leafdev.top/leaf/rag/ent/migrate" "leafdev.top/leaf/rag/ent/migrate"
"leafdev.top/leaf/rag/ent/library"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect" "entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"leafdev.top/leaf/rag/ent/library"
) )
// Client is the client that holds all ent builders. // Client is the client that holds all ent builders.

View File

@ -6,13 +6,13 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"leafdev.top/leaf/rag/ent/library"
"reflect" "reflect"
"sync" "sync"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"leafdev.top/leaf/rag/ent/library"
) )
// ent aliases to avoid import conflicts in user's code. // ent aliases to avoid import conflicts in user's code.

View File

@ -4,13 +4,13 @@ package enttest
import ( import (
"context" "context"
"leafdev.top/leaf/rag/ent" "leafdev.top/leaf/rag/ent"
// required by schema hooks. // required by schema hooks.
_ "leafdev.top/leaf/rag/ent/runtime" _ "leafdev.top/leaf/rag/ent/runtime"
"leafdev.top/leaf/rag/ent/migrate"
"entgo.io/ent/dialect/sql/schema" "entgo.io/ent/dialect/sql/schema"
"leafdev.top/leaf/rag/ent/migrate"
) )
type ( type (

View File

@ -5,6 +5,7 @@ package hook
import ( import (
"context" "context"
"fmt" "fmt"
"leafdev.top/leaf/rag/ent" "leafdev.top/leaf/rag/ent"
) )

View File

@ -4,12 +4,12 @@ package ent
import ( import (
"fmt" "fmt"
"leafdev.top/leaf/rag/ent/library"
"strings" "strings"
"time" "time"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"leafdev.top/leaf/rag/ent/library"
) )
// Library is the model entity for the Library schema. // Library is the model entity for the Library schema.
@ -20,7 +20,7 @@ type Library struct {
// Name holds the value of the "name" field. // Name holds the value of the "name" field.
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
// UserID holds the value of the "user_id" field. // UserID holds the value of the "user_id" field.
UserID uint64 `json:"user_id,omitempty"` UserID string `json:"user_id,omitempty"`
// CreatedAt holds the value of the "created_at" field. // CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field. // UpdatedAt holds the value of the "updated_at" field.
@ -33,9 +33,9 @@ func (*Library) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns)) values := make([]any, len(columns))
for i := range columns { for i := range columns {
switch columns[i] { switch columns[i] {
case library.FieldID, library.FieldUserID: case library.FieldID:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case library.FieldName: case library.FieldName, library.FieldUserID:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
case library.FieldCreatedAt, library.FieldUpdatedAt: case library.FieldCreatedAt, library.FieldUpdatedAt:
values[i] = new(sql.NullTime) values[i] = new(sql.NullTime)
@ -67,10 +67,10 @@ func (l *Library) assignValues(columns []string, values []any) error {
l.Name = value.String l.Name = value.String
} }
case library.FieldUserID: case library.FieldUserID:
if value, ok := values[i].(*sql.NullInt64); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i]) return fmt.Errorf("unexpected type %T for field user_id", values[i])
} else if value.Valid { } else if value.Valid {
l.UserID = uint64(value.Int64) l.UserID = value.String
} }
case library.FieldCreatedAt: case library.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok { if value, ok := values[i].(*sql.NullTime); !ok {
@ -124,7 +124,7 @@ func (l *Library) String() string {
builder.WriteString(l.Name) builder.WriteString(l.Name)
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("user_id=") builder.WriteString("user_id=")
builder.WriteString(fmt.Sprintf("%v", l.UserID)) builder.WriteString(l.UserID)
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("created_at=") builder.WriteString("created_at=")
builder.WriteString(l.CreatedAt.Format(time.ANSIC)) builder.WriteString(l.CreatedAt.Format(time.ANSIC))

View File

@ -3,10 +3,10 @@
package library package library
import ( import (
"leafdev.top/leaf/rag/ent/predicate"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"leafdev.top/leaf/rag/ent/predicate"
) )
// ID filters vertices based on their ID field. // ID filters vertices based on their ID field.
@ -60,7 +60,7 @@ func Name(v string) predicate.Library {
} }
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. // UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
func UserID(v uint64) predicate.Library { func UserID(v string) predicate.Library {
return predicate.Library(sql.FieldEQ(FieldUserID, v)) return predicate.Library(sql.FieldEQ(FieldUserID, v))
} }
@ -140,45 +140,70 @@ func NameContainsFold(v string) predicate.Library {
} }
// UserIDEQ applies the EQ predicate on the "user_id" field. // UserIDEQ applies the EQ predicate on the "user_id" field.
func UserIDEQ(v uint64) predicate.Library { func UserIDEQ(v string) predicate.Library {
return predicate.Library(sql.FieldEQ(FieldUserID, v)) return predicate.Library(sql.FieldEQ(FieldUserID, v))
} }
// UserIDNEQ applies the NEQ predicate on the "user_id" field. // UserIDNEQ applies the NEQ predicate on the "user_id" field.
func UserIDNEQ(v uint64) predicate.Library { func UserIDNEQ(v string) predicate.Library {
return predicate.Library(sql.FieldNEQ(FieldUserID, v)) return predicate.Library(sql.FieldNEQ(FieldUserID, v))
} }
// UserIDIn applies the In predicate on the "user_id" field. // UserIDIn applies the In predicate on the "user_id" field.
func UserIDIn(vs ...uint64) predicate.Library { func UserIDIn(vs ...string) predicate.Library {
return predicate.Library(sql.FieldIn(FieldUserID, vs...)) return predicate.Library(sql.FieldIn(FieldUserID, vs...))
} }
// UserIDNotIn applies the NotIn predicate on the "user_id" field. // UserIDNotIn applies the NotIn predicate on the "user_id" field.
func UserIDNotIn(vs ...uint64) predicate.Library { func UserIDNotIn(vs ...string) predicate.Library {
return predicate.Library(sql.FieldNotIn(FieldUserID, vs...)) return predicate.Library(sql.FieldNotIn(FieldUserID, vs...))
} }
// UserIDGT applies the GT predicate on the "user_id" field. // UserIDGT applies the GT predicate on the "user_id" field.
func UserIDGT(v uint64) predicate.Library { func UserIDGT(v string) predicate.Library {
return predicate.Library(sql.FieldGT(FieldUserID, v)) return predicate.Library(sql.FieldGT(FieldUserID, v))
} }
// UserIDGTE applies the GTE predicate on the "user_id" field. // UserIDGTE applies the GTE predicate on the "user_id" field.
func UserIDGTE(v uint64) predicate.Library { func UserIDGTE(v string) predicate.Library {
return predicate.Library(sql.FieldGTE(FieldUserID, v)) return predicate.Library(sql.FieldGTE(FieldUserID, v))
} }
// UserIDLT applies the LT predicate on the "user_id" field. // UserIDLT applies the LT predicate on the "user_id" field.
func UserIDLT(v uint64) predicate.Library { func UserIDLT(v string) predicate.Library {
return predicate.Library(sql.FieldLT(FieldUserID, v)) return predicate.Library(sql.FieldLT(FieldUserID, v))
} }
// UserIDLTE applies the LTE predicate on the "user_id" field. // UserIDLTE applies the LTE predicate on the "user_id" field.
func UserIDLTE(v uint64) predicate.Library { func UserIDLTE(v string) predicate.Library {
return predicate.Library(sql.FieldLTE(FieldUserID, v)) return predicate.Library(sql.FieldLTE(FieldUserID, v))
} }
// UserIDContains applies the Contains predicate on the "user_id" field.
func UserIDContains(v string) predicate.Library {
return predicate.Library(sql.FieldContains(FieldUserID, v))
}
// UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field.
func UserIDHasPrefix(v string) predicate.Library {
return predicate.Library(sql.FieldHasPrefix(FieldUserID, v))
}
// UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field.
func UserIDHasSuffix(v string) predicate.Library {
return predicate.Library(sql.FieldHasSuffix(FieldUserID, v))
}
// UserIDEqualFold applies the EqualFold predicate on the "user_id" field.
func UserIDEqualFold(v string) predicate.Library {
return predicate.Library(sql.FieldEqualFold(FieldUserID, v))
}
// UserIDContainsFold applies the ContainsFold predicate on the "user_id" field.
func UserIDContainsFold(v string) predicate.Library {
return predicate.Library(sql.FieldContainsFold(FieldUserID, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field. // CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Library { func CreatedAtEQ(v time.Time) predicate.Library {
return predicate.Library(sql.FieldEQ(FieldCreatedAt, v)) return predicate.Library(sql.FieldEQ(FieldCreatedAt, v))

View File

@ -6,11 +6,11 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"leafdev.top/leaf/rag/ent/library"
"time" "time"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/library"
) )
// LibraryCreate is the builder for creating a Library entity. // LibraryCreate is the builder for creating a Library entity.
@ -27,8 +27,8 @@ func (lc *LibraryCreate) SetName(s string) *LibraryCreate {
} }
// SetUserID sets the "user_id" field. // SetUserID sets the "user_id" field.
func (lc *LibraryCreate) SetUserID(u uint64) *LibraryCreate { func (lc *LibraryCreate) SetUserID(s string) *LibraryCreate {
lc.mutation.SetUserID(u) lc.mutation.SetUserID(s)
return lc return lc
} }
@ -150,7 +150,7 @@ func (lc *LibraryCreate) createSpec() (*Library, *sqlgraph.CreateSpec) {
_node.Name = value _node.Name = value
} }
if value, ok := lc.mutation.UserID(); ok { if value, ok := lc.mutation.UserID(); ok {
_spec.SetField(library.FieldUserID, field.TypeUint64, value) _spec.SetField(library.FieldUserID, field.TypeString, value)
_node.UserID = value _node.UserID = value
} }
if value, ok := lc.mutation.CreatedAt(); ok { if value, ok := lc.mutation.CreatedAt(); ok {

View File

@ -4,12 +4,12 @@ package ent
import ( import (
"context" "context"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
) )
// LibraryDelete is the builder for deleting a Library entity. // LibraryDelete is the builder for deleting a Library entity.

View File

@ -5,13 +5,13 @@ package ent
import ( import (
"context" "context"
"fmt" "fmt"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
"math" "math"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
) )
// LibraryQuery is the builder for querying Library entities. // LibraryQuery is the builder for querying Library entities.

View File

@ -6,13 +6,13 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
) )
// LibraryUpdate is the builder for updating Library entities. // LibraryUpdate is the builder for updating Library entities.
@ -43,26 +43,19 @@ func (lu *LibraryUpdate) SetNillableName(s *string) *LibraryUpdate {
} }
// SetUserID sets the "user_id" field. // SetUserID sets the "user_id" field.
func (lu *LibraryUpdate) SetUserID(u uint64) *LibraryUpdate { func (lu *LibraryUpdate) SetUserID(s string) *LibraryUpdate {
lu.mutation.ResetUserID() lu.mutation.SetUserID(s)
lu.mutation.SetUserID(u)
return lu return lu
} }
// SetNillableUserID sets the "user_id" field if the given value is not nil. // SetNillableUserID sets the "user_id" field if the given value is not nil.
func (lu *LibraryUpdate) SetNillableUserID(u *uint64) *LibraryUpdate { func (lu *LibraryUpdate) SetNillableUserID(s *string) *LibraryUpdate {
if u != nil { if s != nil {
lu.SetUserID(*u) lu.SetUserID(*s)
} }
return lu return lu
} }
// AddUserID adds u to the "user_id" field.
func (lu *LibraryUpdate) AddUserID(u int64) *LibraryUpdate {
lu.mutation.AddUserID(u)
return lu
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (lu *LibraryUpdate) SetCreatedAt(t time.Time) *LibraryUpdate { func (lu *LibraryUpdate) SetCreatedAt(t time.Time) *LibraryUpdate {
lu.mutation.SetCreatedAt(t) lu.mutation.SetCreatedAt(t)
@ -136,10 +129,7 @@ func (lu *LibraryUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec.SetField(library.FieldName, field.TypeString, value) _spec.SetField(library.FieldName, field.TypeString, value)
} }
if value, ok := lu.mutation.UserID(); ok { if value, ok := lu.mutation.UserID(); ok {
_spec.SetField(library.FieldUserID, field.TypeUint64, value) _spec.SetField(library.FieldUserID, field.TypeString, value)
}
if value, ok := lu.mutation.AddedUserID(); ok {
_spec.AddField(library.FieldUserID, field.TypeUint64, value)
} }
if value, ok := lu.mutation.CreatedAt(); ok { if value, ok := lu.mutation.CreatedAt(); ok {
_spec.SetField(library.FieldCreatedAt, field.TypeTime, value) _spec.SetField(library.FieldCreatedAt, field.TypeTime, value)
@ -182,26 +172,19 @@ func (luo *LibraryUpdateOne) SetNillableName(s *string) *LibraryUpdateOne {
} }
// SetUserID sets the "user_id" field. // SetUserID sets the "user_id" field.
func (luo *LibraryUpdateOne) SetUserID(u uint64) *LibraryUpdateOne { func (luo *LibraryUpdateOne) SetUserID(s string) *LibraryUpdateOne {
luo.mutation.ResetUserID() luo.mutation.SetUserID(s)
luo.mutation.SetUserID(u)
return luo return luo
} }
// SetNillableUserID sets the "user_id" field if the given value is not nil. // SetNillableUserID sets the "user_id" field if the given value is not nil.
func (luo *LibraryUpdateOne) SetNillableUserID(u *uint64) *LibraryUpdateOne { func (luo *LibraryUpdateOne) SetNillableUserID(s *string) *LibraryUpdateOne {
if u != nil { if s != nil {
luo.SetUserID(*u) luo.SetUserID(*s)
} }
return luo return luo
} }
// AddUserID adds u to the "user_id" field.
func (luo *LibraryUpdateOne) AddUserID(u int64) *LibraryUpdateOne {
luo.mutation.AddUserID(u)
return luo
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (luo *LibraryUpdateOne) SetCreatedAt(t time.Time) *LibraryUpdateOne { func (luo *LibraryUpdateOne) SetCreatedAt(t time.Time) *LibraryUpdateOne {
luo.mutation.SetCreatedAt(t) luo.mutation.SetCreatedAt(t)
@ -305,10 +288,7 @@ func (luo *LibraryUpdateOne) sqlSave(ctx context.Context) (_node *Library, err e
_spec.SetField(library.FieldName, field.TypeString, value) _spec.SetField(library.FieldName, field.TypeString, value)
} }
if value, ok := luo.mutation.UserID(); ok { if value, ok := luo.mutation.UserID(); ok {
_spec.SetField(library.FieldUserID, field.TypeUint64, value) _spec.SetField(library.FieldUserID, field.TypeString, value)
}
if value, ok := luo.mutation.AddedUserID(); ok {
_spec.AddField(library.FieldUserID, field.TypeUint64, value)
} }
if value, ok := luo.mutation.CreatedAt(); ok { if value, ok := luo.mutation.CreatedAt(); ok {
_spec.SetField(library.FieldCreatedAt, field.TypeTime, value) _spec.SetField(library.FieldCreatedAt, field.TypeTime, value)

View File

@ -12,7 +12,7 @@ var (
LibrariesColumns = []*schema.Column{ LibrariesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "name", Type: field.TypeString}, {Name: "name", Type: field.TypeString},
{Name: "user_id", Type: field.TypeUint64}, {Name: "user_id", Type: field.TypeString},
{Name: "created_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime},
} }

View File

@ -6,13 +6,13 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
"sync" "sync"
"time" "time"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
) )
const ( const (
@ -34,8 +34,7 @@ type LibraryMutation struct {
typ string typ string
id *int id *int
name *string name *string
user_id *uint64 user_id *string
adduser_id *int64
created_at *time.Time created_at *time.Time
updated_at *time.Time updated_at *time.Time
clearedFields map[string]struct{} clearedFields map[string]struct{}
@ -179,13 +178,12 @@ func (m *LibraryMutation) ResetName() {
} }
// SetUserID sets the "user_id" field. // SetUserID sets the "user_id" field.
func (m *LibraryMutation) SetUserID(u uint64) { func (m *LibraryMutation) SetUserID(s string) {
m.user_id = &u m.user_id = &s
m.adduser_id = nil
} }
// UserID returns the value of the "user_id" field in the mutation. // UserID returns the value of the "user_id" field in the mutation.
func (m *LibraryMutation) UserID() (r uint64, exists bool) { func (m *LibraryMutation) UserID() (r string, exists bool) {
v := m.user_id v := m.user_id
if v == nil { if v == nil {
return return
@ -196,7 +194,7 @@ func (m *LibraryMutation) UserID() (r uint64, exists bool) {
// OldUserID returns the old "user_id" field's value of the Library entity. // OldUserID returns the old "user_id" field's value of the Library entity.
// If the Library object wasn't provided to the builder, the object is fetched from the database. // If the Library object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *LibraryMutation) OldUserID(ctx context.Context) (v uint64, err error) { func (m *LibraryMutation) OldUserID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) { if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations") return v, errors.New("OldUserID is only allowed on UpdateOne operations")
} }
@ -210,28 +208,9 @@ func (m *LibraryMutation) OldUserID(ctx context.Context) (v uint64, err error) {
return oldValue.UserID, nil return oldValue.UserID, nil
} }
// AddUserID adds u to the "user_id" field.
func (m *LibraryMutation) AddUserID(u int64) {
if m.adduser_id != nil {
*m.adduser_id += u
} else {
m.adduser_id = &u
}
}
// AddedUserID returns the value that was added to the "user_id" field in this mutation.
func (m *LibraryMutation) AddedUserID() (r int64, exists bool) {
v := m.adduser_id
if v == nil {
return
}
return *v, true
}
// ResetUserID resets all changes to the "user_id" field. // ResetUserID resets all changes to the "user_id" field.
func (m *LibraryMutation) ResetUserID() { func (m *LibraryMutation) ResetUserID() {
m.user_id = nil m.user_id = nil
m.adduser_id = nil
} }
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
@ -403,7 +382,7 @@ func (m *LibraryMutation) SetField(name string, value ent.Value) error {
m.SetName(v) m.SetName(v)
return nil return nil
case library.FieldUserID: case library.FieldUserID:
v, ok := value.(uint64) v, ok := value.(string)
if !ok { if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name) return fmt.Errorf("unexpected type %T for field %s", value, name)
} }
@ -430,21 +409,13 @@ func (m *LibraryMutation) SetField(name string, value ent.Value) error {
// AddedFields returns all numeric fields that were incremented/decremented during // AddedFields returns all numeric fields that were incremented/decremented during
// this mutation. // this mutation.
func (m *LibraryMutation) AddedFields() []string { func (m *LibraryMutation) AddedFields() []string {
var fields []string return nil
if m.adduser_id != nil {
fields = append(fields, library.FieldUserID)
}
return fields
} }
// AddedField returns the numeric value that was incremented/decremented on a field // AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field // with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema. // was not set, or was not defined in the schema.
func (m *LibraryMutation) AddedField(name string) (ent.Value, bool) { func (m *LibraryMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case library.FieldUserID:
return m.AddedUserID()
}
return nil, false return nil, false
} }
@ -453,13 +424,6 @@ func (m *LibraryMutation) AddedField(name string) (ent.Value, bool) {
// type. // type.
func (m *LibraryMutation) AddField(name string, value ent.Value) error { func (m *LibraryMutation) AddField(name string, value ent.Value) error {
switch name { switch name {
case library.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddUserID(v)
return nil
} }
return fmt.Errorf("unknown Library numeric field %s", name) return fmt.Errorf("unknown Library numeric field %s", name)
} }

View File

@ -3,9 +3,10 @@
package ent package ent
import ( import (
"time"
"leafdev.top/leaf/rag/ent/library" "leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/schema" "leafdev.top/leaf/rag/ent/schema"
"time"
) )
// The init function reads all schema descriptors with runtime code // The init function reads all schema descriptors with runtime code

View File

@ -2,7 +2,7 @@
package runtime package runtime
// The schema-stitching logic is generated in framework_v2/ent/runtime.go // The schema-stitching logic is generated in leafdev.top/leaf/rag/ent/runtime.go
const ( const (
Version = "v0.13.1" // Version of ent codegen. Version = "v0.13.1" // Version of ent codegen.

View File

@ -16,7 +16,7 @@ type Library struct {
func (Library) Fields() []ent.Field { func (Library) Fields() []ent.Field {
return []ent.Field{ return []ent.Field{
field.String("name"), field.String("name"),
field.Uint64("user_id"), field.String("user_id"),
field.Time("created_at").Default(time.Now), field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now), field.Time("updated_at").Default(time.Now),
} }

4
go.sum
View File

@ -150,6 +150,8 @@ github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY= github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
@ -170,6 +172,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

View File

@ -1,6 +1,13 @@
package library package library
import "github.com/gin-gonic/gin" import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"leafdev.top/leaf/rag/internal/logic"
"leafdev.top/leaf/rag/internal/providers/helper"
"leafdev.top/leaf/rag/models"
"net/http"
)
type Controller struct { type Controller struct {
} }
@ -9,11 +16,59 @@ func NewLibraryController() *Controller {
return &Controller{} return &Controller{}
} }
var libraryLogic = logic.NewLibraryLogic()
// Library 获取当前用户的资料库 godoc // Library 获取当前用户的资料库 godoc
// @Success 200 {array} models.CurrentUserResponse // @Summary 获取当前用户的资料库
// @Router / [get] // @Success 200 {array} models.ListLibraryResponse
// @Router /library [get]
func (c *Controller) Library(ctx *gin.Context) { func (c *Controller) Library(ctx *gin.Context) {
ctx.JSON(200, gin.H{ libraries, _ := libraryLogic.ListLibrary(ctx)
"message": "ok",
libraryResponse := models.ListLibraryResponse{
Libraries: libraries,
}
//helper.Response(ctx, http.StatusOK, libraryResponse)
ctx.JSON(http.StatusOK, libraryResponse)
}
// CreateLibrary 创建一个资料库 godoc
// @Summary 创建一个资料库
// @Security ApiKeyAuth
// @Success 200 {object} models.CreateLibraryResponse
// @Router /library [post]
func (c *Controller) CreateLibrary(ctx *gin.Context) {
var createLibraryReq models.CreateLibraryRequest
err := ctx.ShouldBindBodyWithJSON(&createLibraryReq)
if err != nil {
helper.ResponseError(ctx, http.StatusBadRequest, err)
return
}
library, err := libraryLogic.CreateLibrary(ctx, createLibraryReq.Name)
if err != nil {
helper.ResponseError(ctx, http.StatusInternalServerError, err)
return
}
//helper.Response(ctx, http.StatusCreated, models.CreateLibraryResponse{
// Library: library,
//})
ctx.JSON(http.StatusOK, models.CreateLibraryResponse{
Library: library,
}) })
} }
func MustBindBodyWithJSON(ctx *gin.Context, obj interface{}) error {
err := ctx.ShouldBindBodyWith(obj, binding.JSON)
if err != nil {
helper.ResponseError(ctx, http.StatusBadRequest, err)
return err
}
return err
}

View File

@ -4,6 +4,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"leafdev.top/leaf/rag/internal/logic" "leafdev.top/leaf/rag/internal/logic"
"leafdev.top/leaf/rag/models" "leafdev.top/leaf/rag/models"
"net/http"
) )
var AuthLogic = logic.NewAuthLogic() var AuthLogic = logic.NewAuthLogic()
@ -16,11 +17,11 @@ func NewUserController() *Controller {
// CurrentUser 获取当前用户 godoc // CurrentUser 获取当前用户 godoc
// @Summary 获取当前用户的请求 // @Summary 获取当前用户的请求
// @Success 200 {array} models.CurrentUserResponse // @Success 200 {object} models.CurrentUserResponse
// @Router / [get] // @Router /user [get]
func (c *Controller) CurrentUser(ctx *gin.Context) { func (c *Controller) CurrentUser(ctx *gin.Context) {
var user = AuthLogic.GinUser(ctx) var user = AuthLogic.GinUser(ctx)
ctx.JSON(200, models.CurrentUserResponse{ ctx.JSON(http.StatusOK, models.CurrentUserResponse{
IP: ctx.ClientIP(), IP: ctx.ClientIP(),
Valid: user.Valid, Valid: user.Valid,
UserEmail: user.Token.Email, UserEmail: user.Token.Email,

View File

@ -83,3 +83,8 @@ func (a *AuthLogic) GinUser(c *gin.Context) *models.User {
user, _ := c.Get(consts.AuthMiddlewareKey) user, _ := c.Get(consts.AuthMiddlewareKey)
return user.(*models.User) return user.(*models.User)
} }
func GetUserId(ctx *gin.Context) string {
logic := AuthLogic{}
return logic.GinUser(ctx).Token.Sub
}

1
internal/logic/base.go Normal file
View File

@ -0,0 +1 @@
package logic

28
internal/logic/library.go Normal file
View File

@ -0,0 +1,28 @@
package logic
import (
"github.com/gin-gonic/gin"
"leafdev.top/leaf/rag/ent"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/internal/providers"
)
type LibraryLogic struct {
}
var client = providers.MustGet[ent.Client]()
func NewLibraryLogic() *LibraryLogic {
return &LibraryLogic{}
}
func (l *LibraryLogic) ListLibrary(ctx *gin.Context) ([]*ent.Library, error) {
return client.Library.Query().Where(library.UserID(GetUserId(ctx))).All(ctx)
}
func (l *LibraryLogic) CreateLibrary(ctx *gin.Context, name string) (*ent.Library, error) {
return client.Library.Create().
SetName(name).
SetUserID(GetUserId(ctx)).
Save(ctx)
}

View File

@ -0,0 +1,7 @@
-- +goose Up
-- modify "libraries" table
ALTER TABLE "libraries" ALTER COLUMN "user_id" TYPE character varying;
-- +goose Down
-- reverse: modify "libraries" table
ALTER TABLE "libraries" ALTER COLUMN "user_id" TYPE bigint;

View File

@ -1,2 +1,3 @@
h1:UUSMLWHMuU9uMY48Lb2EYjpQSZk/Ngn7OEjDSH7UQlA= h1:gAvB+J97CWicumiwquwzeenMmWbnkb2SkIa7TZ9+r2w=
20240714155720_create_library.sql h1:JzdeQPcsm2609MV/6DbYu5N7tg583qpxoaXgFtazOzE= 20240714155720_create_library.sql h1:JzdeQPcsm2609MV/6DbYu5N7tg583qpxoaXgFtazOzE=
20240714164619_update_user_id.sql h1:YiqNbf8FcKJCH9cj3PIFqOtr/pqzLKJgXza8nw8iO/w=

View File

@ -2,11 +2,11 @@ package helper
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"leafdev.top/leaf/rag/internal/providers/response" "leafdev.top/leaf/rag/models"
) )
func ResponseMessage(c *gin.Context, code int, message string, data interface{}) { func ResponseMessage(c *gin.Context, code int, message string, data interface{}) {
c.JSON(code, &response.BaseResponse{ c.JSON(code, &models.BaseResponse{
Message: message, Message: message,
Code: code, Code: code,
Data: data, Data: data,
@ -15,7 +15,7 @@ func ResponseMessage(c *gin.Context, code int, message string, data interface{})
} }
func Response(c *gin.Context, code int, data interface{}) { func Response(c *gin.Context, code int, data interface{}) {
c.JSON(code, &response.BaseResponse{ c.JSON(code, &models.BaseResponse{
Code: code, Code: code,
Data: data, Data: data,
}) })
@ -23,7 +23,7 @@ func Response(c *gin.Context, code int, data interface{}) {
} }
func ResponseError(c *gin.Context, code int, err error) { func ResponseError(c *gin.Context, code int, err error) {
c.JSON(code, &response.BaseResponse{ c.JSON(code, &models.BaseResponse{
Error: err.Error(), Error: err.Error(),
Code: code, Code: code,
}) })

View File

@ -5,11 +5,15 @@ import (
swaggerFiles "github.com/swaggo/files" swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger" ginSwagger "github.com/swaggo/gin-swagger"
_ "leafdev.top/leaf/rag/docs" _ "leafdev.top/leaf/rag/docs"
"leafdev.top/leaf/rag/internal/handlers/controllers/library"
"leafdev.top/leaf/rag/internal/handlers/controllers/user" "leafdev.top/leaf/rag/internal/handlers/controllers/user"
"leafdev.top/leaf/rag/internal/middleware/http" "leafdev.top/leaf/rag/internal/middleware/http"
"leafdev.top/leaf/rag/internal/providers" "leafdev.top/leaf/rag/internal/providers"
) )
var userController = user.NewUserController()
var libraryController = library.NewLibraryController()
// @title Swagger Example API // @title Swagger Example API
// @version 1.0 // @version 1.0
// @description This is a sample server celler server. // @description This is a sample server celler server.
@ -23,7 +27,7 @@ import (
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080 // @host localhost:8080
// @BasePath / // @BasePath /api/v1
// @securityDefinitions.apikey ApiKeyAuth // @securityDefinitions.apikey ApiKeyAuth
// //
@ -34,9 +38,17 @@ import (
func InitApiRoutes() { func InitApiRoutes() {
var r = *providers.MustGet[gin.Engine]() var r = *providers.MustGet[gin.Engine]()
var userController = user.NewUserController() r.Use(http.MiddlewareJSONResponse)
// middleware group
authorizedApiV1 := r.Group("/api/v1")
authorizedApiV1.Use(http.RequireJWTIDToken)
{
authorizedApiV1.GET("/user", userController.CurrentUser)
authorizedApiV1.GET("/library", libraryController.Library)
authorizedApiV1.POST("/library", libraryController.CreateLibrary)
}
r.GET("/", http.MiddlewareJSONResponse, http.RequireJWTIDToken, userController.CurrentUser)
} }
// InitSwaggerRoutes init swagger routes // InitSwaggerRoutes init swagger routes

View File

@ -1,4 +1,4 @@
package response package models
type BaseResponse struct { type BaseResponse struct {
Message string `json:"message"` Message string `json:"message"`

View File

@ -1,16 +1,26 @@
package models package models
import "leafdev.top/leaf/rag/ent"
type ListLibraryRequest struct { type ListLibraryRequest struct {
} }
type ListLibraryResponse struct { type ListLibraryResponse struct {
Libraries []LibraryRequest `json:"libraries"` Libraries []*ent.Library `json:"libraries"`
}
type CreateLibraryRequest struct {
Name string `json:"name" binding:"required"`
}
type CreateLibraryResponse struct {
Library *ent.Library `json:"library"`
} }
type Library struct { type Library struct {
LibraryName string `json:"libraryName"` Id int `json:"libraryName"`
LibraryID string `json:"libraryId"` LibraryID string `json:"libraryId"`
Valid bool `json:"valid"` Valid bool `json:"valid"`
} }
type LibraryRequest struct { type LibraryRequest struct {