init
This commit is contained in:
parent
6cf09d6375
commit
f2efea4ed1
@ -26,6 +26,7 @@ import (
|
||||
"leafdev.top/Ecosystem/recommender/internal/handler/http/middleware"
|
||||
"leafdev.top/Ecosystem/recommender/internal/router"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/application"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/auth"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/jwks"
|
||||
)
|
||||
@ -37,8 +38,11 @@ func CreateApp() (*base.Application, error) {
|
||||
config := conf.ProviderConfig(loggerLogger)
|
||||
jwksJWKS := jwks.NewJWKS(config, loggerLogger)
|
||||
authService := auth.NewAuthService(config, jwksJWKS, loggerLogger)
|
||||
userController := v1.NewUserController(authService)
|
||||
handlers := http.NewHandler(userController)
|
||||
db := orm.NewGORM(config, loggerLogger)
|
||||
query := dao.NewQuery(db)
|
||||
applicationService := application.NewService(query)
|
||||
applicationController := v1.NewApplicationController(authService, applicationService)
|
||||
handlers := http.NewHandler(applicationController)
|
||||
api := router.NewApiRoute(handlers)
|
||||
swaggerRouter := router.NewSwaggerRoute()
|
||||
ginLoggerMiddleware := middleware.NewGinLoggerMiddleware(loggerLogger)
|
||||
@ -46,20 +50,18 @@ func CreateApp() (*base.Application, error) {
|
||||
jsonResponseMiddleware := middleware.NewJSONResponseMiddleware()
|
||||
httpMiddleware := http.NewMiddleware(ginLoggerMiddleware, authMiddleware, jsonResponseMiddleware)
|
||||
httpServer := server.NewHTTPServer(config, api, swaggerRouter, httpMiddleware)
|
||||
db := orm.NewGORM(config, loggerLogger)
|
||||
query := dao.NewQuery(db)
|
||||
documentService := documents.NewDocumentService(query)
|
||||
interceptorAuth := interceptor.NewAuth(authService)
|
||||
interceptorLogger := interceptor.NewLogger(loggerLogger)
|
||||
grpcInterceptor := grpc.NewInterceptor(interceptorAuth, interceptorLogger)
|
||||
grpcHandlers := grpc.NewHandler(documentService, grpcInterceptor)
|
||||
handlerHandler := handler.NewHandler(grpcHandlers, handlers)
|
||||
serviceService := service.NewService(loggerLogger, jwksJWKS, authService)
|
||||
serviceService := service.NewService(loggerLogger, jwksJWKS, authService, applicationService)
|
||||
redisRedis := redis.NewRedis(config)
|
||||
batchBatch := batch.NewBatch(loggerLogger)
|
||||
s3S3 := s3.NewS3(config)
|
||||
application := base.NewApplication(config, httpServer, handlerHandler, loggerLogger, serviceService, httpMiddleware, redisRedis, batchBatch, s3S3, db, query)
|
||||
return application, nil
|
||||
baseApplication := base.NewApplication(config, httpServer, handlerHandler, loggerLogger, serviceService, httpMiddleware, redisRedis, batchBatch, s3S3, db, query)
|
||||
return baseApplication, nil
|
||||
}
|
||||
|
||||
// wire.go:
|
||||
|
235
docs/docs.go
235
docs/docs.go
@ -15,14 +15,14 @@ const docTemplate = `{
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/api/v1/ping": {
|
||||
"/api/v1/application/{application_id}/tokens": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "测试接口,将会返回当前用户的信息",
|
||||
"description": "获取应用程序的 Token 列表",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
@ -30,10 +30,16 @@ const docTemplate = `{
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"ping"
|
||||
"applications"
|
||||
],
|
||||
"summary": "获取应用程序的 Token 列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "application_id",
|
||||
"in": "path"
|
||||
}
|
||||
],
|
||||
"summary": "Greet",
|
||||
"deprecated": true,
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
@ -46,7 +52,177 @@ const docTemplate = `{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/schema.CurrentUserResponse"
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.ApplicationToken"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "获取应用程序的 Token 列表",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"applications"
|
||||
],
|
||||
"summary": "获取应用程序的 Token 列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "application_id",
|
||||
"in": "path"
|
||||
},
|
||||
{
|
||||
"description": "创建应用程序的请求",
|
||||
"name": "ApplicationCreateRequest",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ApplicationCreateRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.ApplicationToken"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/applications": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "列出当前用户下的应用程序列表",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"applications"
|
||||
],
|
||||
"summary": "List Applications",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.Application"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "创建一个应用程序",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"applications"
|
||||
],
|
||||
"summary": "创建并保存一个应用程序",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "创建应用程序的请求",
|
||||
"name": "ApplicationCreateRequest",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ApplicationCreateRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.Application"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,23 +240,54 @@ const docTemplate = `{
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"schema.CurrentUserResponse": {
|
||||
"entity.Application": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ip": {
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"userEmail": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"userId": {
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"userName": {
|
||||
"user_id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity.ApplicationToken": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"application": {
|
||||
"$ref": "#/definitions/entity.Application"
|
||||
},
|
||||
"application_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"valid": {
|
||||
"type": "boolean"
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.ApplicationCreateRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -115,7 +322,7 @@ var SwaggerInfo = &swag.Spec{
|
||||
Host: "",
|
||||
BasePath: "",
|
||||
Schemes: []string{},
|
||||
Title: "API Docs",
|
||||
Title: "Recommender API",
|
||||
Description: "",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
|
@ -1,19 +1,19 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "API Docs",
|
||||
"title": "Recommender API",
|
||||
"contact": {},
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/api/v1/ping": {
|
||||
"/api/v1/application/{application_id}/tokens": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "测试接口,将会返回当前用户的信息",
|
||||
"description": "获取应用程序的 Token 列表",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
@ -21,10 +21,16 @@
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"ping"
|
||||
"applications"
|
||||
],
|
||||
"summary": "获取应用程序的 Token 列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "application_id",
|
||||
"in": "path"
|
||||
}
|
||||
],
|
||||
"summary": "Greet",
|
||||
"deprecated": true,
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
@ -37,7 +43,177 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/schema.CurrentUserResponse"
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.ApplicationToken"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "获取应用程序的 Token 列表",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"applications"
|
||||
],
|
||||
"summary": "获取应用程序的 Token 列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "application_id",
|
||||
"in": "path"
|
||||
},
|
||||
{
|
||||
"description": "创建应用程序的请求",
|
||||
"name": "ApplicationCreateRequest",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ApplicationCreateRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.ApplicationToken"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/applications": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "列出当前用户下的应用程序列表",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"applications"
|
||||
],
|
||||
"summary": "List Applications",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.Application"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "创建一个应用程序",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"applications"
|
||||
],
|
||||
"summary": "创建并保存一个应用程序",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "创建应用程序的请求",
|
||||
"name": "ApplicationCreateRequest",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ApplicationCreateRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/schema.ResponseBody"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.Application"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -55,23 +231,54 @@
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"schema.CurrentUserResponse": {
|
||||
"entity.Application": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ip": {
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"userEmail": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"userId": {
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"userName": {
|
||||
"user_id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity.ApplicationToken": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"application": {
|
||||
"$ref": "#/definitions/entity.Application"
|
||||
},
|
||||
"application_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"valid": {
|
||||
"type": "boolean"
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.ApplicationCreateRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1,16 +1,36 @@
|
||||
definitions:
|
||||
schema.CurrentUserResponse:
|
||||
entity.Application:
|
||||
properties:
|
||||
ip:
|
||||
created_at:
|
||||
type: string
|
||||
userEmail:
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
type: string
|
||||
userId:
|
||||
updated_at:
|
||||
type: string
|
||||
userName:
|
||||
user_id:
|
||||
type: string
|
||||
type: object
|
||||
entity.ApplicationToken:
|
||||
properties:
|
||||
application:
|
||||
$ref: '#/definitions/entity.Application'
|
||||
application_id:
|
||||
type: integer
|
||||
created_at:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
token:
|
||||
type: string
|
||||
updated_at:
|
||||
type: string
|
||||
type: object
|
||||
schema.ApplicationCreateRequest:
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
valid:
|
||||
type: boolean
|
||||
type: object
|
||||
schema.ResponseBody:
|
||||
properties:
|
||||
@ -24,15 +44,18 @@ definitions:
|
||||
type: object
|
||||
info:
|
||||
contact: {}
|
||||
title: API Docs
|
||||
title: Recommender API
|
||||
version: "1.0"
|
||||
paths:
|
||||
/api/v1/ping:
|
||||
/api/v1/application/{application_id}/tokens:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
deprecated: true
|
||||
description: 测试接口,将会返回当前用户的信息
|
||||
description: 获取应用程序的 Token 列表
|
||||
parameters:
|
||||
- in: path
|
||||
name: application_id
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@ -43,7 +66,9 @@ paths:
|
||||
- $ref: '#/definitions/schema.ResponseBody'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/schema.CurrentUserResponse'
|
||||
items:
|
||||
$ref: '#/definitions/entity.ApplicationToken'
|
||||
type: array
|
||||
type: object
|
||||
"400":
|
||||
description: Bad Request
|
||||
@ -51,9 +76,106 @@ paths:
|
||||
$ref: '#/definitions/schema.ResponseBody'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Greet
|
||||
summary: 获取应用程序的 Token 列表
|
||||
tags:
|
||||
- ping
|
||||
- applications
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 获取应用程序的 Token 列表
|
||||
parameters:
|
||||
- in: path
|
||||
name: application_id
|
||||
type: integer
|
||||
- description: 创建应用程序的请求
|
||||
in: body
|
||||
name: ApplicationCreateRequest
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ApplicationCreateRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/schema.ResponseBody'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/entity.ApplicationToken'
|
||||
type: object
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ResponseBody'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 获取应用程序的 Token 列表
|
||||
tags:
|
||||
- applications
|
||||
/api/v1/applications:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 列出当前用户下的应用程序列表
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/schema.ResponseBody'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/entity.Application'
|
||||
type: array
|
||||
type: object
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ResponseBody'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: List Applications
|
||||
tags:
|
||||
- applications
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 创建一个应用程序
|
||||
parameters:
|
||||
- description: 创建应用程序的请求
|
||||
in: body
|
||||
name: ApplicationCreateRequest
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ApplicationCreateRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/schema.ResponseBody'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/entity.Application'
|
||||
type: array
|
||||
type: object
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ResponseBody'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: 创建并保存一个应用程序
|
||||
tags:
|
||||
- applications
|
||||
securityDefinitions:
|
||||
ApiKeyAuth:
|
||||
in: header
|
||||
|
1
go.mod
1
go.mod
@ -11,6 +11,7 @@ require (
|
||||
github.com/google/wire v0.6.0
|
||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0
|
||||
github.com/iVampireSP/pkg v0.0.8-0.20241015163922-65faf24f73ac
|
||||
github.com/milvus-io/milvus-sdk-go/v2 v2.4.2
|
||||
github.com/minio/minio-go/v7 v7.0.78
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
|
2
go.sum
2
go.sum
@ -199,6 +199,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
|
||||
github.com/iVampireSP/pkg v0.0.8-0.20241015163922-65faf24f73ac h1:/+NgUY2opR7AAGpTetjTSa27OrH+OA3F1lBMkYQ2nxI=
|
||||
github.com/iVampireSP/pkg v0.0.8-0.20241015163922-65faf24f73ac/go.mod h1:hZ/NJCic3+HJjX3kFMVHQXlhZwR5khP0U2Rn/9PZeYA=
|
||||
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
|
@ -25,7 +25,14 @@ func main() {
|
||||
//g.UseDB(app.GORM)
|
||||
|
||||
g.ApplyBasic(
|
||||
entity.User{},
|
||||
entity.Post{},
|
||||
entity.PostTag{},
|
||||
entity.Tag{},
|
||||
entity.TagMapping{},
|
||||
entity.UserLike{},
|
||||
entity.Application{},
|
||||
entity.ApplicationToken{},
|
||||
entity.UserTagScore{},
|
||||
)
|
||||
|
||||
// Generate Type Safe API with Dynamic SQL defined on Querier interface for `model.User` and `model.Company`
|
||||
|
@ -3,8 +3,8 @@ package server
|
||||
import (
|
||||
"leafdev.top/Ecosystem/recommender/internal/base/conf"
|
||||
httpHandler "leafdev.top/Ecosystem/recommender/internal/handler/http"
|
||||
"leafdev.top/Ecosystem/recommender/internal/handler/http/response"
|
||||
"leafdev.top/Ecosystem/recommender/internal/router"
|
||||
"leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
"leafdev.top/Ecosystem/recommender/pkg/consts"
|
||||
"net/http"
|
||||
"time"
|
||||
@ -86,7 +86,7 @@ func (hs *HttpServer) BizRouter() *gin.Engine {
|
||||
}
|
||||
|
||||
hs.Gin.NoRoute(func(ctx *gin.Context) {
|
||||
schema.NewResponse(ctx).Status(http.StatusNotFound).Error(consts.ErrPageNotFound).Send()
|
||||
response.Ctx(ctx).Status(http.StatusNotFound).Error(consts.ErrPageNotFound).Send()
|
||||
})
|
||||
|
||||
return hs.Gin
|
||||
|
474
internal/dao/application_tokens.gen.go
Normal file
474
internal/dao/application_tokens.gen.go
Normal file
@ -0,0 +1,474 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newApplicationToken(db *gorm.DB, opts ...gen.DOOption) applicationToken {
|
||||
_applicationToken := applicationToken{}
|
||||
|
||||
_applicationToken.applicationTokenDo.UseDB(db, opts...)
|
||||
_applicationToken.applicationTokenDo.UseModel(&entity.ApplicationToken{})
|
||||
|
||||
tableName := _applicationToken.applicationTokenDo.TableName()
|
||||
_applicationToken.ALL = field.NewAsterisk(tableName)
|
||||
_applicationToken.Id = field.NewUint(tableName, "id")
|
||||
_applicationToken.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_applicationToken.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_applicationToken.Token = field.NewString(tableName, "token")
|
||||
_applicationToken.ApplicationId = field.NewUint(tableName, "application_id")
|
||||
_applicationToken.Application = applicationTokenBelongsToApplication{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Application", "entity.Application"),
|
||||
}
|
||||
|
||||
_applicationToken.fillFieldMap()
|
||||
|
||||
return _applicationToken
|
||||
}
|
||||
|
||||
type applicationToken struct {
|
||||
applicationTokenDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
Token field.String
|
||||
ApplicationId field.Uint
|
||||
Application applicationTokenBelongsToApplication
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (a applicationToken) Table(newTableName string) *applicationToken {
|
||||
a.applicationTokenDo.UseTable(newTableName)
|
||||
return a.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (a applicationToken) As(alias string) *applicationToken {
|
||||
a.applicationTokenDo.DO = *(a.applicationTokenDo.As(alias).(*gen.DO))
|
||||
return a.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (a *applicationToken) updateTableName(table string) *applicationToken {
|
||||
a.ALL = field.NewAsterisk(table)
|
||||
a.Id = field.NewUint(table, "id")
|
||||
a.CreatedAt = field.NewTime(table, "created_at")
|
||||
a.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
a.Token = field.NewString(table, "token")
|
||||
a.ApplicationId = field.NewUint(table, "application_id")
|
||||
|
||||
a.fillFieldMap()
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *applicationToken) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := a.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (a *applicationToken) fillFieldMap() {
|
||||
a.fieldMap = make(map[string]field.Expr, 6)
|
||||
a.fieldMap["id"] = a.Id
|
||||
a.fieldMap["created_at"] = a.CreatedAt
|
||||
a.fieldMap["updated_at"] = a.UpdatedAt
|
||||
a.fieldMap["token"] = a.Token
|
||||
a.fieldMap["application_id"] = a.ApplicationId
|
||||
|
||||
}
|
||||
|
||||
func (a applicationToken) clone(db *gorm.DB) applicationToken {
|
||||
a.applicationTokenDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a applicationToken) replaceDB(db *gorm.DB) applicationToken {
|
||||
a.applicationTokenDo.ReplaceDB(db)
|
||||
return a
|
||||
}
|
||||
|
||||
type applicationTokenBelongsToApplication struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplication) Where(conds ...field.Expr) *applicationTokenBelongsToApplication {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplication) WithContext(ctx context.Context) *applicationTokenBelongsToApplication {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplication) Session(session *gorm.Session) *applicationTokenBelongsToApplication {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplication) Model(m *entity.ApplicationToken) *applicationTokenBelongsToApplicationTx {
|
||||
return &applicationTokenBelongsToApplicationTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type applicationTokenBelongsToApplicationTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a applicationTokenBelongsToApplicationTx) Find() (result *entity.Application, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplicationTx) Append(values ...*entity.Application) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplicationTx) Replace(values ...*entity.Application) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplicationTx) Delete(values ...*entity.Application) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplicationTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a applicationTokenBelongsToApplicationTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type applicationTokenDo struct{ gen.DO }
|
||||
|
||||
type IApplicationTokenDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IApplicationTokenDo
|
||||
WithContext(ctx context.Context) IApplicationTokenDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IApplicationTokenDo
|
||||
WriteDB() IApplicationTokenDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IApplicationTokenDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IApplicationTokenDo
|
||||
Not(conds ...gen.Condition) IApplicationTokenDo
|
||||
Or(conds ...gen.Condition) IApplicationTokenDo
|
||||
Select(conds ...field.Expr) IApplicationTokenDo
|
||||
Where(conds ...gen.Condition) IApplicationTokenDo
|
||||
Order(conds ...field.Expr) IApplicationTokenDo
|
||||
Distinct(cols ...field.Expr) IApplicationTokenDo
|
||||
Omit(cols ...field.Expr) IApplicationTokenDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IApplicationTokenDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IApplicationTokenDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IApplicationTokenDo
|
||||
Group(cols ...field.Expr) IApplicationTokenDo
|
||||
Having(conds ...gen.Condition) IApplicationTokenDo
|
||||
Limit(limit int) IApplicationTokenDo
|
||||
Offset(offset int) IApplicationTokenDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IApplicationTokenDo
|
||||
Unscoped() IApplicationTokenDo
|
||||
Create(values ...*entity.ApplicationToken) error
|
||||
CreateInBatches(values []*entity.ApplicationToken, batchSize int) error
|
||||
Save(values ...*entity.ApplicationToken) error
|
||||
First() (*entity.ApplicationToken, error)
|
||||
Take() (*entity.ApplicationToken, error)
|
||||
Last() (*entity.ApplicationToken, error)
|
||||
Find() ([]*entity.ApplicationToken, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.ApplicationToken, err error)
|
||||
FindInBatches(result *[]*entity.ApplicationToken, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.ApplicationToken) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IApplicationTokenDo
|
||||
Assign(attrs ...field.AssignExpr) IApplicationTokenDo
|
||||
Joins(fields ...field.RelationField) IApplicationTokenDo
|
||||
Preload(fields ...field.RelationField) IApplicationTokenDo
|
||||
FirstOrInit() (*entity.ApplicationToken, error)
|
||||
FirstOrCreate() (*entity.ApplicationToken, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.ApplicationToken, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IApplicationTokenDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Debug() IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Debug())
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) WithContext(ctx context.Context) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) ReadDB() IApplicationTokenDo {
|
||||
return a.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) WriteDB() IApplicationTokenDo {
|
||||
return a.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Session(config *gorm.Session) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Session(config))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Clauses(conds ...clause.Expression) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Returning(value interface{}, columns ...string) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Not(conds ...gen.Condition) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Or(conds ...gen.Condition) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Select(conds ...field.Expr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Where(conds ...gen.Condition) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Order(conds ...field.Expr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Distinct(cols ...field.Expr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Omit(cols ...field.Expr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Join(table schema.Tabler, on ...field.Expr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) LeftJoin(table schema.Tabler, on ...field.Expr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) RightJoin(table schema.Tabler, on ...field.Expr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Group(cols ...field.Expr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Having(conds ...gen.Condition) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Limit(limit int) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Offset(offset int) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Unscoped() IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Create(values ...*entity.ApplicationToken) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Create(values)
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) CreateInBatches(values []*entity.ApplicationToken, batchSize int) error {
|
||||
return a.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (a applicationTokenDo) Save(values ...*entity.ApplicationToken) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Save(values)
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) First() (*entity.ApplicationToken, error) {
|
||||
if result, err := a.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.ApplicationToken), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Take() (*entity.ApplicationToken, error) {
|
||||
if result, err := a.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.ApplicationToken), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Last() (*entity.ApplicationToken, error) {
|
||||
if result, err := a.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.ApplicationToken), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Find() ([]*entity.ApplicationToken, error) {
|
||||
result, err := a.DO.Find()
|
||||
return result.([]*entity.ApplicationToken), err
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.ApplicationToken, err error) {
|
||||
buf := make([]*entity.ApplicationToken, 0, batchSize)
|
||||
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) FindInBatches(result *[]*entity.ApplicationToken, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return a.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Attrs(attrs ...field.AssignExpr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Assign(attrs ...field.AssignExpr) IApplicationTokenDo {
|
||||
return a.withDO(a.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Joins(fields ...field.RelationField) IApplicationTokenDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Joins(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Preload(fields ...field.RelationField) IApplicationTokenDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Preload(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) FirstOrInit() (*entity.ApplicationToken, error) {
|
||||
if result, err := a.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.ApplicationToken), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) FirstOrCreate() (*entity.ApplicationToken, error) {
|
||||
if result, err := a.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.ApplicationToken), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) FindByPage(offset int, limit int) (result []*entity.ApplicationToken, count int64, err error) {
|
||||
result, err = a.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = a.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = a.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = a.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Scan(result interface{}) (err error) {
|
||||
return a.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (a applicationTokenDo) Delete(models ...*entity.ApplicationToken) (result gen.ResultInfo, err error) {
|
||||
return a.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (a *applicationTokenDo) withDO(do gen.Dao) *applicationTokenDo {
|
||||
a.DO = *do.(*gen.DO)
|
||||
return a
|
||||
}
|
396
internal/dao/applications.gen.go
Normal file
396
internal/dao/applications.gen.go
Normal file
@ -0,0 +1,396 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newApplication(db *gorm.DB, opts ...gen.DOOption) application {
|
||||
_application := application{}
|
||||
|
||||
_application.applicationDo.UseDB(db, opts...)
|
||||
_application.applicationDo.UseModel(&entity.Application{})
|
||||
|
||||
tableName := _application.applicationDo.TableName()
|
||||
_application.ALL = field.NewAsterisk(tableName)
|
||||
_application.Id = field.NewUint(tableName, "id")
|
||||
_application.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_application.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_application.Name = field.NewString(tableName, "name")
|
||||
_application.UserId = field.NewString(tableName, "user_id")
|
||||
|
||||
_application.fillFieldMap()
|
||||
|
||||
return _application
|
||||
}
|
||||
|
||||
type application struct {
|
||||
applicationDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
Name field.String
|
||||
UserId field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (a application) Table(newTableName string) *application {
|
||||
a.applicationDo.UseTable(newTableName)
|
||||
return a.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (a application) As(alias string) *application {
|
||||
a.applicationDo.DO = *(a.applicationDo.As(alias).(*gen.DO))
|
||||
return a.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (a *application) updateTableName(table string) *application {
|
||||
a.ALL = field.NewAsterisk(table)
|
||||
a.Id = field.NewUint(table, "id")
|
||||
a.CreatedAt = field.NewTime(table, "created_at")
|
||||
a.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
a.Name = field.NewString(table, "name")
|
||||
a.UserId = field.NewString(table, "user_id")
|
||||
|
||||
a.fillFieldMap()
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *application) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := a.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (a *application) fillFieldMap() {
|
||||
a.fieldMap = make(map[string]field.Expr, 5)
|
||||
a.fieldMap["id"] = a.Id
|
||||
a.fieldMap["created_at"] = a.CreatedAt
|
||||
a.fieldMap["updated_at"] = a.UpdatedAt
|
||||
a.fieldMap["name"] = a.Name
|
||||
a.fieldMap["user_id"] = a.UserId
|
||||
}
|
||||
|
||||
func (a application) clone(db *gorm.DB) application {
|
||||
a.applicationDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a application) replaceDB(db *gorm.DB) application {
|
||||
a.applicationDo.ReplaceDB(db)
|
||||
return a
|
||||
}
|
||||
|
||||
type applicationDo struct{ gen.DO }
|
||||
|
||||
type IApplicationDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IApplicationDo
|
||||
WithContext(ctx context.Context) IApplicationDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IApplicationDo
|
||||
WriteDB() IApplicationDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IApplicationDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IApplicationDo
|
||||
Not(conds ...gen.Condition) IApplicationDo
|
||||
Or(conds ...gen.Condition) IApplicationDo
|
||||
Select(conds ...field.Expr) IApplicationDo
|
||||
Where(conds ...gen.Condition) IApplicationDo
|
||||
Order(conds ...field.Expr) IApplicationDo
|
||||
Distinct(cols ...field.Expr) IApplicationDo
|
||||
Omit(cols ...field.Expr) IApplicationDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IApplicationDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IApplicationDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IApplicationDo
|
||||
Group(cols ...field.Expr) IApplicationDo
|
||||
Having(conds ...gen.Condition) IApplicationDo
|
||||
Limit(limit int) IApplicationDo
|
||||
Offset(offset int) IApplicationDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IApplicationDo
|
||||
Unscoped() IApplicationDo
|
||||
Create(values ...*entity.Application) error
|
||||
CreateInBatches(values []*entity.Application, batchSize int) error
|
||||
Save(values ...*entity.Application) error
|
||||
First() (*entity.Application, error)
|
||||
Take() (*entity.Application, error)
|
||||
Last() (*entity.Application, error)
|
||||
Find() ([]*entity.Application, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Application, err error)
|
||||
FindInBatches(result *[]*entity.Application, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.Application) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IApplicationDo
|
||||
Assign(attrs ...field.AssignExpr) IApplicationDo
|
||||
Joins(fields ...field.RelationField) IApplicationDo
|
||||
Preload(fields ...field.RelationField) IApplicationDo
|
||||
FirstOrInit() (*entity.Application, error)
|
||||
FirstOrCreate() (*entity.Application, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.Application, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IApplicationDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (a applicationDo) Debug() IApplicationDo {
|
||||
return a.withDO(a.DO.Debug())
|
||||
}
|
||||
|
||||
func (a applicationDo) WithContext(ctx context.Context) IApplicationDo {
|
||||
return a.withDO(a.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (a applicationDo) ReadDB() IApplicationDo {
|
||||
return a.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (a applicationDo) WriteDB() IApplicationDo {
|
||||
return a.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (a applicationDo) Session(config *gorm.Session) IApplicationDo {
|
||||
return a.withDO(a.DO.Session(config))
|
||||
}
|
||||
|
||||
func (a applicationDo) Clauses(conds ...clause.Expression) IApplicationDo {
|
||||
return a.withDO(a.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Returning(value interface{}, columns ...string) IApplicationDo {
|
||||
return a.withDO(a.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Not(conds ...gen.Condition) IApplicationDo {
|
||||
return a.withDO(a.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Or(conds ...gen.Condition) IApplicationDo {
|
||||
return a.withDO(a.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Select(conds ...field.Expr) IApplicationDo {
|
||||
return a.withDO(a.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Where(conds ...gen.Condition) IApplicationDo {
|
||||
return a.withDO(a.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Order(conds ...field.Expr) IApplicationDo {
|
||||
return a.withDO(a.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Distinct(cols ...field.Expr) IApplicationDo {
|
||||
return a.withDO(a.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Omit(cols ...field.Expr) IApplicationDo {
|
||||
return a.withDO(a.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Join(table schema.Tabler, on ...field.Expr) IApplicationDo {
|
||||
return a.withDO(a.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (a applicationDo) LeftJoin(table schema.Tabler, on ...field.Expr) IApplicationDo {
|
||||
return a.withDO(a.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a applicationDo) RightJoin(table schema.Tabler, on ...field.Expr) IApplicationDo {
|
||||
return a.withDO(a.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Group(cols ...field.Expr) IApplicationDo {
|
||||
return a.withDO(a.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Having(conds ...gen.Condition) IApplicationDo {
|
||||
return a.withDO(a.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Limit(limit int) IApplicationDo {
|
||||
return a.withDO(a.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (a applicationDo) Offset(offset int) IApplicationDo {
|
||||
return a.withDO(a.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (a applicationDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IApplicationDo {
|
||||
return a.withDO(a.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Unscoped() IApplicationDo {
|
||||
return a.withDO(a.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (a applicationDo) Create(values ...*entity.Application) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Create(values)
|
||||
}
|
||||
|
||||
func (a applicationDo) CreateInBatches(values []*entity.Application, batchSize int) error {
|
||||
return a.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (a applicationDo) Save(values ...*entity.Application) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Save(values)
|
||||
}
|
||||
|
||||
func (a applicationDo) First() (*entity.Application, error) {
|
||||
if result, err := a.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Application), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationDo) Take() (*entity.Application, error) {
|
||||
if result, err := a.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Application), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationDo) Last() (*entity.Application, error) {
|
||||
if result, err := a.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Application), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationDo) Find() ([]*entity.Application, error) {
|
||||
result, err := a.DO.Find()
|
||||
return result.([]*entity.Application), err
|
||||
}
|
||||
|
||||
func (a applicationDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Application, err error) {
|
||||
buf := make([]*entity.Application, 0, batchSize)
|
||||
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (a applicationDo) FindInBatches(result *[]*entity.Application, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return a.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (a applicationDo) Attrs(attrs ...field.AssignExpr) IApplicationDo {
|
||||
return a.withDO(a.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Assign(attrs ...field.AssignExpr) IApplicationDo {
|
||||
return a.withDO(a.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (a applicationDo) Joins(fields ...field.RelationField) IApplicationDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Joins(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a applicationDo) Preload(fields ...field.RelationField) IApplicationDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Preload(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a applicationDo) FirstOrInit() (*entity.Application, error) {
|
||||
if result, err := a.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Application), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationDo) FirstOrCreate() (*entity.Application, error) {
|
||||
if result, err := a.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Application), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a applicationDo) FindByPage(offset int, limit int) (result []*entity.Application, count int64, err error) {
|
||||
result, err = a.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = a.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (a applicationDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = a.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = a.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (a applicationDo) Scan(result interface{}) (err error) {
|
||||
return a.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (a applicationDo) Delete(models ...*entity.Application) (result gen.ResultInfo, err error) {
|
||||
return a.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (a *applicationDo) withDO(do gen.Dao) *applicationDo {
|
||||
a.DO = *do.(*gen.DO)
|
||||
return a
|
||||
}
|
@ -16,34 +16,69 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
User *user
|
||||
Q = new(Query)
|
||||
Application *application
|
||||
ApplicationToken *applicationToken
|
||||
Post *post
|
||||
PostTag *postTag
|
||||
Tag *tag
|
||||
TagMapping *tagMapping
|
||||
UserLike *userLike
|
||||
UserTagScore *userTagScore
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
User = &Q.User
|
||||
Application = &Q.Application
|
||||
ApplicationToken = &Q.ApplicationToken
|
||||
Post = &Q.Post
|
||||
PostTag = &Q.PostTag
|
||||
Tag = &Q.Tag
|
||||
TagMapping = &Q.TagMapping
|
||||
UserLike = &Q.UserLike
|
||||
UserTagScore = &Q.UserTagScore
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
User: newUser(db, opts...),
|
||||
db: db,
|
||||
Application: newApplication(db, opts...),
|
||||
ApplicationToken: newApplicationToken(db, opts...),
|
||||
Post: newPost(db, opts...),
|
||||
PostTag: newPostTag(db, opts...),
|
||||
Tag: newTag(db, opts...),
|
||||
TagMapping: newTagMapping(db, opts...),
|
||||
UserLike: newUserLike(db, opts...),
|
||||
UserTagScore: newUserTagScore(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
User user
|
||||
Application application
|
||||
ApplicationToken applicationToken
|
||||
Post post
|
||||
PostTag postTag
|
||||
Tag tag
|
||||
TagMapping tagMapping
|
||||
UserLike userLike
|
||||
UserTagScore userTagScore
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
User: q.User.clone(db),
|
||||
db: db,
|
||||
Application: q.Application.clone(db),
|
||||
ApplicationToken: q.ApplicationToken.clone(db),
|
||||
Post: q.Post.clone(db),
|
||||
PostTag: q.PostTag.clone(db),
|
||||
Tag: q.Tag.clone(db),
|
||||
TagMapping: q.TagMapping.clone(db),
|
||||
UserLike: q.UserLike.clone(db),
|
||||
UserTagScore: q.UserTagScore.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,18 +92,39 @@ func (q *Query) WriteDB() *Query {
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
User: q.User.replaceDB(db),
|
||||
db: db,
|
||||
Application: q.Application.replaceDB(db),
|
||||
ApplicationToken: q.ApplicationToken.replaceDB(db),
|
||||
Post: q.Post.replaceDB(db),
|
||||
PostTag: q.PostTag.replaceDB(db),
|
||||
Tag: q.Tag.replaceDB(db),
|
||||
TagMapping: q.TagMapping.replaceDB(db),
|
||||
UserLike: q.UserLike.replaceDB(db),
|
||||
UserTagScore: q.UserTagScore.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
User IUserDo
|
||||
Application IApplicationDo
|
||||
ApplicationToken IApplicationTokenDo
|
||||
Post IPostDo
|
||||
PostTag IPostTagDo
|
||||
Tag ITagDo
|
||||
TagMapping ITagMappingDo
|
||||
UserLike IUserLikeDo
|
||||
UserTagScore IUserTagScoreDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
User: q.User.WithContext(ctx),
|
||||
Application: q.Application.WithContext(ctx),
|
||||
ApplicationToken: q.ApplicationToken.WithContext(ctx),
|
||||
Post: q.Post.WithContext(ctx),
|
||||
PostTag: q.PostTag.WithContext(ctx),
|
||||
Tag: q.Tag.WithContext(ctx),
|
||||
TagMapping: q.TagMapping.WithContext(ctx),
|
||||
UserLike: q.UserLike.WithContext(ctx),
|
||||
UserTagScore: q.UserTagScore.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
|
545
internal/dao/post_tags.gen.go
Normal file
545
internal/dao/post_tags.gen.go
Normal file
@ -0,0 +1,545 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newPostTag(db *gorm.DB, opts ...gen.DOOption) postTag {
|
||||
_postTag := postTag{}
|
||||
|
||||
_postTag.postTagDo.UseDB(db, opts...)
|
||||
_postTag.postTagDo.UseModel(&entity.PostTag{})
|
||||
|
||||
tableName := _postTag.postTagDo.TableName()
|
||||
_postTag.ALL = field.NewAsterisk(tableName)
|
||||
_postTag.Id = field.NewUint(tableName, "id")
|
||||
_postTag.PostId = field.NewUint(tableName, "post_id")
|
||||
_postTag.TagId = field.NewUint(tableName, "tag_id")
|
||||
_postTag.Post = postTagBelongsToPost{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Post", "entity.Post"),
|
||||
}
|
||||
|
||||
_postTag.Tag = postTagBelongsToTag{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Tag", "entity.Tag"),
|
||||
}
|
||||
|
||||
_postTag.fillFieldMap()
|
||||
|
||||
return _postTag
|
||||
}
|
||||
|
||||
type postTag struct {
|
||||
postTagDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
PostId field.Uint
|
||||
TagId field.Uint
|
||||
Post postTagBelongsToPost
|
||||
|
||||
Tag postTagBelongsToTag
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p postTag) Table(newTableName string) *postTag {
|
||||
p.postTagDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p postTag) As(alias string) *postTag {
|
||||
p.postTagDo.DO = *(p.postTagDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *postTag) updateTableName(table string) *postTag {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.Id = field.NewUint(table, "id")
|
||||
p.PostId = field.NewUint(table, "post_id")
|
||||
p.TagId = field.NewUint(table, "tag_id")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *postTag) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *postTag) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 5)
|
||||
p.fieldMap["id"] = p.Id
|
||||
p.fieldMap["post_id"] = p.PostId
|
||||
p.fieldMap["tag_id"] = p.TagId
|
||||
|
||||
}
|
||||
|
||||
func (p postTag) clone(db *gorm.DB) postTag {
|
||||
p.postTagDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p postTag) replaceDB(db *gorm.DB) postTag {
|
||||
p.postTagDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type postTagBelongsToPost struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPost) Where(conds ...field.Expr) *postTagBelongsToPost {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPost) WithContext(ctx context.Context) *postTagBelongsToPost {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPost) Session(session *gorm.Session) *postTagBelongsToPost {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPost) Model(m *entity.PostTag) *postTagBelongsToPostTx {
|
||||
return &postTagBelongsToPostTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type postTagBelongsToPostTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a postTagBelongsToPostTx) Find() (result *entity.Post, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPostTx) Append(values ...*entity.Post) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPostTx) Replace(values ...*entity.Post) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPostTx) Delete(values ...*entity.Post) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPostTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a postTagBelongsToPostTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type postTagBelongsToTag struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTag) Where(conds ...field.Expr) *postTagBelongsToTag {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTag) WithContext(ctx context.Context) *postTagBelongsToTag {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTag) Session(session *gorm.Session) *postTagBelongsToTag {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTag) Model(m *entity.PostTag) *postTagBelongsToTagTx {
|
||||
return &postTagBelongsToTagTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type postTagBelongsToTagTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a postTagBelongsToTagTx) Find() (result *entity.Tag, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTagTx) Append(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTagTx) Replace(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTagTx) Delete(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTagTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a postTagBelongsToTagTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type postTagDo struct{ gen.DO }
|
||||
|
||||
type IPostTagDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPostTagDo
|
||||
WithContext(ctx context.Context) IPostTagDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPostTagDo
|
||||
WriteDB() IPostTagDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPostTagDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPostTagDo
|
||||
Not(conds ...gen.Condition) IPostTagDo
|
||||
Or(conds ...gen.Condition) IPostTagDo
|
||||
Select(conds ...field.Expr) IPostTagDo
|
||||
Where(conds ...gen.Condition) IPostTagDo
|
||||
Order(conds ...field.Expr) IPostTagDo
|
||||
Distinct(cols ...field.Expr) IPostTagDo
|
||||
Omit(cols ...field.Expr) IPostTagDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPostTagDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPostTagDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPostTagDo
|
||||
Group(cols ...field.Expr) IPostTagDo
|
||||
Having(conds ...gen.Condition) IPostTagDo
|
||||
Limit(limit int) IPostTagDo
|
||||
Offset(offset int) IPostTagDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPostTagDo
|
||||
Unscoped() IPostTagDo
|
||||
Create(values ...*entity.PostTag) error
|
||||
CreateInBatches(values []*entity.PostTag, batchSize int) error
|
||||
Save(values ...*entity.PostTag) error
|
||||
First() (*entity.PostTag, error)
|
||||
Take() (*entity.PostTag, error)
|
||||
Last() (*entity.PostTag, error)
|
||||
Find() ([]*entity.PostTag, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.PostTag, err error)
|
||||
FindInBatches(result *[]*entity.PostTag, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.PostTag) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IPostTagDo
|
||||
Assign(attrs ...field.AssignExpr) IPostTagDo
|
||||
Joins(fields ...field.RelationField) IPostTagDo
|
||||
Preload(fields ...field.RelationField) IPostTagDo
|
||||
FirstOrInit() (*entity.PostTag, error)
|
||||
FirstOrCreate() (*entity.PostTag, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.PostTag, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IPostTagDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p postTagDo) Debug() IPostTagDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p postTagDo) WithContext(ctx context.Context) IPostTagDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p postTagDo) ReadDB() IPostTagDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p postTagDo) WriteDB() IPostTagDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p postTagDo) Session(config *gorm.Session) IPostTagDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p postTagDo) Clauses(conds ...clause.Expression) IPostTagDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Returning(value interface{}, columns ...string) IPostTagDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Not(conds ...gen.Condition) IPostTagDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Or(conds ...gen.Condition) IPostTagDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Select(conds ...field.Expr) IPostTagDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Where(conds ...gen.Condition) IPostTagDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Order(conds ...field.Expr) IPostTagDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Distinct(cols ...field.Expr) IPostTagDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Omit(cols ...field.Expr) IPostTagDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Join(table schema.Tabler, on ...field.Expr) IPostTagDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p postTagDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPostTagDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p postTagDo) RightJoin(table schema.Tabler, on ...field.Expr) IPostTagDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Group(cols ...field.Expr) IPostTagDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Having(conds ...gen.Condition) IPostTagDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Limit(limit int) IPostTagDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p postTagDo) Offset(offset int) IPostTagDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p postTagDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPostTagDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Unscoped() IPostTagDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p postTagDo) Create(values ...*entity.PostTag) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p postTagDo) CreateInBatches(values []*entity.PostTag, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p postTagDo) Save(values ...*entity.PostTag) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p postTagDo) First() (*entity.PostTag, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.PostTag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postTagDo) Take() (*entity.PostTag, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.PostTag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postTagDo) Last() (*entity.PostTag, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.PostTag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postTagDo) Find() ([]*entity.PostTag, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*entity.PostTag), err
|
||||
}
|
||||
|
||||
func (p postTagDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.PostTag, err error) {
|
||||
buf := make([]*entity.PostTag, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p postTagDo) FindInBatches(result *[]*entity.PostTag, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p postTagDo) Attrs(attrs ...field.AssignExpr) IPostTagDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Assign(attrs ...field.AssignExpr) IPostTagDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p postTagDo) Joins(fields ...field.RelationField) IPostTagDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p postTagDo) Preload(fields ...field.RelationField) IPostTagDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p postTagDo) FirstOrInit() (*entity.PostTag, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.PostTag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postTagDo) FirstOrCreate() (*entity.PostTag, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.PostTag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postTagDo) FindByPage(offset int, limit int) (result []*entity.PostTag, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p postTagDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p postTagDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p postTagDo) Delete(models ...*entity.PostTag) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *postTagDo) withDO(do gen.Dao) *postTagDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
404
internal/dao/posts.gen.go
Normal file
404
internal/dao/posts.gen.go
Normal file
@ -0,0 +1,404 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newPost(db *gorm.DB, opts ...gen.DOOption) post {
|
||||
_post := post{}
|
||||
|
||||
_post.postDo.UseDB(db, opts...)
|
||||
_post.postDo.UseModel(&entity.Post{})
|
||||
|
||||
tableName := _post.postDo.TableName()
|
||||
_post.ALL = field.NewAsterisk(tableName)
|
||||
_post.Id = field.NewUint(tableName, "id")
|
||||
_post.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_post.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_post.Title = field.NewString(tableName, "title")
|
||||
_post.Content = field.NewString(tableName, "content")
|
||||
_post.TargetId = field.NewString(tableName, "target_id")
|
||||
_post.Processed = field.NewBool(tableName, "processed")
|
||||
|
||||
_post.fillFieldMap()
|
||||
|
||||
return _post
|
||||
}
|
||||
|
||||
type post struct {
|
||||
postDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
Title field.String
|
||||
Content field.String
|
||||
TargetId field.String
|
||||
Processed field.Bool
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p post) Table(newTableName string) *post {
|
||||
p.postDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p post) As(alias string) *post {
|
||||
p.postDo.DO = *(p.postDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *post) updateTableName(table string) *post {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.Id = field.NewUint(table, "id")
|
||||
p.CreatedAt = field.NewTime(table, "created_at")
|
||||
p.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
p.Title = field.NewString(table, "title")
|
||||
p.Content = field.NewString(table, "content")
|
||||
p.TargetId = field.NewString(table, "target_id")
|
||||
p.Processed = field.NewBool(table, "processed")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *post) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *post) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 7)
|
||||
p.fieldMap["id"] = p.Id
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
p.fieldMap["title"] = p.Title
|
||||
p.fieldMap["content"] = p.Content
|
||||
p.fieldMap["target_id"] = p.TargetId
|
||||
p.fieldMap["processed"] = p.Processed
|
||||
}
|
||||
|
||||
func (p post) clone(db *gorm.DB) post {
|
||||
p.postDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p post) replaceDB(db *gorm.DB) post {
|
||||
p.postDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type postDo struct{ gen.DO }
|
||||
|
||||
type IPostDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPostDo
|
||||
WithContext(ctx context.Context) IPostDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPostDo
|
||||
WriteDB() IPostDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPostDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPostDo
|
||||
Not(conds ...gen.Condition) IPostDo
|
||||
Or(conds ...gen.Condition) IPostDo
|
||||
Select(conds ...field.Expr) IPostDo
|
||||
Where(conds ...gen.Condition) IPostDo
|
||||
Order(conds ...field.Expr) IPostDo
|
||||
Distinct(cols ...field.Expr) IPostDo
|
||||
Omit(cols ...field.Expr) IPostDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPostDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPostDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPostDo
|
||||
Group(cols ...field.Expr) IPostDo
|
||||
Having(conds ...gen.Condition) IPostDo
|
||||
Limit(limit int) IPostDo
|
||||
Offset(offset int) IPostDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPostDo
|
||||
Unscoped() IPostDo
|
||||
Create(values ...*entity.Post) error
|
||||
CreateInBatches(values []*entity.Post, batchSize int) error
|
||||
Save(values ...*entity.Post) error
|
||||
First() (*entity.Post, error)
|
||||
Take() (*entity.Post, error)
|
||||
Last() (*entity.Post, error)
|
||||
Find() ([]*entity.Post, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Post, err error)
|
||||
FindInBatches(result *[]*entity.Post, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.Post) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IPostDo
|
||||
Assign(attrs ...field.AssignExpr) IPostDo
|
||||
Joins(fields ...field.RelationField) IPostDo
|
||||
Preload(fields ...field.RelationField) IPostDo
|
||||
FirstOrInit() (*entity.Post, error)
|
||||
FirstOrCreate() (*entity.Post, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.Post, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IPostDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p postDo) Debug() IPostDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p postDo) WithContext(ctx context.Context) IPostDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p postDo) ReadDB() IPostDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p postDo) WriteDB() IPostDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p postDo) Session(config *gorm.Session) IPostDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p postDo) Clauses(conds ...clause.Expression) IPostDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Returning(value interface{}, columns ...string) IPostDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p postDo) Not(conds ...gen.Condition) IPostDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Or(conds ...gen.Condition) IPostDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Select(conds ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Where(conds ...gen.Condition) IPostDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Order(conds ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Distinct(cols ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p postDo) Omit(cols ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p postDo) Join(table schema.Tabler, on ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p postDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p postDo) RightJoin(table schema.Tabler, on ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p postDo) Group(cols ...field.Expr) IPostDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p postDo) Having(conds ...gen.Condition) IPostDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p postDo) Limit(limit int) IPostDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p postDo) Offset(offset int) IPostDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p postDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPostDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p postDo) Unscoped() IPostDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p postDo) Create(values ...*entity.Post) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p postDo) CreateInBatches(values []*entity.Post, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p postDo) Save(values ...*entity.Post) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p postDo) First() (*entity.Post, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) Take() (*entity.Post, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) Last() (*entity.Post, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) Find() ([]*entity.Post, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*entity.Post), err
|
||||
}
|
||||
|
||||
func (p postDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Post, err error) {
|
||||
buf := make([]*entity.Post, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p postDo) FindInBatches(result *[]*entity.Post, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p postDo) Attrs(attrs ...field.AssignExpr) IPostDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p postDo) Assign(attrs ...field.AssignExpr) IPostDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p postDo) Joins(fields ...field.RelationField) IPostDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p postDo) Preload(fields ...field.RelationField) IPostDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p postDo) FirstOrInit() (*entity.Post, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) FirstOrCreate() (*entity.Post, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Post), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p postDo) FindByPage(offset int, limit int) (result []*entity.Post, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p postDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p postDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p postDo) Delete(models ...*entity.Post) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *postDo) withDO(do gen.Dao) *postDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
466
internal/dao/tag_mappings.gen.go
Normal file
466
internal/dao/tag_mappings.gen.go
Normal file
@ -0,0 +1,466 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newTagMapping(db *gorm.DB, opts ...gen.DOOption) tagMapping {
|
||||
_tagMapping := tagMapping{}
|
||||
|
||||
_tagMapping.tagMappingDo.UseDB(db, opts...)
|
||||
_tagMapping.tagMappingDo.UseModel(&entity.TagMapping{})
|
||||
|
||||
tableName := _tagMapping.tagMappingDo.TableName()
|
||||
_tagMapping.ALL = field.NewAsterisk(tableName)
|
||||
_tagMapping.Id = field.NewUint(tableName, "id")
|
||||
_tagMapping.TagId = field.NewUint(tableName, "tag_id")
|
||||
_tagMapping.Name = field.NewString(tableName, "name")
|
||||
_tagMapping.Tag = tagMappingBelongsToTag{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Tag", "entity.Tag"),
|
||||
}
|
||||
|
||||
_tagMapping.fillFieldMap()
|
||||
|
||||
return _tagMapping
|
||||
}
|
||||
|
||||
type tagMapping struct {
|
||||
tagMappingDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
TagId field.Uint
|
||||
Name field.String
|
||||
Tag tagMappingBelongsToTag
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (t tagMapping) Table(newTableName string) *tagMapping {
|
||||
t.tagMappingDo.UseTable(newTableName)
|
||||
return t.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (t tagMapping) As(alias string) *tagMapping {
|
||||
t.tagMappingDo.DO = *(t.tagMappingDo.As(alias).(*gen.DO))
|
||||
return t.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (t *tagMapping) updateTableName(table string) *tagMapping {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.Id = field.NewUint(table, "id")
|
||||
t.TagId = field.NewUint(table, "tag_id")
|
||||
t.Name = field.NewString(table, "name")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tagMapping) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := t.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (t *tagMapping) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 4)
|
||||
t.fieldMap["id"] = t.Id
|
||||
t.fieldMap["tag_id"] = t.TagId
|
||||
t.fieldMap["name"] = t.Name
|
||||
|
||||
}
|
||||
|
||||
func (t tagMapping) clone(db *gorm.DB) tagMapping {
|
||||
t.tagMappingDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t tagMapping) replaceDB(db *gorm.DB) tagMapping {
|
||||
t.tagMappingDo.ReplaceDB(db)
|
||||
return t
|
||||
}
|
||||
|
||||
type tagMappingBelongsToTag struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTag) Where(conds ...field.Expr) *tagMappingBelongsToTag {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTag) WithContext(ctx context.Context) *tagMappingBelongsToTag {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTag) Session(session *gorm.Session) *tagMappingBelongsToTag {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTag) Model(m *entity.TagMapping) *tagMappingBelongsToTagTx {
|
||||
return &tagMappingBelongsToTagTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type tagMappingBelongsToTagTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a tagMappingBelongsToTagTx) Find() (result *entity.Tag, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTagTx) Append(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTagTx) Replace(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTagTx) Delete(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTagTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a tagMappingBelongsToTagTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type tagMappingDo struct{ gen.DO }
|
||||
|
||||
type ITagMappingDo interface {
|
||||
gen.SubQuery
|
||||
Debug() ITagMappingDo
|
||||
WithContext(ctx context.Context) ITagMappingDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() ITagMappingDo
|
||||
WriteDB() ITagMappingDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) ITagMappingDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) ITagMappingDo
|
||||
Not(conds ...gen.Condition) ITagMappingDo
|
||||
Or(conds ...gen.Condition) ITagMappingDo
|
||||
Select(conds ...field.Expr) ITagMappingDo
|
||||
Where(conds ...gen.Condition) ITagMappingDo
|
||||
Order(conds ...field.Expr) ITagMappingDo
|
||||
Distinct(cols ...field.Expr) ITagMappingDo
|
||||
Omit(cols ...field.Expr) ITagMappingDo
|
||||
Join(table schema.Tabler, on ...field.Expr) ITagMappingDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) ITagMappingDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) ITagMappingDo
|
||||
Group(cols ...field.Expr) ITagMappingDo
|
||||
Having(conds ...gen.Condition) ITagMappingDo
|
||||
Limit(limit int) ITagMappingDo
|
||||
Offset(offset int) ITagMappingDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) ITagMappingDo
|
||||
Unscoped() ITagMappingDo
|
||||
Create(values ...*entity.TagMapping) error
|
||||
CreateInBatches(values []*entity.TagMapping, batchSize int) error
|
||||
Save(values ...*entity.TagMapping) error
|
||||
First() (*entity.TagMapping, error)
|
||||
Take() (*entity.TagMapping, error)
|
||||
Last() (*entity.TagMapping, error)
|
||||
Find() ([]*entity.TagMapping, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.TagMapping, err error)
|
||||
FindInBatches(result *[]*entity.TagMapping, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.TagMapping) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) ITagMappingDo
|
||||
Assign(attrs ...field.AssignExpr) ITagMappingDo
|
||||
Joins(fields ...field.RelationField) ITagMappingDo
|
||||
Preload(fields ...field.RelationField) ITagMappingDo
|
||||
FirstOrInit() (*entity.TagMapping, error)
|
||||
FirstOrCreate() (*entity.TagMapping, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.TagMapping, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) ITagMappingDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Debug() ITagMappingDo {
|
||||
return t.withDO(t.DO.Debug())
|
||||
}
|
||||
|
||||
func (t tagMappingDo) WithContext(ctx context.Context) ITagMappingDo {
|
||||
return t.withDO(t.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) ReadDB() ITagMappingDo {
|
||||
return t.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (t tagMappingDo) WriteDB() ITagMappingDo {
|
||||
return t.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Session(config *gorm.Session) ITagMappingDo {
|
||||
return t.withDO(t.DO.Session(config))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Clauses(conds ...clause.Expression) ITagMappingDo {
|
||||
return t.withDO(t.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Returning(value interface{}, columns ...string) ITagMappingDo {
|
||||
return t.withDO(t.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Not(conds ...gen.Condition) ITagMappingDo {
|
||||
return t.withDO(t.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Or(conds ...gen.Condition) ITagMappingDo {
|
||||
return t.withDO(t.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Select(conds ...field.Expr) ITagMappingDo {
|
||||
return t.withDO(t.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Where(conds ...gen.Condition) ITagMappingDo {
|
||||
return t.withDO(t.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Order(conds ...field.Expr) ITagMappingDo {
|
||||
return t.withDO(t.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Distinct(cols ...field.Expr) ITagMappingDo {
|
||||
return t.withDO(t.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Omit(cols ...field.Expr) ITagMappingDo {
|
||||
return t.withDO(t.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Join(table schema.Tabler, on ...field.Expr) ITagMappingDo {
|
||||
return t.withDO(t.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) LeftJoin(table schema.Tabler, on ...field.Expr) ITagMappingDo {
|
||||
return t.withDO(t.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) RightJoin(table schema.Tabler, on ...field.Expr) ITagMappingDo {
|
||||
return t.withDO(t.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Group(cols ...field.Expr) ITagMappingDo {
|
||||
return t.withDO(t.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Having(conds ...gen.Condition) ITagMappingDo {
|
||||
return t.withDO(t.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Limit(limit int) ITagMappingDo {
|
||||
return t.withDO(t.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Offset(offset int) ITagMappingDo {
|
||||
return t.withDO(t.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ITagMappingDo {
|
||||
return t.withDO(t.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Unscoped() ITagMappingDo {
|
||||
return t.withDO(t.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Create(values ...*entity.TagMapping) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Create(values)
|
||||
}
|
||||
|
||||
func (t tagMappingDo) CreateInBatches(values []*entity.TagMapping, batchSize int) error {
|
||||
return t.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (t tagMappingDo) Save(values ...*entity.TagMapping) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Save(values)
|
||||
}
|
||||
|
||||
func (t tagMappingDo) First() (*entity.TagMapping, error) {
|
||||
if result, err := t.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.TagMapping), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Take() (*entity.TagMapping, error) {
|
||||
if result, err := t.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.TagMapping), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Last() (*entity.TagMapping, error) {
|
||||
if result, err := t.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.TagMapping), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Find() ([]*entity.TagMapping, error) {
|
||||
result, err := t.DO.Find()
|
||||
return result.([]*entity.TagMapping), err
|
||||
}
|
||||
|
||||
func (t tagMappingDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.TagMapping, err error) {
|
||||
buf := make([]*entity.TagMapping, 0, batchSize)
|
||||
err = t.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (t tagMappingDo) FindInBatches(result *[]*entity.TagMapping, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return t.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Attrs(attrs ...field.AssignExpr) ITagMappingDo {
|
||||
return t.withDO(t.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Assign(attrs ...field.AssignExpr) ITagMappingDo {
|
||||
return t.withDO(t.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Joins(fields ...field.RelationField) ITagMappingDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Joins(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Preload(fields ...field.RelationField) ITagMappingDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Preload(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t tagMappingDo) FirstOrInit() (*entity.TagMapping, error) {
|
||||
if result, err := t.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.TagMapping), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagMappingDo) FirstOrCreate() (*entity.TagMapping, error) {
|
||||
if result, err := t.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.TagMapping), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagMappingDo) FindByPage(offset int, limit int) (result []*entity.TagMapping, count int64, err error) {
|
||||
result, err = t.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = t.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (t tagMappingDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = t.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Scan(result interface{}) (err error) {
|
||||
return t.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (t tagMappingDo) Delete(models ...*entity.TagMapping) (result gen.ResultInfo, err error) {
|
||||
return t.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (t *tagMappingDo) withDO(do gen.Dao) *tagMappingDo {
|
||||
t.DO = *do.(*gen.DO)
|
||||
return t
|
||||
}
|
384
internal/dao/tags.gen.go
Normal file
384
internal/dao/tags.gen.go
Normal file
@ -0,0 +1,384 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newTag(db *gorm.DB, opts ...gen.DOOption) tag {
|
||||
_tag := tag{}
|
||||
|
||||
_tag.tagDo.UseDB(db, opts...)
|
||||
_tag.tagDo.UseModel(&entity.Tag{})
|
||||
|
||||
tableName := _tag.tagDo.TableName()
|
||||
_tag.ALL = field.NewAsterisk(tableName)
|
||||
_tag.Id = field.NewUint(tableName, "id")
|
||||
_tag.Name = field.NewString(tableName, "name")
|
||||
|
||||
_tag.fillFieldMap()
|
||||
|
||||
return _tag
|
||||
}
|
||||
|
||||
type tag struct {
|
||||
tagDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
Name field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (t tag) Table(newTableName string) *tag {
|
||||
t.tagDo.UseTable(newTableName)
|
||||
return t.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (t tag) As(alias string) *tag {
|
||||
t.tagDo.DO = *(t.tagDo.As(alias).(*gen.DO))
|
||||
return t.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (t *tag) updateTableName(table string) *tag {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.Id = field.NewUint(table, "id")
|
||||
t.Name = field.NewString(table, "name")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tag) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := t.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (t *tag) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 2)
|
||||
t.fieldMap["id"] = t.Id
|
||||
t.fieldMap["name"] = t.Name
|
||||
}
|
||||
|
||||
func (t tag) clone(db *gorm.DB) tag {
|
||||
t.tagDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t tag) replaceDB(db *gorm.DB) tag {
|
||||
t.tagDo.ReplaceDB(db)
|
||||
return t
|
||||
}
|
||||
|
||||
type tagDo struct{ gen.DO }
|
||||
|
||||
type ITagDo interface {
|
||||
gen.SubQuery
|
||||
Debug() ITagDo
|
||||
WithContext(ctx context.Context) ITagDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() ITagDo
|
||||
WriteDB() ITagDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) ITagDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) ITagDo
|
||||
Not(conds ...gen.Condition) ITagDo
|
||||
Or(conds ...gen.Condition) ITagDo
|
||||
Select(conds ...field.Expr) ITagDo
|
||||
Where(conds ...gen.Condition) ITagDo
|
||||
Order(conds ...field.Expr) ITagDo
|
||||
Distinct(cols ...field.Expr) ITagDo
|
||||
Omit(cols ...field.Expr) ITagDo
|
||||
Join(table schema.Tabler, on ...field.Expr) ITagDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) ITagDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) ITagDo
|
||||
Group(cols ...field.Expr) ITagDo
|
||||
Having(conds ...gen.Condition) ITagDo
|
||||
Limit(limit int) ITagDo
|
||||
Offset(offset int) ITagDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) ITagDo
|
||||
Unscoped() ITagDo
|
||||
Create(values ...*entity.Tag) error
|
||||
CreateInBatches(values []*entity.Tag, batchSize int) error
|
||||
Save(values ...*entity.Tag) error
|
||||
First() (*entity.Tag, error)
|
||||
Take() (*entity.Tag, error)
|
||||
Last() (*entity.Tag, error)
|
||||
Find() ([]*entity.Tag, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Tag, err error)
|
||||
FindInBatches(result *[]*entity.Tag, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.Tag) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) ITagDo
|
||||
Assign(attrs ...field.AssignExpr) ITagDo
|
||||
Joins(fields ...field.RelationField) ITagDo
|
||||
Preload(fields ...field.RelationField) ITagDo
|
||||
FirstOrInit() (*entity.Tag, error)
|
||||
FirstOrCreate() (*entity.Tag, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.Tag, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) ITagDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (t tagDo) Debug() ITagDo {
|
||||
return t.withDO(t.DO.Debug())
|
||||
}
|
||||
|
||||
func (t tagDo) WithContext(ctx context.Context) ITagDo {
|
||||
return t.withDO(t.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (t tagDo) ReadDB() ITagDo {
|
||||
return t.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (t tagDo) WriteDB() ITagDo {
|
||||
return t.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (t tagDo) Session(config *gorm.Session) ITagDo {
|
||||
return t.withDO(t.DO.Session(config))
|
||||
}
|
||||
|
||||
func (t tagDo) Clauses(conds ...clause.Expression) ITagDo {
|
||||
return t.withDO(t.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (t tagDo) Returning(value interface{}, columns ...string) ITagDo {
|
||||
return t.withDO(t.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (t tagDo) Not(conds ...gen.Condition) ITagDo {
|
||||
return t.withDO(t.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (t tagDo) Or(conds ...gen.Condition) ITagDo {
|
||||
return t.withDO(t.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (t tagDo) Select(conds ...field.Expr) ITagDo {
|
||||
return t.withDO(t.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (t tagDo) Where(conds ...gen.Condition) ITagDo {
|
||||
return t.withDO(t.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (t tagDo) Order(conds ...field.Expr) ITagDo {
|
||||
return t.withDO(t.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (t tagDo) Distinct(cols ...field.Expr) ITagDo {
|
||||
return t.withDO(t.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (t tagDo) Omit(cols ...field.Expr) ITagDo {
|
||||
return t.withDO(t.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (t tagDo) Join(table schema.Tabler, on ...field.Expr) ITagDo {
|
||||
return t.withDO(t.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (t tagDo) LeftJoin(table schema.Tabler, on ...field.Expr) ITagDo {
|
||||
return t.withDO(t.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t tagDo) RightJoin(table schema.Tabler, on ...field.Expr) ITagDo {
|
||||
return t.withDO(t.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t tagDo) Group(cols ...field.Expr) ITagDo {
|
||||
return t.withDO(t.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (t tagDo) Having(conds ...gen.Condition) ITagDo {
|
||||
return t.withDO(t.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (t tagDo) Limit(limit int) ITagDo {
|
||||
return t.withDO(t.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (t tagDo) Offset(offset int) ITagDo {
|
||||
return t.withDO(t.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (t tagDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ITagDo {
|
||||
return t.withDO(t.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (t tagDo) Unscoped() ITagDo {
|
||||
return t.withDO(t.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (t tagDo) Create(values ...*entity.Tag) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Create(values)
|
||||
}
|
||||
|
||||
func (t tagDo) CreateInBatches(values []*entity.Tag, batchSize int) error {
|
||||
return t.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (t tagDo) Save(values ...*entity.Tag) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Save(values)
|
||||
}
|
||||
|
||||
func (t tagDo) First() (*entity.Tag, error) {
|
||||
if result, err := t.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Tag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagDo) Take() (*entity.Tag, error) {
|
||||
if result, err := t.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Tag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagDo) Last() (*entity.Tag, error) {
|
||||
if result, err := t.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Tag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagDo) Find() ([]*entity.Tag, error) {
|
||||
result, err := t.DO.Find()
|
||||
return result.([]*entity.Tag), err
|
||||
}
|
||||
|
||||
func (t tagDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Tag, err error) {
|
||||
buf := make([]*entity.Tag, 0, batchSize)
|
||||
err = t.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (t tagDo) FindInBatches(result *[]*entity.Tag, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return t.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (t tagDo) Attrs(attrs ...field.AssignExpr) ITagDo {
|
||||
return t.withDO(t.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (t tagDo) Assign(attrs ...field.AssignExpr) ITagDo {
|
||||
return t.withDO(t.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (t tagDo) Joins(fields ...field.RelationField) ITagDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Joins(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t tagDo) Preload(fields ...field.RelationField) ITagDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Preload(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t tagDo) FirstOrInit() (*entity.Tag, error) {
|
||||
if result, err := t.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Tag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagDo) FirstOrCreate() (*entity.Tag, error) {
|
||||
if result, err := t.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.Tag), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tagDo) FindByPage(offset int, limit int) (result []*entity.Tag, count int64, err error) {
|
||||
result, err = t.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = t.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (t tagDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = t.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (t tagDo) Scan(result interface{}) (err error) {
|
||||
return t.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (t tagDo) Delete(models ...*entity.Tag) (result gen.ResultInfo, err error) {
|
||||
return t.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (t *tagDo) withDO(do gen.Dao) *tagDo {
|
||||
t.DO = *do.(*gen.DO)
|
||||
return t
|
||||
}
|
388
internal/dao/user_likes.gen.go
Normal file
388
internal/dao/user_likes.gen.go
Normal file
@ -0,0 +1,388 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newUserLike(db *gorm.DB, opts ...gen.DOOption) userLike {
|
||||
_userLike := userLike{}
|
||||
|
||||
_userLike.userLikeDo.UseDB(db, opts...)
|
||||
_userLike.userLikeDo.UseModel(&entity.UserLike{})
|
||||
|
||||
tableName := _userLike.userLikeDo.TableName()
|
||||
_userLike.ALL = field.NewAsterisk(tableName)
|
||||
_userLike.UserId = field.NewString(tableName, "user_id")
|
||||
_userLike.PostId = field.NewUint(tableName, "post_id")
|
||||
_userLike.Type = field.NewString(tableName, "type")
|
||||
|
||||
_userLike.fillFieldMap()
|
||||
|
||||
return _userLike
|
||||
}
|
||||
|
||||
type userLike struct {
|
||||
userLikeDo
|
||||
|
||||
ALL field.Asterisk
|
||||
UserId field.String
|
||||
PostId field.Uint
|
||||
Type field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (u userLike) Table(newTableName string) *userLike {
|
||||
u.userLikeDo.UseTable(newTableName)
|
||||
return u.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (u userLike) As(alias string) *userLike {
|
||||
u.userLikeDo.DO = *(u.userLikeDo.As(alias).(*gen.DO))
|
||||
return u.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (u *userLike) updateTableName(table string) *userLike {
|
||||
u.ALL = field.NewAsterisk(table)
|
||||
u.UserId = field.NewString(table, "user_id")
|
||||
u.PostId = field.NewUint(table, "post_id")
|
||||
u.Type = field.NewString(table, "type")
|
||||
|
||||
u.fillFieldMap()
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *userLike) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := u.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (u *userLike) fillFieldMap() {
|
||||
u.fieldMap = make(map[string]field.Expr, 3)
|
||||
u.fieldMap["user_id"] = u.UserId
|
||||
u.fieldMap["post_id"] = u.PostId
|
||||
u.fieldMap["type"] = u.Type
|
||||
}
|
||||
|
||||
func (u userLike) clone(db *gorm.DB) userLike {
|
||||
u.userLikeDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return u
|
||||
}
|
||||
|
||||
func (u userLike) replaceDB(db *gorm.DB) userLike {
|
||||
u.userLikeDo.ReplaceDB(db)
|
||||
return u
|
||||
}
|
||||
|
||||
type userLikeDo struct{ gen.DO }
|
||||
|
||||
type IUserLikeDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IUserLikeDo
|
||||
WithContext(ctx context.Context) IUserLikeDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IUserLikeDo
|
||||
WriteDB() IUserLikeDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IUserLikeDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IUserLikeDo
|
||||
Not(conds ...gen.Condition) IUserLikeDo
|
||||
Or(conds ...gen.Condition) IUserLikeDo
|
||||
Select(conds ...field.Expr) IUserLikeDo
|
||||
Where(conds ...gen.Condition) IUserLikeDo
|
||||
Order(conds ...field.Expr) IUserLikeDo
|
||||
Distinct(cols ...field.Expr) IUserLikeDo
|
||||
Omit(cols ...field.Expr) IUserLikeDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IUserLikeDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IUserLikeDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IUserLikeDo
|
||||
Group(cols ...field.Expr) IUserLikeDo
|
||||
Having(conds ...gen.Condition) IUserLikeDo
|
||||
Limit(limit int) IUserLikeDo
|
||||
Offset(offset int) IUserLikeDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IUserLikeDo
|
||||
Unscoped() IUserLikeDo
|
||||
Create(values ...*entity.UserLike) error
|
||||
CreateInBatches(values []*entity.UserLike, batchSize int) error
|
||||
Save(values ...*entity.UserLike) error
|
||||
First() (*entity.UserLike, error)
|
||||
Take() (*entity.UserLike, error)
|
||||
Last() (*entity.UserLike, error)
|
||||
Find() ([]*entity.UserLike, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.UserLike, err error)
|
||||
FindInBatches(result *[]*entity.UserLike, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.UserLike) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IUserLikeDo
|
||||
Assign(attrs ...field.AssignExpr) IUserLikeDo
|
||||
Joins(fields ...field.RelationField) IUserLikeDo
|
||||
Preload(fields ...field.RelationField) IUserLikeDo
|
||||
FirstOrInit() (*entity.UserLike, error)
|
||||
FirstOrCreate() (*entity.UserLike, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.UserLike, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IUserLikeDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (u userLikeDo) Debug() IUserLikeDo {
|
||||
return u.withDO(u.DO.Debug())
|
||||
}
|
||||
|
||||
func (u userLikeDo) WithContext(ctx context.Context) IUserLikeDo {
|
||||
return u.withDO(u.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (u userLikeDo) ReadDB() IUserLikeDo {
|
||||
return u.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (u userLikeDo) WriteDB() IUserLikeDo {
|
||||
return u.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (u userLikeDo) Session(config *gorm.Session) IUserLikeDo {
|
||||
return u.withDO(u.DO.Session(config))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Clauses(conds ...clause.Expression) IUserLikeDo {
|
||||
return u.withDO(u.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Returning(value interface{}, columns ...string) IUserLikeDo {
|
||||
return u.withDO(u.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Not(conds ...gen.Condition) IUserLikeDo {
|
||||
return u.withDO(u.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Or(conds ...gen.Condition) IUserLikeDo {
|
||||
return u.withDO(u.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Select(conds ...field.Expr) IUserLikeDo {
|
||||
return u.withDO(u.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Where(conds ...gen.Condition) IUserLikeDo {
|
||||
return u.withDO(u.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Order(conds ...field.Expr) IUserLikeDo {
|
||||
return u.withDO(u.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Distinct(cols ...field.Expr) IUserLikeDo {
|
||||
return u.withDO(u.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Omit(cols ...field.Expr) IUserLikeDo {
|
||||
return u.withDO(u.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Join(table schema.Tabler, on ...field.Expr) IUserLikeDo {
|
||||
return u.withDO(u.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserLikeDo {
|
||||
return u.withDO(u.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserLikeDo {
|
||||
return u.withDO(u.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Group(cols ...field.Expr) IUserLikeDo {
|
||||
return u.withDO(u.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Having(conds ...gen.Condition) IUserLikeDo {
|
||||
return u.withDO(u.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Limit(limit int) IUserLikeDo {
|
||||
return u.withDO(u.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Offset(offset int) IUserLikeDo {
|
||||
return u.withDO(u.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserLikeDo {
|
||||
return u.withDO(u.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Unscoped() IUserLikeDo {
|
||||
return u.withDO(u.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (u userLikeDo) Create(values ...*entity.UserLike) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return u.DO.Create(values)
|
||||
}
|
||||
|
||||
func (u userLikeDo) CreateInBatches(values []*entity.UserLike, batchSize int) error {
|
||||
return u.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (u userLikeDo) Save(values ...*entity.UserLike) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return u.DO.Save(values)
|
||||
}
|
||||
|
||||
func (u userLikeDo) First() (*entity.UserLike, error) {
|
||||
if result, err := u.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserLike), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userLikeDo) Take() (*entity.UserLike, error) {
|
||||
if result, err := u.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserLike), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userLikeDo) Last() (*entity.UserLike, error) {
|
||||
if result, err := u.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserLike), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userLikeDo) Find() ([]*entity.UserLike, error) {
|
||||
result, err := u.DO.Find()
|
||||
return result.([]*entity.UserLike), err
|
||||
}
|
||||
|
||||
func (u userLikeDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.UserLike, err error) {
|
||||
buf := make([]*entity.UserLike, 0, batchSize)
|
||||
err = u.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (u userLikeDo) FindInBatches(result *[]*entity.UserLike, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return u.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (u userLikeDo) Attrs(attrs ...field.AssignExpr) IUserLikeDo {
|
||||
return u.withDO(u.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Assign(attrs ...field.AssignExpr) IUserLikeDo {
|
||||
return u.withDO(u.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (u userLikeDo) Joins(fields ...field.RelationField) IUserLikeDo {
|
||||
for _, _f := range fields {
|
||||
u = *u.withDO(u.DO.Joins(_f))
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u userLikeDo) Preload(fields ...field.RelationField) IUserLikeDo {
|
||||
for _, _f := range fields {
|
||||
u = *u.withDO(u.DO.Preload(_f))
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u userLikeDo) FirstOrInit() (*entity.UserLike, error) {
|
||||
if result, err := u.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserLike), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userLikeDo) FirstOrCreate() (*entity.UserLike, error) {
|
||||
if result, err := u.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserLike), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userLikeDo) FindByPage(offset int, limit int) (result []*entity.UserLike, count int64, err error) {
|
||||
result, err = u.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = u.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (u userLikeDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = u.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = u.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (u userLikeDo) Scan(result interface{}) (err error) {
|
||||
return u.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (u userLikeDo) Delete(models ...*entity.UserLike) (result gen.ResultInfo, err error) {
|
||||
return u.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (u *userLikeDo) withDO(do gen.Dao) *userLikeDo {
|
||||
u.DO = *do.(*gen.DO)
|
||||
return u
|
||||
}
|
466
internal/dao/user_tag_scores.gen.go
Normal file
466
internal/dao/user_tag_scores.gen.go
Normal file
@ -0,0 +1,466 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newUserTagScore(db *gorm.DB, opts ...gen.DOOption) userTagScore {
|
||||
_userTagScore := userTagScore{}
|
||||
|
||||
_userTagScore.userTagScoreDo.UseDB(db, opts...)
|
||||
_userTagScore.userTagScoreDo.UseModel(&entity.UserTagScore{})
|
||||
|
||||
tableName := _userTagScore.userTagScoreDo.TableName()
|
||||
_userTagScore.ALL = field.NewAsterisk(tableName)
|
||||
_userTagScore.UserId = field.NewString(tableName, "user_id")
|
||||
_userTagScore.TagId = field.NewUint(tableName, "tag_id")
|
||||
_userTagScore.Score = field.NewInt(tableName, "score")
|
||||
_userTagScore.Tag = userTagScoreBelongsToTag{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Tag", "entity.Tag"),
|
||||
}
|
||||
|
||||
_userTagScore.fillFieldMap()
|
||||
|
||||
return _userTagScore
|
||||
}
|
||||
|
||||
type userTagScore struct {
|
||||
userTagScoreDo
|
||||
|
||||
ALL field.Asterisk
|
||||
UserId field.String
|
||||
TagId field.Uint
|
||||
Score field.Int
|
||||
Tag userTagScoreBelongsToTag
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (u userTagScore) Table(newTableName string) *userTagScore {
|
||||
u.userTagScoreDo.UseTable(newTableName)
|
||||
return u.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (u userTagScore) As(alias string) *userTagScore {
|
||||
u.userTagScoreDo.DO = *(u.userTagScoreDo.As(alias).(*gen.DO))
|
||||
return u.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (u *userTagScore) updateTableName(table string) *userTagScore {
|
||||
u.ALL = field.NewAsterisk(table)
|
||||
u.UserId = field.NewString(table, "user_id")
|
||||
u.TagId = field.NewUint(table, "tag_id")
|
||||
u.Score = field.NewInt(table, "score")
|
||||
|
||||
u.fillFieldMap()
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *userTagScore) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := u.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (u *userTagScore) fillFieldMap() {
|
||||
u.fieldMap = make(map[string]field.Expr, 4)
|
||||
u.fieldMap["user_id"] = u.UserId
|
||||
u.fieldMap["tag_id"] = u.TagId
|
||||
u.fieldMap["score"] = u.Score
|
||||
|
||||
}
|
||||
|
||||
func (u userTagScore) clone(db *gorm.DB) userTagScore {
|
||||
u.userTagScoreDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return u
|
||||
}
|
||||
|
||||
func (u userTagScore) replaceDB(db *gorm.DB) userTagScore {
|
||||
u.userTagScoreDo.ReplaceDB(db)
|
||||
return u
|
||||
}
|
||||
|
||||
type userTagScoreBelongsToTag struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTag) Where(conds ...field.Expr) *userTagScoreBelongsToTag {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTag) WithContext(ctx context.Context) *userTagScoreBelongsToTag {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTag) Session(session *gorm.Session) *userTagScoreBelongsToTag {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTag) Model(m *entity.UserTagScore) *userTagScoreBelongsToTagTx {
|
||||
return &userTagScoreBelongsToTagTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type userTagScoreBelongsToTagTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a userTagScoreBelongsToTagTx) Find() (result *entity.Tag, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTagTx) Append(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTagTx) Replace(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTagTx) Delete(values ...*entity.Tag) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTagTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a userTagScoreBelongsToTagTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type userTagScoreDo struct{ gen.DO }
|
||||
|
||||
type IUserTagScoreDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IUserTagScoreDo
|
||||
WithContext(ctx context.Context) IUserTagScoreDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IUserTagScoreDo
|
||||
WriteDB() IUserTagScoreDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IUserTagScoreDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IUserTagScoreDo
|
||||
Not(conds ...gen.Condition) IUserTagScoreDo
|
||||
Or(conds ...gen.Condition) IUserTagScoreDo
|
||||
Select(conds ...field.Expr) IUserTagScoreDo
|
||||
Where(conds ...gen.Condition) IUserTagScoreDo
|
||||
Order(conds ...field.Expr) IUserTagScoreDo
|
||||
Distinct(cols ...field.Expr) IUserTagScoreDo
|
||||
Omit(cols ...field.Expr) IUserTagScoreDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IUserTagScoreDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IUserTagScoreDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IUserTagScoreDo
|
||||
Group(cols ...field.Expr) IUserTagScoreDo
|
||||
Having(conds ...gen.Condition) IUserTagScoreDo
|
||||
Limit(limit int) IUserTagScoreDo
|
||||
Offset(offset int) IUserTagScoreDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IUserTagScoreDo
|
||||
Unscoped() IUserTagScoreDo
|
||||
Create(values ...*entity.UserTagScore) error
|
||||
CreateInBatches(values []*entity.UserTagScore, batchSize int) error
|
||||
Save(values ...*entity.UserTagScore) error
|
||||
First() (*entity.UserTagScore, error)
|
||||
Take() (*entity.UserTagScore, error)
|
||||
Last() (*entity.UserTagScore, error)
|
||||
Find() ([]*entity.UserTagScore, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.UserTagScore, err error)
|
||||
FindInBatches(result *[]*entity.UserTagScore, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.UserTagScore) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IUserTagScoreDo
|
||||
Assign(attrs ...field.AssignExpr) IUserTagScoreDo
|
||||
Joins(fields ...field.RelationField) IUserTagScoreDo
|
||||
Preload(fields ...field.RelationField) IUserTagScoreDo
|
||||
FirstOrInit() (*entity.UserTagScore, error)
|
||||
FirstOrCreate() (*entity.UserTagScore, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.UserTagScore, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IUserTagScoreDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Debug() IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Debug())
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) WithContext(ctx context.Context) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) ReadDB() IUserTagScoreDo {
|
||||
return u.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) WriteDB() IUserTagScoreDo {
|
||||
return u.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Session(config *gorm.Session) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Session(config))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Clauses(conds ...clause.Expression) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Returning(value interface{}, columns ...string) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Not(conds ...gen.Condition) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Or(conds ...gen.Condition) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Select(conds ...field.Expr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Where(conds ...gen.Condition) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Order(conds ...field.Expr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Distinct(cols ...field.Expr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Omit(cols ...field.Expr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Join(table schema.Tabler, on ...field.Expr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Group(cols ...field.Expr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Having(conds ...gen.Condition) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Limit(limit int) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Offset(offset int) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Unscoped() IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Create(values ...*entity.UserTagScore) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return u.DO.Create(values)
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) CreateInBatches(values []*entity.UserTagScore, batchSize int) error {
|
||||
return u.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (u userTagScoreDo) Save(values ...*entity.UserTagScore) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return u.DO.Save(values)
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) First() (*entity.UserTagScore, error) {
|
||||
if result, err := u.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserTagScore), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Take() (*entity.UserTagScore, error) {
|
||||
if result, err := u.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserTagScore), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Last() (*entity.UserTagScore, error) {
|
||||
if result, err := u.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserTagScore), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Find() ([]*entity.UserTagScore, error) {
|
||||
result, err := u.DO.Find()
|
||||
return result.([]*entity.UserTagScore), err
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.UserTagScore, err error) {
|
||||
buf := make([]*entity.UserTagScore, 0, batchSize)
|
||||
err = u.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) FindInBatches(result *[]*entity.UserTagScore, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return u.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Attrs(attrs ...field.AssignExpr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Assign(attrs ...field.AssignExpr) IUserTagScoreDo {
|
||||
return u.withDO(u.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Joins(fields ...field.RelationField) IUserTagScoreDo {
|
||||
for _, _f := range fields {
|
||||
u = *u.withDO(u.DO.Joins(_f))
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Preload(fields ...field.RelationField) IUserTagScoreDo {
|
||||
for _, _f := range fields {
|
||||
u = *u.withDO(u.DO.Preload(_f))
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) FirstOrInit() (*entity.UserTagScore, error) {
|
||||
if result, err := u.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserTagScore), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) FirstOrCreate() (*entity.UserTagScore, error) {
|
||||
if result, err := u.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.UserTagScore), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) FindByPage(offset int, limit int) (result []*entity.UserTagScore, count int64, err error) {
|
||||
result, err = u.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = u.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = u.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = u.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Scan(result interface{}) (err error) {
|
||||
return u.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (u userTagScoreDo) Delete(models ...*entity.UserTagScore) (result gen.ResultInfo, err error) {
|
||||
return u.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (u *userTagScoreDo) withDO(do gen.Dao) *userTagScoreDo {
|
||||
u.DO = *do.(*gen.DO)
|
||||
return u
|
||||
}
|
@ -1,392 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
||||
_user := user{}
|
||||
|
||||
_user.userDo.UseDB(db, opts...)
|
||||
_user.userDo.UseModel(&entity.User{})
|
||||
|
||||
tableName := _user.userDo.TableName()
|
||||
_user.ALL = field.NewAsterisk(tableName)
|
||||
_user.Id = field.NewUint(tableName, "id")
|
||||
_user.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_user.Name = field.NewString(tableName, "name")
|
||||
|
||||
_user.fillFieldMap()
|
||||
|
||||
return _user
|
||||
}
|
||||
|
||||
type user struct {
|
||||
userDo
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Uint
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
Name field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (u user) Table(newTableName string) *user {
|
||||
u.userDo.UseTable(newTableName)
|
||||
return u.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (u user) As(alias string) *user {
|
||||
u.userDo.DO = *(u.userDo.As(alias).(*gen.DO))
|
||||
return u.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (u *user) updateTableName(table string) *user {
|
||||
u.ALL = field.NewAsterisk(table)
|
||||
u.Id = field.NewUint(table, "id")
|
||||
u.CreatedAt = field.NewTime(table, "created_at")
|
||||
u.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
u.Name = field.NewString(table, "name")
|
||||
|
||||
u.fillFieldMap()
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := u.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (u *user) fillFieldMap() {
|
||||
u.fieldMap = make(map[string]field.Expr, 4)
|
||||
u.fieldMap["id"] = u.Id
|
||||
u.fieldMap["created_at"] = u.CreatedAt
|
||||
u.fieldMap["updated_at"] = u.UpdatedAt
|
||||
u.fieldMap["name"] = u.Name
|
||||
}
|
||||
|
||||
func (u user) clone(db *gorm.DB) user {
|
||||
u.userDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return u
|
||||
}
|
||||
|
||||
func (u user) replaceDB(db *gorm.DB) user {
|
||||
u.userDo.ReplaceDB(db)
|
||||
return u
|
||||
}
|
||||
|
||||
type userDo struct{ gen.DO }
|
||||
|
||||
type IUserDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IUserDo
|
||||
WithContext(ctx context.Context) IUserDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IUserDo
|
||||
WriteDB() IUserDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IUserDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IUserDo
|
||||
Not(conds ...gen.Condition) IUserDo
|
||||
Or(conds ...gen.Condition) IUserDo
|
||||
Select(conds ...field.Expr) IUserDo
|
||||
Where(conds ...gen.Condition) IUserDo
|
||||
Order(conds ...field.Expr) IUserDo
|
||||
Distinct(cols ...field.Expr) IUserDo
|
||||
Omit(cols ...field.Expr) IUserDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IUserDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IUserDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IUserDo
|
||||
Group(cols ...field.Expr) IUserDo
|
||||
Having(conds ...gen.Condition) IUserDo
|
||||
Limit(limit int) IUserDo
|
||||
Offset(offset int) IUserDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IUserDo
|
||||
Unscoped() IUserDo
|
||||
Create(values ...*entity.User) error
|
||||
CreateInBatches(values []*entity.User, batchSize int) error
|
||||
Save(values ...*entity.User) error
|
||||
First() (*entity.User, error)
|
||||
Take() (*entity.User, error)
|
||||
Last() (*entity.User, error)
|
||||
Find() ([]*entity.User, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.User, err error)
|
||||
FindInBatches(result *[]*entity.User, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*entity.User) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IUserDo
|
||||
Assign(attrs ...field.AssignExpr) IUserDo
|
||||
Joins(fields ...field.RelationField) IUserDo
|
||||
Preload(fields ...field.RelationField) IUserDo
|
||||
FirstOrInit() (*entity.User, error)
|
||||
FirstOrCreate() (*entity.User, error)
|
||||
FindByPage(offset int, limit int) (result []*entity.User, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IUserDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (u userDo) Debug() IUserDo {
|
||||
return u.withDO(u.DO.Debug())
|
||||
}
|
||||
|
||||
func (u userDo) WithContext(ctx context.Context) IUserDo {
|
||||
return u.withDO(u.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (u userDo) ReadDB() IUserDo {
|
||||
return u.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (u userDo) WriteDB() IUserDo {
|
||||
return u.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (u userDo) Session(config *gorm.Session) IUserDo {
|
||||
return u.withDO(u.DO.Session(config))
|
||||
}
|
||||
|
||||
func (u userDo) Clauses(conds ...clause.Expression) IUserDo {
|
||||
return u.withDO(u.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Returning(value interface{}, columns ...string) IUserDo {
|
||||
return u.withDO(u.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (u userDo) Not(conds ...gen.Condition) IUserDo {
|
||||
return u.withDO(u.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Or(conds ...gen.Condition) IUserDo {
|
||||
return u.withDO(u.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Select(conds ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Where(conds ...gen.Condition) IUserDo {
|
||||
return u.withDO(u.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Order(conds ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Distinct(cols ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (u userDo) Omit(cols ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (u userDo) Join(table schema.Tabler, on ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (u userDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (u userDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (u userDo) Group(cols ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (u userDo) Having(conds ...gen.Condition) IUserDo {
|
||||
return u.withDO(u.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Limit(limit int) IUserDo {
|
||||
return u.withDO(u.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (u userDo) Offset(offset int) IUserDo {
|
||||
return u.withDO(u.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (u userDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserDo {
|
||||
return u.withDO(u.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (u userDo) Unscoped() IUserDo {
|
||||
return u.withDO(u.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (u userDo) Create(values ...*entity.User) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return u.DO.Create(values)
|
||||
}
|
||||
|
||||
func (u userDo) CreateInBatches(values []*entity.User, batchSize int) error {
|
||||
return u.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (u userDo) Save(values ...*entity.User) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return u.DO.Save(values)
|
||||
}
|
||||
|
||||
func (u userDo) First() (*entity.User, error) {
|
||||
if result, err := u.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) Take() (*entity.User, error) {
|
||||
if result, err := u.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) Last() (*entity.User, error) {
|
||||
if result, err := u.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) Find() ([]*entity.User, error) {
|
||||
result, err := u.DO.Find()
|
||||
return result.([]*entity.User), err
|
||||
}
|
||||
|
||||
func (u userDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.User, err error) {
|
||||
buf := make([]*entity.User, 0, batchSize)
|
||||
err = u.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (u userDo) FindInBatches(result *[]*entity.User, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return u.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (u userDo) Attrs(attrs ...field.AssignExpr) IUserDo {
|
||||
return u.withDO(u.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (u userDo) Assign(attrs ...field.AssignExpr) IUserDo {
|
||||
return u.withDO(u.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (u userDo) Joins(fields ...field.RelationField) IUserDo {
|
||||
for _, _f := range fields {
|
||||
u = *u.withDO(u.DO.Joins(_f))
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u userDo) Preload(fields ...field.RelationField) IUserDo {
|
||||
for _, _f := range fields {
|
||||
u = *u.withDO(u.DO.Preload(_f))
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u userDo) FirstOrInit() (*entity.User, error) {
|
||||
if result, err := u.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) FirstOrCreate() (*entity.User, error) {
|
||||
if result, err := u.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*entity.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) FindByPage(offset int, limit int) (result []*entity.User, count int64, err error) {
|
||||
result, err = u.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = u.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (u userDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = u.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = u.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (u userDo) Scan(result interface{}) (err error) {
|
||||
return u.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (u userDo) Delete(models ...*entity.User) (result gen.ResultInfo, err error) {
|
||||
return u.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (u *userDo) withDO(do gen.Dao) *userDo {
|
||||
u.DO = *do.(*gen.DO)
|
||||
return u
|
||||
}
|
27
internal/entity/Application.go
Normal file
27
internal/entity/Application.go
Normal file
@ -0,0 +1,27 @@
|
||||
package entity
|
||||
|
||||
import "leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
|
||||
type Application struct {
|
||||
Model
|
||||
|
||||
Name string `json:"name"`
|
||||
UserId schema.UserId `json:"user_id"`
|
||||
}
|
||||
|
||||
func (u *Application) TableName() string {
|
||||
return "applications"
|
||||
}
|
||||
|
||||
type ApplicationToken struct {
|
||||
Model
|
||||
|
||||
Token string
|
||||
|
||||
ApplicationId schema.EntityId `json:"application_id"`
|
||||
Application *Application `json:"application"`
|
||||
}
|
||||
|
||||
func (u *ApplicationToken) TableName() string {
|
||||
return "application_tokens"
|
||||
}
|
28
internal/entity/Post.go
Normal file
28
internal/entity/Post.go
Normal file
@ -0,0 +1,28 @@
|
||||
package entity
|
||||
|
||||
import "leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
|
||||
type Post struct {
|
||||
Model
|
||||
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
TargetId string `json:"target_id"`
|
||||
Processed bool `json:"processed"`
|
||||
}
|
||||
|
||||
func (u *Post) TableName() string {
|
||||
return "posts"
|
||||
}
|
||||
|
||||
type PostTag struct {
|
||||
Id schema.EntityId `gorm:"primarykey" json:"id"`
|
||||
PostId *schema.EntityId `gorm:"primarykey" json:"post_id"`
|
||||
Post *Post
|
||||
TagId *schema.EntityId `gorm:"primarykey" json:"tag_id"`
|
||||
Tag *Tag
|
||||
}
|
||||
|
||||
func (u *PostTag) TableName() string {
|
||||
return "post_tags"
|
||||
}
|
12
internal/entity/Tag.go
Normal file
12
internal/entity/Tag.go
Normal file
@ -0,0 +1,12 @@
|
||||
package entity
|
||||
|
||||
import "leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
|
||||
type Tag struct {
|
||||
Id schema.EntityId `gorm:"primarykey" json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (u *Tag) TableName() string {
|
||||
return "tags"
|
||||
}
|
14
internal/entity/TagMapping.go
Normal file
14
internal/entity/TagMapping.go
Normal file
@ -0,0 +1,14 @@
|
||||
package entity
|
||||
|
||||
import "leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
|
||||
type TagMapping struct {
|
||||
Id schema.EntityId `gorm:"primarykey" json:"id"`
|
||||
TagId *schema.EntityId `gorm:"primarykey" json:"tag_id"`
|
||||
Tag *Tag `json:"tag"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (u *TagMapping) TableName() string {
|
||||
return "tag_mappings"
|
||||
}
|
@ -1,10 +1,33 @@
|
||||
package entity
|
||||
|
||||
import "leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
|
||||
type User struct {
|
||||
Model
|
||||
Name string `json:"name"`
|
||||
Id schema.EntityId `gorm:"primarykey" json:"id"`
|
||||
Title string `json:"name"`
|
||||
}
|
||||
|
||||
func (u *User) TableName() string {
|
||||
return "user"
|
||||
return "users"
|
||||
}
|
||||
|
||||
type UserLike struct {
|
||||
UserId schema.UserId `gorm:"primarykey" json:"user_id"`
|
||||
PostId schema.EntityId `gorm:"primarykey" json:"post_id"`
|
||||
Type schema.UserLikeType `json:"type"`
|
||||
}
|
||||
|
||||
func (u *UserLike) TableName() string {
|
||||
return "user_likes"
|
||||
}
|
||||
|
||||
type UserTagScore struct {
|
||||
UserId schema.UserId `gorm:"primarykey" json:"user_id"`
|
||||
TagId schema.EntityId `gorm:"primarykey" json:"tag_id"`
|
||||
Tag *Tag
|
||||
Score int `json:"score"`
|
||||
}
|
||||
|
||||
func (u *UserTagScore) TableName() string {
|
||||
return "user_tag_scores"
|
||||
}
|
||||
|
153
internal/handler/http/controller/v1/applications.go
Normal file
153
internal/handler/http/controller/v1/applications.go
Normal file
@ -0,0 +1,153 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"leafdev.top/Ecosystem/recommender/internal/handler/http/response"
|
||||
"leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/application"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/auth"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ApplicationController struct {
|
||||
authService *auth.Service
|
||||
applicationService *application.Service
|
||||
}
|
||||
|
||||
func NewApplicationController(authService *auth.Service, applicationService *application.Service) *ApplicationController {
|
||||
return &ApplicationController{
|
||||
authService,
|
||||
applicationService,
|
||||
}
|
||||
}
|
||||
|
||||
// List godoc
|
||||
// @Summary List Applications
|
||||
// @Description 列出当前用户下的应用程序列表
|
||||
// @Tags applications
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} schema.ResponseBody{data=[]entity.Application}
|
||||
// @Failure 400 {object} schema.ResponseBody
|
||||
// @Router /api/v1/applications [get]
|
||||
func (u *ApplicationController) List(c *gin.Context) {
|
||||
user := u.authService.GetUser(c)
|
||||
|
||||
applications, err := u.applicationService.ListApplications(c, &user.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
response.Ctx(c).Status(http.StatusOK).Data(applications).Send()
|
||||
}
|
||||
|
||||
// Save godoc
|
||||
// @Summary 创建并保存一个应用程序
|
||||
// @Description 创建一个应用程序
|
||||
// @Tags applications
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param ApplicationCreateRequest body schema.ApplicationCreateRequest true "创建应用程序的请求"
|
||||
// @Success 200 {object} schema.ResponseBody{data=[]entity.Application}
|
||||
// @Failure 400 {object} schema.ResponseBody
|
||||
// @Router /api/v1/applications [post]
|
||||
func (u *ApplicationController) Save(c *gin.Context) {
|
||||
user := u.authService.GetUser(c)
|
||||
|
||||
var applicationCreateRequest = &schema.ApplicationCreateRequest{}
|
||||
if err := c.ShouldBindJSON(applicationCreateRequest); err != nil {
|
||||
response.Ctx(c).Error(err).Status(http.StatusBadRequest).Send()
|
||||
return
|
||||
}
|
||||
|
||||
applications, err := u.applicationService.CreateApplication(c, applicationCreateRequest.Name, user.ID)
|
||||
if err != nil {
|
||||
response.Ctx(c).Error(err).Send()
|
||||
return
|
||||
}
|
||||
|
||||
response.Ctx(c).Status(http.StatusOK).Data(applications).Send()
|
||||
}
|
||||
|
||||
// ListToken godoc
|
||||
// @Summary 获取应用程序的 Token 列表
|
||||
// @Description 获取应用程序的 Token 列表
|
||||
// @Tags applications
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param application_id path schema.ApplicationId true "应用程序 ID"
|
||||
// @Success 200 {object} schema.ResponseBody{data=[]entity.ApplicationToken}
|
||||
// @Failure 400 {object} schema.ResponseBody
|
||||
// @Router /api/v1/application/{application_id}/tokens [get]
|
||||
func (u *ApplicationController) ListToken(c *gin.Context) {
|
||||
user := u.authService.GetUser(c)
|
||||
|
||||
var applicationRequest = &schema.ApplicationId{}
|
||||
if err := c.ShouldBindUri(applicationRequest); err != nil {
|
||||
response.Ctx(c).Error(err).Status(http.StatusBadRequest).Send()
|
||||
return
|
||||
}
|
||||
|
||||
applicationEntity, err := u.applicationService.GetApplicationById(c, applicationRequest.ApplicationId)
|
||||
if err != nil {
|
||||
response.Ctx(c).Error(err).Send()
|
||||
return
|
||||
}
|
||||
|
||||
if applicationEntity.UserId != user.ID {
|
||||
response.Ctx(c).Status(http.StatusForbidden).Send()
|
||||
return
|
||||
}
|
||||
|
||||
applicationTokens, err := u.applicationService.ListToken(c, applicationEntity)
|
||||
if err != nil {
|
||||
response.Ctx(c).Error(err).Send()
|
||||
return
|
||||
}
|
||||
|
||||
response.Ctx(c).Status(http.StatusOK).Data(applicationTokens).Send()
|
||||
}
|
||||
|
||||
// SaveToken godoc
|
||||
// @Summary 获取应用程序的 Token 列表
|
||||
// @Description 获取应用程序的 Token 列表
|
||||
// @Tags applications
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param application_id path schema.ApplicationId true "应用程序 ID"
|
||||
// @Param ApplicationCreateRequest body schema.ApplicationCreateRequest true "创建应用程序的请求"
|
||||
// @Success 200 {object} schema.ResponseBody{data=entity.ApplicationToken}
|
||||
// @Failure 400 {object} schema.ResponseBody
|
||||
// @Router /api/v1/application/{application_id}/tokens [post]
|
||||
func (u *ApplicationController) SaveToken(c *gin.Context) {
|
||||
user := u.authService.GetUser(c)
|
||||
|
||||
var applicationRequest = &schema.ApplicationId{}
|
||||
if err := c.ShouldBindUri(applicationRequest); err != nil {
|
||||
response.Ctx(c).Error(err).Status(http.StatusBadRequest).Send()
|
||||
return
|
||||
}
|
||||
|
||||
applicationEntity, err := u.applicationService.GetApplicationById(c, applicationRequest.ApplicationId)
|
||||
if err != nil {
|
||||
response.Ctx(c).Error(err).Send()
|
||||
return
|
||||
}
|
||||
|
||||
if applicationEntity.UserId != user.ID {
|
||||
response.Ctx(c).Status(http.StatusForbidden).Send()
|
||||
return
|
||||
}
|
||||
|
||||
applicationToken, err := u.applicationService.CreateToken(c, applicationEntity)
|
||||
if err != nil {
|
||||
response.Ctx(c).Error(err).Send()
|
||||
return
|
||||
}
|
||||
|
||||
response.Ctx(c).Status(http.StatusOK).Data(applicationToken).Send()
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/auth"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type UserController struct {
|
||||
authService *auth.Service
|
||||
}
|
||||
|
||||
func NewUserController(authService *auth.Service) *UserController {
|
||||
return &UserController{authService}
|
||||
}
|
||||
|
||||
// Test godoc
|
||||
// @Summary Greet
|
||||
// @Description 测试接口,将会返回当前用户的信息
|
||||
// @Tags ping
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @deprecated true
|
||||
// @Success 200 {object} schema.ResponseBody{data=schema.CurrentUserResponse}
|
||||
// @Failure 400 {object} schema.ResponseBody
|
||||
// @Router /api/v1/ping [get]
|
||||
func (u *UserController) Test(c *gin.Context) {
|
||||
user := u.authService.GetUser(c)
|
||||
|
||||
var currentUserResponse = &schema.CurrentUserResponse{
|
||||
IP: c.ClientIP(),
|
||||
Valid: user.Valid,
|
||||
UserEmail: user.Token.Email,
|
||||
UserId: user.Token.Sub,
|
||||
UserName: user.Token.Name,
|
||||
}
|
||||
|
||||
schema.NewResponse(c).Status(http.StatusOK).Data(currentUserResponse).Send()
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"leafdev.top/Ecosystem/recommender/internal/handler/http/response"
|
||||
"leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/auth"
|
||||
"leafdev.top/Ecosystem/recommender/pkg/consts"
|
||||
@ -24,7 +25,7 @@ func (a AuthMiddleware) RequireJWTIDToken(c *gin.Context) {
|
||||
|
||||
if err != nil {
|
||||
c.Abort()
|
||||
schema.NewResponse(c).Error(err).Status(http.StatusUnauthorized).Send()
|
||||
response.Ctx(c).Error(err).Status(http.StatusUnauthorized).Send()
|
||||
return
|
||||
}
|
||||
|
||||
@ -36,7 +37,7 @@ func (a AuthMiddleware) RequireJWTAccessToken(c *gin.Context) {
|
||||
user, err := a.authService.GinMiddlewareAuth(schema.JWTAccessToken, c)
|
||||
if err != nil {
|
||||
c.Abort()
|
||||
schema.NewResponse(c).Error(err).Status(http.StatusUnauthorized).Send()
|
||||
response.Ctx(c).Error(err).Status(http.StatusUnauthorized).Send()
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ var ProviderSet = wire.NewSet(
|
||||
middleware.NewGinLoggerMiddleware,
|
||||
middleware.NewJSONResponseMiddleware,
|
||||
NewMiddleware,
|
||||
v1.NewUserController,
|
||||
v1.NewApplicationController,
|
||||
NewHandler,
|
||||
)
|
||||
|
||||
@ -34,13 +34,13 @@ func NewMiddleware(
|
||||
}
|
||||
|
||||
type Handlers struct {
|
||||
User *v1.UserController
|
||||
Application *v1.ApplicationController
|
||||
}
|
||||
|
||||
func NewHandler(
|
||||
user *v1.UserController,
|
||||
application *v1.ApplicationController,
|
||||
) *Handlers {
|
||||
return &Handlers{
|
||||
User: user,
|
||||
Application: application,
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,23 @@
|
||||
package schema
|
||||
package response
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ResponseBody struct {
|
||||
Message string `json:"message"`
|
||||
Error string `json:"error"`
|
||||
Success bool `json:"success"`
|
||||
Data any `json:"data,omitempty"`
|
||||
Wrap bool `json:"-"`
|
||||
}
|
||||
|
||||
type HttpResponse struct {
|
||||
body *ResponseBody
|
||||
body *schema.ResponseBody
|
||||
httpStatus int
|
||||
ctx *gin.Context
|
||||
}
|
||||
|
||||
func NewResponse(c *gin.Context) *HttpResponse {
|
||||
func NewResponse() *HttpResponse {
|
||||
return &HttpResponse{
|
||||
body: &ResponseBody{
|
||||
body: &schema.ResponseBody{
|
||||
Wrap: true,
|
||||
},
|
||||
httpStatus: 0,
|
||||
ctx: c,
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,6 +80,7 @@ func (r *HttpResponse) Status(status int) *HttpResponse {
|
||||
}
|
||||
|
||||
func (r *HttpResponse) Send() {
|
||||
|
||||
if r.httpStatus == 0 {
|
||||
r.httpStatus = http.StatusOK
|
||||
}
|
||||
@ -129,3 +122,13 @@ func (r *HttpResponse) Abort() {
|
||||
// })
|
||||
// c.Abort()
|
||||
//}
|
||||
|
||||
func Ctx(c *gin.Context) *HttpResponse {
|
||||
return &HttpResponse{
|
||||
body: &schema.ResponseBody{
|
||||
Wrap: true,
|
||||
},
|
||||
ctx: c,
|
||||
httpStatus: 0,
|
||||
}
|
||||
}
|
@ -1,15 +1,122 @@
|
||||
-- +goose Up
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(255) NOT NULL,
|
||||
`email` varchar(255) NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
CREATE TABLE `applications`
|
||||
(
|
||||
id serial NOT NULL,
|
||||
name varchar(255) NOT NULL,
|
||||
user_id varchar(255) NOT NULL,
|
||||
created_at timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
primary key (id),
|
||||
index (user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE `application_tokens`
|
||||
(
|
||||
id serial NOT NULL,
|
||||
token varchar(255) NOT NULL,
|
||||
application_id bigint unsigned NOT NULL,
|
||||
created_at timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
primary key (id),
|
||||
index (token),
|
||||
foreign key (application_id) references applications (id) on delete cascade
|
||||
);
|
||||
|
||||
CREATE TABLE `categories`
|
||||
(
|
||||
id serial NOT NULL,
|
||||
name varchar(255) NOT NULL,
|
||||
application_id bigint unsigned NOT NULL,
|
||||
primary key (id),
|
||||
foreign key (application_id) references applications (id) on delete cascade
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE `tags`
|
||||
(
|
||||
id serial NOT NULL,
|
||||
name varchar(255) NOT NULL,
|
||||
application_id bigint unsigned NOT NULL,
|
||||
primary key (id),
|
||||
foreign key (application_id) references applications (id) on delete cascade
|
||||
);
|
||||
|
||||
CREATE TABLE `tag_mapping`
|
||||
(
|
||||
id serial NOT NULL,
|
||||
tag_id bigint unsigned NOT NULL,
|
||||
name varchar(255) NOT NULL,
|
||||
application_id bigint unsigned NOT NULL,
|
||||
primary key (id),
|
||||
foreign key (tag_id) references tags (id)
|
||||
on delete cascade,
|
||||
foreign key (application_id) references applications (id) on delete cascade,
|
||||
index (tag_id, name, application_id)
|
||||
);
|
||||
|
||||
CREATE TABLE `posts`
|
||||
(
|
||||
id serial NOT NULL,
|
||||
target_id VARCHAR(255) NOT NULL,
|
||||
title varchar(255) NOT NULL,
|
||||
content LONGTEXT NOT NULL,
|
||||
application_id bigint unsigned NOT NULL,
|
||||
processed BOOLEAN DEFAULT FALSE,
|
||||
created_at timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
index (target_id, processed, application_id),
|
||||
primary key (id),
|
||||
foreign key (application_id) references applications (id) on delete cascade
|
||||
);
|
||||
|
||||
CREATE TABLE `post_tags`
|
||||
(
|
||||
id serial NOT NULL,
|
||||
post_id bigint unsigned NOT NULL,
|
||||
tag_id bigint unsigned NOT NULL,
|
||||
primary key (id),
|
||||
foreign key (post_id) references posts (id)
|
||||
on delete cascade,
|
||||
foreign key (tag_id) references tags (id)
|
||||
on delete cascade,
|
||||
index (post_id, tag_id)
|
||||
);
|
||||
|
||||
-- user tag scores
|
||||
CREATE TABLE `user_tag_scores`
|
||||
(
|
||||
user_id varchar(255) NOT NULL,
|
||||
tag_id bigint unsigned NOT NULL,
|
||||
score int NOT NULL,
|
||||
application_id bigint unsigned NOT NULL,
|
||||
primary key (user_id, tag_id),
|
||||
index (score, application_id),
|
||||
foreign key (tag_id) references tags (id) on delete cascade,
|
||||
foreign key (application_id) references applications (id) on delete cascade
|
||||
);
|
||||
|
||||
-- user likes
|
||||
CREATE TABLE `user_likes`
|
||||
(
|
||||
user_id varchar(255) NOT NULL,
|
||||
post_id bigint unsigned NOT NULL,
|
||||
type enum ('like', 'dislike') NOT NULL,
|
||||
application_id bigint unsigned NOT NULL,
|
||||
primary key (user_id, post_id),
|
||||
index (type, application_id),
|
||||
foreign key (post_id) references posts (id) on delete cascade,
|
||||
foreign key (application_id) references applications (id) on delete cascade
|
||||
);
|
||||
|
||||
|
||||
-- +goose Down
|
||||
|
||||
DROP TABLE `users`;
|
||||
DROP TABLE IF EXISTS `tag_mapping`;
|
||||
DROP TABLE IF EXISTS `user_tag_scores`;
|
||||
DROP TABLE IF EXISTS `post_tags`;
|
||||
DROP TABLE IF EXISTS `user_likes`;
|
||||
DROP TABLE IF EXISTS `posts`;
|
||||
DROP TABLE IF EXISTS `tags`;
|
||||
DROP TABLE IF EXISTS `categories`;
|
||||
DROP TABLE IF EXISTS `application_tokens`;
|
||||
DROP TABLE IF EXISTS `applications`;
|
||||
|
@ -11,26 +11,23 @@ import (
|
||||
//}
|
||||
|
||||
type Api struct {
|
||||
HttpHandler *http.Handlers
|
||||
h *http.Handlers
|
||||
}
|
||||
|
||||
func NewApiRoute(
|
||||
//User *v1.UserController,
|
||||
HttpHandler *http.Handlers,
|
||||
h *http.Handlers,
|
||||
) *Api {
|
||||
//return &Api{
|
||||
// User,
|
||||
//}
|
||||
|
||||
return &Api{
|
||||
HttpHandler,
|
||||
h,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Api) InitApiRouter(r *gin.RouterGroup) {
|
||||
//r.GET("/ping", a.User.Test)
|
||||
r.GET("/applications", a.h.Application.List)
|
||||
r.POST("/applications", a.h.Application.Save)
|
||||
r.GET("/application/:application_id/tokens", a.h.Application.ListToken)
|
||||
r.POST("/application/:application_id/tokens", a.h.Application.SaveToken)
|
||||
|
||||
r.GET("/ping", a.HttpHandler.User.Test)
|
||||
}
|
||||
|
||||
func (a *Api) InitNoAuthApiRouter(r *gin.RouterGroup) {
|
||||
|
9
internal/schema/applications.go
Normal file
9
internal/schema/applications.go
Normal file
@ -0,0 +1,9 @@
|
||||
package schema
|
||||
|
||||
type ApplicationId struct {
|
||||
ApplicationId EntityId `json:"application_id" uri:"application_id"`
|
||||
}
|
||||
|
||||
type ApplicationCreateRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
9
internal/schema/http.go
Normal file
9
internal/schema/http.go
Normal file
@ -0,0 +1,9 @@
|
||||
package schema
|
||||
|
||||
type ResponseBody struct {
|
||||
Message string `json:"message"`
|
||||
Error string `json:"error"`
|
||||
Success bool `json:"success"`
|
||||
Data any `json:"data,omitempty"`
|
||||
Wrap bool `json:"-"`
|
||||
}
|
@ -25,6 +25,7 @@ type UserTokenInfo struct {
|
||||
|
||||
type User struct {
|
||||
Token UserTokenInfo
|
||||
ID UserId
|
||||
Valid bool
|
||||
}
|
||||
|
||||
|
8
internal/schema/user_likes.go
Normal file
8
internal/schema/user_likes.go
Normal file
@ -0,0 +1,8 @@
|
||||
package schema
|
||||
|
||||
type UserLikeType string
|
||||
|
||||
const (
|
||||
UserLikeTypeLike UserLikeType = "like"
|
||||
UserLikeTypeDislike UserLikeType = "dislike"
|
||||
)
|
45
internal/service/application/applications.go
Normal file
45
internal/service/application/applications.go
Normal file
@ -0,0 +1,45 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
"leafdev.top/Ecosystem/recommender/internal/schema"
|
||||
)
|
||||
|
||||
func (s *Service) CreateApplication(ctx context.Context, name string, userId schema.UserId) (*entity.Application, error) {
|
||||
application := &entity.Application{
|
||||
Name: name,
|
||||
UserId: userId,
|
||||
}
|
||||
|
||||
err := s.dao.Application.WithContext(ctx).Create(application)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return application, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetApplicationById(ctx context.Context, id schema.EntityId) (*entity.Application, error) {
|
||||
return s.dao.Application.WithContext(ctx).Where(s.dao.Application.Id.Eq(id.Uint())).First()
|
||||
}
|
||||
|
||||
// ListApplications 列出所有应用
|
||||
func (s *Service) ListApplications(ctx context.Context, userId *schema.UserId) ([]*entity.Application, error) {
|
||||
var q = s.dao.WithContext(ctx).Application
|
||||
|
||||
if userId != nil {
|
||||
return q.Where(s.dao.Application.UserId.Eq(userId.String())).Find()
|
||||
}
|
||||
|
||||
return q.Find()
|
||||
}
|
||||
|
||||
// DeleteApplication 删除应用
|
||||
func (s *Service) DeleteApplication(ctx context.Context, id schema.EntityId) error {
|
||||
// TODO: 删除之前,需要删除关联的部分
|
||||
|
||||
_, err := s.dao.WithContext(ctx).Application.Where(s.dao.Application.Id.Eq(id.Uint())).Delete()
|
||||
|
||||
return err
|
||||
}
|
11
internal/service/application/provider.go
Normal file
11
internal/service/application/provider.go
Normal file
@ -0,0 +1,11 @@
|
||||
package application
|
||||
|
||||
import "leafdev.top/Ecosystem/recommender/internal/dao"
|
||||
|
||||
type Service struct {
|
||||
dao *dao.Query
|
||||
}
|
||||
|
||||
func NewService(dao *dao.Query) *Service {
|
||||
return &Service{dao: dao}
|
||||
}
|
24
internal/service/application/tokens.go
Normal file
24
internal/service/application/tokens.go
Normal file
@ -0,0 +1,24 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/iVampireSP/pkg/random"
|
||||
"leafdev.top/Ecosystem/recommender/internal/entity"
|
||||
)
|
||||
|
||||
func (s *Service) ListToken(ctx context.Context, application *entity.Application) ([]*entity.ApplicationToken, error) {
|
||||
return s.dao.ApplicationToken.WithContext(ctx).Where(s.dao.ApplicationToken.ApplicationId.Eq(application.Id.Uint())).Find()
|
||||
}
|
||||
|
||||
func (s *Service) CreateToken(ctx context.Context, application *entity.Application) (*entity.ApplicationToken, error) {
|
||||
var token = random.String(32)
|
||||
|
||||
var at = &entity.ApplicationToken{
|
||||
ApplicationId: application.Id,
|
||||
Token: token,
|
||||
}
|
||||
|
||||
err := s.dao.ApplicationToken.WithContext(ctx).Create(at)
|
||||
|
||||
return at, err
|
||||
}
|
@ -76,7 +76,10 @@ func (a *Service) GetUserId(ctx context.Context) schema.UserId {
|
||||
func (a *Service) GetUser(ctx context.Context) *schema.User {
|
||||
user := ctx.Value(consts.AuthMiddlewareKey)
|
||||
|
||||
return user.(*schema.User)
|
||||
user2 := user.(*schema.User)
|
||||
user2.ID = user2.Token.Sub
|
||||
|
||||
return user2
|
||||
}
|
||||
|
||||
func (a *Service) SetUser(ctx context.Context, user *schema.User) context.Context {
|
||||
|
@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"leafdev.top/Ecosystem/recommender/internal/base/logger"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/application"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/auth"
|
||||
"leafdev.top/Ecosystem/recommender/internal/service/jwks"
|
||||
|
||||
@ -9,14 +10,16 @@ import (
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
logger *logger.Logger
|
||||
Jwks *jwks.JWKS
|
||||
Auth *auth.Service
|
||||
logger *logger.Logger
|
||||
Jwks *jwks.JWKS
|
||||
Auth *auth.Service
|
||||
Application *application.Service
|
||||
}
|
||||
|
||||
var Provider = wire.NewSet(
|
||||
jwks.NewJWKS,
|
||||
auth.NewAuthService,
|
||||
application.NewService,
|
||||
NewService,
|
||||
)
|
||||
|
||||
@ -24,11 +27,12 @@ func NewService(
|
||||
logger *logger.Logger,
|
||||
jwks *jwks.JWKS,
|
||||
auth *auth.Service,
|
||||
|
||||
application *application.Service,
|
||||
) *Service {
|
||||
return &Service{
|
||||
logger,
|
||||
jwks,
|
||||
auth,
|
||||
application,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user