add: some user api and all api desc
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package email
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/email/api/internal/logic/email"
|
||||||
|
"juwan-backend/app/email/api/internal/svc"
|
||||||
|
"juwan-backend/app/email/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 忘记密码-发送验证码
|
||||||
|
func ForgotPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.ForgotPasswordReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := email.NewForgotPasswordLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ForgotPassword(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
},
|
},
|
||||||
}...,
|
}...,
|
||||||
),
|
),
|
||||||
rest.WithPrefix("/api/email"),
|
rest.WithPrefix("/api/v1/email"),
|
||||||
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 忘记密码-发送验证码
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/forgot-password/send",
|
||||||
|
Handler: email.ForgotPasswordHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rest.WithPrefix("/api/v1/auth"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/email/api/internal/logic/user"
|
||||||
|
"juwan-backend/app/email/api/internal/svc"
|
||||||
|
"juwan-backend/app/email/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 忘记密码-发送验证码
|
||||||
|
func ForgotPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.ForgotPasswordReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := user.NewForgotPasswordLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ForgotPassword(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package email
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/email/api/internal/svc"
|
||||||
|
"juwan-backend/app/email/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ForgotPasswordLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 忘记密码-发送验证码
|
||||||
|
func NewForgotPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForgotPasswordLogic {
|
||||||
|
return &ForgotPasswordLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ForgotPasswordLogic) ForgotPassword(req *types.ForgotPasswordReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/email/api/internal/svc"
|
||||||
|
"juwan-backend/app/email/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ForgotPasswordLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 忘记密码-发送验证码
|
||||||
|
func NewForgotPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForgotPasswordLogic {
|
||||||
|
return &ForgotPasswordLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ForgotPasswordLogic) ForgotPassword(req *types.ForgotPasswordReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -3,6 +3,13 @@
|
|||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
|
type EmptyResp struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type ForgotPasswordReq struct {
|
||||||
|
Email string `json:"email"`
|
||||||
|
}
|
||||||
|
|
||||||
type SendVerificationCodeReq struct {
|
type SendVerificationCodeReq struct {
|
||||||
Email string `json:"email" binding:"required,email"`
|
Email string `json:"email" binding:"required,email"`
|
||||||
Scene string `json:"scene" binding:"required,oneof=register login reset_password bind_email"`
|
Scene string `json:"scene" binding:"required,oneof=register login reset_password bind_email"`
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Name: file-api
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 8888
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"juwan-backend/app/objectstory/api/internal/config"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/handler"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/file-api.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
server.Start()
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import "github.com/zeromicro/go-zero/rest"
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rest.RestConf
|
||||||
|
Logger struct {
|
||||||
|
AccessSecret string
|
||||||
|
AccessExpire int64
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/logic/file"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 文件获取接口 (如果是私有文件,通过此接口获取或重定向)
|
||||||
|
func GetFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetFileReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := file.NewGetFileLogic(r.Context(), svcCtx)
|
||||||
|
err := l.GetFile(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.Ok(w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/logic/file"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 文件上传接口
|
||||||
|
func UploadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.UploadReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := file.NewUploadLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.Upload(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
file "juwan-backend/app/objectstory/api/internal/handler/file"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
|
server.AddRoutes(
|
||||||
|
rest.WithMiddlewares(
|
||||||
|
[]rest.Middleware{serverCtx.FileSizeLimit},
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 文件获取接口 (如果是私有文件,通过此接口获取或重定向)
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/files/:fileId",
|
||||||
|
Handler: file.GetFileHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 文件上传接口
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/upload",
|
||||||
|
Handler: file.UploadHandler(serverCtx),
|
||||||
|
},
|
||||||
|
}...,
|
||||||
|
),
|
||||||
|
rest.WithJwt(serverCtx.Config.Logger.AccessSecret),
|
||||||
|
rest.WithPrefix("/api/v1"),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetFileLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件获取接口 (如果是私有文件,通过此接口获取或重定向)
|
||||||
|
func NewGetFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileLogic {
|
||||||
|
return &GetFileLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetFileLogic) GetFile(req *types.GetFileReq) error {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/objectstory/api/internal/svc"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UploadLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件上传接口
|
||||||
|
func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogic {
|
||||||
|
return &UploadLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UploadLogic) Upload(req *types.UploadReq) (resp *types.UploadResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package middleware
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
type FileSizeLimitMiddleware struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFileSizeLimitMiddleware() *FileSizeLimitMiddleware {
|
||||||
|
return &FileSizeLimitMiddleware{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *FileSizeLimitMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// TODO generate middleware implement function, delete after code implementation
|
||||||
|
|
||||||
|
// Passthrough to next handler if need
|
||||||
|
next(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/config"
|
||||||
|
"juwan-backend/app/objectstory/api/internal/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
FileSizeLimit rest.Middleware
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
FileSizeLimit: middleware.NewFileSizeLimitMiddleware().Handle,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
type GetFileReq struct {
|
||||||
|
FileId string `path:"fileId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UploadReq struct {
|
||||||
|
Type string `form:"type,options=avatar|chat|post|verification|dispute"` // 文件类型限制
|
||||||
|
}
|
||||||
|
|
||||||
|
type UploadResp struct {
|
||||||
|
Url string `json:"url"` // 返回 CDN 地址或访问地址
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Name: file.rpc
|
||||||
|
ListenOn: 0.0.0.0:8080
|
||||||
|
Etcd:
|
||||||
|
Hosts:
|
||||||
|
- 127.0.0.1:2379
|
||||||
|
Key: file.rpc
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/config"
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/server"
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/objectstory/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/core/service"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/reflection"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/file.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|
||||||
|
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||||
|
pb.RegisterFileServiceServer(grpcServer, server.NewFileServiceServer(ctx))
|
||||||
|
|
||||||
|
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||||
|
reflection.Register(grpcServer)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
||||||
|
s.Start()
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
// Source: objectstory.proto
|
||||||
|
|
||||||
|
package fileservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/objectstory/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
GetFileUrlReq = pb.GetFileUrlReq
|
||||||
|
GetFileUrlResp = pb.GetFileUrlResp
|
||||||
|
UploadFileMetadataReq = pb.UploadFileMetadataReq
|
||||||
|
UploadFileResp = pb.UploadFileResp
|
||||||
|
|
||||||
|
FileService interface {
|
||||||
|
// 简单上传(适合小文件,或保存元数据)
|
||||||
|
Upload(ctx context.Context, in *UploadFileMetadataReq, opts ...grpc.CallOption) (*UploadFileResp, error)
|
||||||
|
// 获取文件访问链接(处理私有文件的鉴权)
|
||||||
|
GetFileUrl(ctx context.Context, in *GetFileUrlReq, opts ...grpc.CallOption) (*GetFileUrlResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultFileService struct {
|
||||||
|
cli zrpc.Client
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewFileService(cli zrpc.Client) FileService {
|
||||||
|
return &defaultFileService{
|
||||||
|
cli: cli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 简单上传(适合小文件,或保存元数据)
|
||||||
|
func (m *defaultFileService) Upload(ctx context.Context, in *UploadFileMetadataReq, opts ...grpc.CallOption) (*UploadFileResp, error) {
|
||||||
|
client := pb.NewFileServiceClient(m.cli.Conn())
|
||||||
|
return client.Upload(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取文件访问链接(处理私有文件的鉴权)
|
||||||
|
func (m *defaultFileService) GetFileUrl(ctx context.Context, in *GetFileUrlReq, opts ...grpc.CallOption) (*GetFileUrlResp, error) {
|
||||||
|
client := pb.NewFileServiceClient(m.cli.Conn())
|
||||||
|
return client.GetFileUrl(ctx, in, opts...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import "github.com/zeromicro/go-zero/zrpc"
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
zrpc.RpcServerConf
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/objectstory/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetFileUrlLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetFileUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileUrlLogic {
|
||||||
|
return &GetFileUrlLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取文件访问链接(处理私有文件的鉴权)
|
||||||
|
func (l *GetFileUrlLogic) GetFileUrl(in *pb.GetFileUrlReq) (*pb.GetFileUrlResp, error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return &pb.GetFileUrlResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/objectstory/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UploadLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogic {
|
||||||
|
return &UploadLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 简单上传(适合小文件,或保存元数据)
|
||||||
|
func (l *UploadLogic) Upload(in *pb.UploadFileMetadataReq) (*pb.UploadFileResp, error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return &pb.UploadFileResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.9.2
|
||||||
|
// Source: objectstory.proto
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/logic"
|
||||||
|
"juwan-backend/app/objectstory/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/objectstory/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FileServiceServer struct {
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
pb.UnimplementedFileServiceServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFileServiceServer(svcCtx *svc.ServiceContext) *FileServiceServer {
|
||||||
|
return &FileServiceServer{
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 简单上传(适合小文件,或保存元数据)
|
||||||
|
func (s *FileServiceServer) Upload(ctx context.Context, in *pb.UploadFileMetadataReq) (*pb.UploadFileResp, error) {
|
||||||
|
l := logic.NewUploadLogic(ctx, s.svcCtx)
|
||||||
|
return l.Upload(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取文件访问链接(处理私有文件的鉴权)
|
||||||
|
func (s *FileServiceServer) GetFileUrl(ctx context.Context, in *pb.GetFileUrlReq) (*pb.GetFileUrlResp, error) {
|
||||||
|
l := logic.NewGetFileUrlLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetFileUrl(in)
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package svc
|
||||||
|
|
||||||
|
import "juwan-backend/app/objectstory/rpc/internal/config"
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,326 @@
|
|||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// protoc-gen-go v1.36.11
|
||||||
|
// protoc v5.29.6
|
||||||
|
// source: objectstory.proto
|
||||||
|
|
||||||
|
package pb
|
||||||
|
|
||||||
|
import (
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
reflect "reflect"
|
||||||
|
sync "sync"
|
||||||
|
unsafe "unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Verify that this generated code is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||||
|
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||||
|
)
|
||||||
|
|
||||||
|
// 文件上传的元数据信息
|
||||||
|
type UploadFileMetadataReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
FileName string `protobuf:"bytes,1,opt,name=fileName,proto3" json:"fileName,omitempty"`
|
||||||
|
FileSize int64 `protobuf:"varint,2,opt,name=fileSize,proto3" json:"fileSize,omitempty"`
|
||||||
|
FileType string `protobuf:"bytes,3,opt,name=fileType,proto3" json:"fileType,omitempty"` // avatar, chat, etc.
|
||||||
|
UserId string `protobuf:"bytes,4,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||||
|
FileData []byte `protobuf:"bytes,5,opt,name=fileData,proto3" json:"fileData,omitempty"` // 如果文件很小可以直接传,大文件建议API层直接传S3,RPC只传元数据
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileMetadataReq) Reset() {
|
||||||
|
*x = UploadFileMetadataReq{}
|
||||||
|
mi := &file_objectstory_proto_msgTypes[0]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileMetadataReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UploadFileMetadataReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UploadFileMetadataReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_objectstory_proto_msgTypes[0]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UploadFileMetadataReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UploadFileMetadataReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_objectstory_proto_rawDescGZIP(), []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileMetadataReq) GetFileName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.FileName
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileMetadataReq) GetFileSize() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.FileSize
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileMetadataReq) GetFileType() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.FileType
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileMetadataReq) GetUserId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.UserId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileMetadataReq) GetFileData() []byte {
|
||||||
|
if x != nil {
|
||||||
|
return x.FileData
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type UploadFileResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"`
|
||||||
|
FileId string `protobuf:"bytes,2,opt,name=fileId,proto3" json:"fileId,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileResp) Reset() {
|
||||||
|
*x = UploadFileResp{}
|
||||||
|
mi := &file_objectstory_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UploadFileResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UploadFileResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_objectstory_proto_msgTypes[1]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UploadFileResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UploadFileResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_objectstory_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileResp) GetUrl() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Url
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UploadFileResp) GetFileId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.FileId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetFileUrlReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
FileId string `protobuf:"bytes,1,opt,name=fileId,proto3" json:"fileId,omitempty"`
|
||||||
|
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` // 用于鉴权
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetFileUrlReq) Reset() {
|
||||||
|
*x = GetFileUrlReq{}
|
||||||
|
mi := &file_objectstory_proto_msgTypes[2]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetFileUrlReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetFileUrlReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetFileUrlReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_objectstory_proto_msgTypes[2]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GetFileUrlReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetFileUrlReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_objectstory_proto_rawDescGZIP(), []int{2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetFileUrlReq) GetFileId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.FileId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetFileUrlReq) GetUserId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.UserId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetFileUrlResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` // 可能是带签名的临时 URL
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetFileUrlResp) Reset() {
|
||||||
|
*x = GetFileUrlResp{}
|
||||||
|
mi := &file_objectstory_proto_msgTypes[3]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetFileUrlResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetFileUrlResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetFileUrlResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_objectstory_proto_msgTypes[3]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GetFileUrlResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetFileUrlResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_objectstory_proto_rawDescGZIP(), []int{3}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetFileUrlResp) GetUrl() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Url
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var File_objectstory_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
|
const file_objectstory_proto_rawDesc = "" +
|
||||||
|
"\n" +
|
||||||
|
"\x11objectstory.proto\x12\x04file\"\x9f\x01\n" +
|
||||||
|
"\x15UploadFileMetadataReq\x12\x1a\n" +
|
||||||
|
"\bfileName\x18\x01 \x01(\tR\bfileName\x12\x1a\n" +
|
||||||
|
"\bfileSize\x18\x02 \x01(\x03R\bfileSize\x12\x1a\n" +
|
||||||
|
"\bfileType\x18\x03 \x01(\tR\bfileType\x12\x16\n" +
|
||||||
|
"\x06userId\x18\x04 \x01(\tR\x06userId\x12\x1a\n" +
|
||||||
|
"\bfileData\x18\x05 \x01(\fR\bfileData\":\n" +
|
||||||
|
"\x0eUploadFileResp\x12\x10\n" +
|
||||||
|
"\x03url\x18\x01 \x01(\tR\x03url\x12\x16\n" +
|
||||||
|
"\x06fileId\x18\x02 \x01(\tR\x06fileId\"?\n" +
|
||||||
|
"\rGetFileUrlReq\x12\x16\n" +
|
||||||
|
"\x06fileId\x18\x01 \x01(\tR\x06fileId\x12\x16\n" +
|
||||||
|
"\x06userId\x18\x02 \x01(\tR\x06userId\"\"\n" +
|
||||||
|
"\x0eGetFileUrlResp\x12\x10\n" +
|
||||||
|
"\x03url\x18\x01 \x01(\tR\x03url2\x83\x01\n" +
|
||||||
|
"\vFileService\x12;\n" +
|
||||||
|
"\x06Upload\x12\x1b.file.UploadFileMetadataReq\x1a\x14.file.UploadFileResp\x127\n" +
|
||||||
|
"\n" +
|
||||||
|
"GetFileUrl\x12\x13.file.GetFileUrlReq\x1a\x14.file.GetFileUrlRespB\x06Z\x04./pbb\x06proto3"
|
||||||
|
|
||||||
|
var (
|
||||||
|
file_objectstory_proto_rawDescOnce sync.Once
|
||||||
|
file_objectstory_proto_rawDescData []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
func file_objectstory_proto_rawDescGZIP() []byte {
|
||||||
|
file_objectstory_proto_rawDescOnce.Do(func() {
|
||||||
|
file_objectstory_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_objectstory_proto_rawDesc), len(file_objectstory_proto_rawDesc)))
|
||||||
|
})
|
||||||
|
return file_objectstory_proto_rawDescData
|
||||||
|
}
|
||||||
|
|
||||||
|
var file_objectstory_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||||
|
var file_objectstory_proto_goTypes = []any{
|
||||||
|
(*UploadFileMetadataReq)(nil), // 0: file.UploadFileMetadataReq
|
||||||
|
(*UploadFileResp)(nil), // 1: file.UploadFileResp
|
||||||
|
(*GetFileUrlReq)(nil), // 2: file.GetFileUrlReq
|
||||||
|
(*GetFileUrlResp)(nil), // 3: file.GetFileUrlResp
|
||||||
|
}
|
||||||
|
var file_objectstory_proto_depIdxs = []int32{
|
||||||
|
0, // 0: file.FileService.Upload:input_type -> file.UploadFileMetadataReq
|
||||||
|
2, // 1: file.FileService.GetFileUrl:input_type -> file.GetFileUrlReq
|
||||||
|
1, // 2: file.FileService.Upload:output_type -> file.UploadFileResp
|
||||||
|
3, // 3: file.FileService.GetFileUrl:output_type -> file.GetFileUrlResp
|
||||||
|
2, // [2:4] is the sub-list for method output_type
|
||||||
|
0, // [0:2] is the sub-list for method input_type
|
||||||
|
0, // [0:0] is the sub-list for extension type_name
|
||||||
|
0, // [0:0] is the sub-list for extension extendee
|
||||||
|
0, // [0:0] is the sub-list for field type_name
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { file_objectstory_proto_init() }
|
||||||
|
func file_objectstory_proto_init() {
|
||||||
|
if File_objectstory_proto != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
type x struct{}
|
||||||
|
out := protoimpl.TypeBuilder{
|
||||||
|
File: protoimpl.DescBuilder{
|
||||||
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_objectstory_proto_rawDesc), len(file_objectstory_proto_rawDesc)),
|
||||||
|
NumEnums: 0,
|
||||||
|
NumMessages: 4,
|
||||||
|
NumExtensions: 0,
|
||||||
|
NumServices: 1,
|
||||||
|
},
|
||||||
|
GoTypes: file_objectstory_proto_goTypes,
|
||||||
|
DependencyIndexes: file_objectstory_proto_depIdxs,
|
||||||
|
MessageInfos: file_objectstory_proto_msgTypes,
|
||||||
|
}.Build()
|
||||||
|
File_objectstory_proto = out.File
|
||||||
|
file_objectstory_proto_goTypes = nil
|
||||||
|
file_objectstory_proto_depIdxs = nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.6.1
|
||||||
|
// - protoc v5.29.6
|
||||||
|
// source: objectstory.proto
|
||||||
|
|
||||||
|
package pb
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
// Requires gRPC-Go v1.64.0 or later.
|
||||||
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
|
const (
|
||||||
|
FileService_Upload_FullMethodName = "/file.FileService/Upload"
|
||||||
|
FileService_GetFileUrl_FullMethodName = "/file.FileService/GetFileUrl"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileServiceClient is the client API for FileService service.
|
||||||
|
//
|
||||||
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
|
type FileServiceClient interface {
|
||||||
|
// 简单上传(适合小文件,或保存元数据)
|
||||||
|
Upload(ctx context.Context, in *UploadFileMetadataReq, opts ...grpc.CallOption) (*UploadFileResp, error)
|
||||||
|
// 获取文件访问链接(处理私有文件的鉴权)
|
||||||
|
GetFileUrl(ctx context.Context, in *GetFileUrlReq, opts ...grpc.CallOption) (*GetFileUrlResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type fileServiceClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFileServiceClient(cc grpc.ClientConnInterface) FileServiceClient {
|
||||||
|
return &fileServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *fileServiceClient) Upload(ctx context.Context, in *UploadFileMetadataReq, opts ...grpc.CallOption) (*UploadFileResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(UploadFileResp)
|
||||||
|
err := c.cc.Invoke(ctx, FileService_Upload_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *fileServiceClient) GetFileUrl(ctx context.Context, in *GetFileUrlReq, opts ...grpc.CallOption) (*GetFileUrlResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetFileUrlResp)
|
||||||
|
err := c.cc.Invoke(ctx, FileService_GetFileUrl_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FileServiceServer is the server API for FileService service.
|
||||||
|
// All implementations must embed UnimplementedFileServiceServer
|
||||||
|
// for forward compatibility.
|
||||||
|
type FileServiceServer interface {
|
||||||
|
// 简单上传(适合小文件,或保存元数据)
|
||||||
|
Upload(context.Context, *UploadFileMetadataReq) (*UploadFileResp, error)
|
||||||
|
// 获取文件访问链接(处理私有文件的鉴权)
|
||||||
|
GetFileUrl(context.Context, *GetFileUrlReq) (*GetFileUrlResp, error)
|
||||||
|
mustEmbedUnimplementedFileServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedFileServiceServer must be embedded to have
|
||||||
|
// forward compatible implementations.
|
||||||
|
//
|
||||||
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||||
|
// pointer dereference when methods are called.
|
||||||
|
type UnimplementedFileServiceServer struct{}
|
||||||
|
|
||||||
|
func (UnimplementedFileServiceServer) Upload(context.Context, *UploadFileMetadataReq) (*UploadFileResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method Upload not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedFileServiceServer) GetFileUrl(context.Context, *GetFileUrlReq) (*GetFileUrlResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method GetFileUrl not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedFileServiceServer) mustEmbedUnimplementedFileServiceServer() {}
|
||||||
|
func (UnimplementedFileServiceServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
|
// UnsafeFileServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to FileServiceServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeFileServiceServer interface {
|
||||||
|
mustEmbedUnimplementedFileServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterFileServiceServer(s grpc.ServiceRegistrar, srv FileServiceServer) {
|
||||||
|
// If the following call panics, it indicates UnimplementedFileServiceServer was
|
||||||
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||||
|
t.testEmbeddedByValue()
|
||||||
|
}
|
||||||
|
s.RegisterService(&FileService_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _FileService_Upload_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(UploadFileMetadataReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(FileServiceServer).Upload(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: FileService_Upload_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(FileServiceServer).Upload(ctx, req.(*UploadFileMetadataReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _FileService_GetFileUrl_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetFileUrlReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(FileServiceServer).GetFileUrl(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: FileService_GetFileUrl_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(FileServiceServer).GetFileUrl(ctx, req.(*GetFileUrlReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FileService_ServiceDesc is the grpc.ServiceDesc for FileService service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var FileService_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "file.FileService",
|
||||||
|
HandlerType: (*FileServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "Upload",
|
||||||
|
Handler: _FileService_Upload_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetFileUrl",
|
||||||
|
Handler: _FileService_GetFileUrl_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "objectstory.proto",
|
||||||
|
}
|
||||||
@@ -3,8 +3,12 @@ ListenOn: 0.0.0.0:8080
|
|||||||
|
|
||||||
DataSource: "${DB_URI}?sslmode=disable"
|
DataSource: "${DB_URI}?sslmode=disable"
|
||||||
|
|
||||||
|
UserVeriRpcConf :
|
||||||
|
Target: k8s://juwan/user_verifications-rpc-svc.juwan:8080
|
||||||
|
|
||||||
SnowflakeRpcConf:
|
SnowflakeRpcConf:
|
||||||
Target: k8s://juwan/snowflake-svc:8080
|
Target: k8s://juwan/snowflake-svc.juwan:8080
|
||||||
|
|
||||||
|
|
||||||
DB:
|
DB:
|
||||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
@@ -20,9 +24,5 @@ CacheConf:
|
|||||||
Pass: "${REDIS_PASSWORD}"
|
Pass: "${REDIS_PASSWORD}"
|
||||||
User: "default"
|
User: "default"
|
||||||
|
|
||||||
Jwt:
|
|
||||||
SecretKey: "${JWT_SECRET_KEY}"
|
|
||||||
Issuer: "juwan-user-rpc"
|
|
||||||
|
|
||||||
Log:
|
Log:
|
||||||
Level: info
|
Level: info
|
||||||
|
|||||||
@@ -1,7 +1,17 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/zrpc"
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
zrpc.RpcServerConf
|
zrpc.RpcServerConf
|
||||||
|
DB struct {
|
||||||
|
Master string
|
||||||
|
Slave string
|
||||||
|
}
|
||||||
|
CacheConf cache.CacheConf
|
||||||
|
UserVeriRpcConf zrpc.RpcClientConf
|
||||||
|
SnowflakeRpcConf zrpc.RpcClientConf
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
|
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||||
"juwan-backend/app/user_verifications/rpc/pb"
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
@@ -25,7 +29,28 @@ func NewAddUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContex
|
|||||||
|
|
||||||
// -----------------------userVerifications-----------------------
|
// -----------------------userVerifications-----------------------
|
||||||
func (l *AddUserVerificationsLogic) AddUserVerifications(in *pb.AddUserVerificationsReq) (*pb.AddUserVerificationsResp, error) {
|
func (l *AddUserVerificationsLogic) AddUserVerifications(in *pb.AddUserVerificationsReq) (*pb.AddUserVerificationsResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
nextIdResp, err := l.svcCtx.SnowflakeRpc.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
materials := schema.MaterialStruct{}
|
||||||
|
err = json.Unmarshal([]byte(in.Materials), &materials)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("Unmarshal %v materials failed: %s", in.Materials, err)
|
||||||
|
return nil, errors.New("bad input materials")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = l.svcCtx.UserVeriModelRW.Create().
|
||||||
|
SetID(nextIdResp.Id).
|
||||||
|
SetUserID(in.UserId).
|
||||||
|
SetRole(in.Role).
|
||||||
|
SetStatus("padding").
|
||||||
|
SetMaterials(materials).
|
||||||
|
Exec(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &pb.AddUserVerificationsResp{}, nil
|
return &pb.AddUserVerificationsResp{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ func NewDelUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContex
|
|||||||
|
|
||||||
func (l *DelUserVerificationsLogic) DelUserVerifications(in *pb.DelUserVerificationsReq) (*pb.DelUserVerificationsResp, error) {
|
func (l *DelUserVerificationsLogic) DelUserVerifications(in *pb.DelUserVerificationsReq) (*pb.DelUserVerificationsResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
|
err := l.svcCtx.UserVeriModelRW.DeleteOneID(in.Id).Exec(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &pb.DelUserVerificationsResp{}, nil
|
return &pb.DelUserVerificationsResp{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||||
"juwan-backend/app/user_verifications/rpc/pb"
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,7 +26,23 @@ func NewGetUserVerificationsByIdLogic(ctx context.Context, svcCtx *svc.ServiceCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetUserVerificationsByIdLogic) GetUserVerificationsById(in *pb.GetUserVerificationsByIdReq) (*pb.GetUserVerificationsByIdResp, error) {
|
func (l *GetUserVerificationsByIdLogic) GetUserVerificationsById(in *pb.GetUserVerificationsByIdReq) (*pb.GetUserVerificationsByIdResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
userVerification, err := l.svcCtx.UserVeriModelRO.Get(l.ctx, in.Id)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("GetUserVerificationsById err: %v", err)
|
||||||
|
return nil, errors.New("get VerificationsById err")
|
||||||
|
}
|
||||||
|
pbVerification := pb.UserVerifications{}
|
||||||
|
err = copier.Copy(&pbVerification, userVerification)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("copier copy err: %v", err)
|
||||||
|
return nil, errors.New("copy Verification err")
|
||||||
|
}
|
||||||
|
createAt := userVerification.CreatedAt.Unix()
|
||||||
|
updateAt := userVerification.UpdatedAt.Unix()
|
||||||
|
pbVerification.CreatedAt = createAt
|
||||||
|
pbVerification.UpdatedAt = updateAt
|
||||||
|
|
||||||
return &pb.GetUserVerificationsByIdResp{}, nil
|
return &pb.GetUserVerificationsByIdResp{
|
||||||
|
UserVerifications: &pbVerification,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||||
"juwan-backend/app/user_verifications/rpc/pb"
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,7 +27,50 @@ func NewSearchUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *SearchUserVerificationsLogic) SearchUserVerifications(in *pb.SearchUserVerificationsReq) (*pb.SearchUserVerificationsResp, error) {
|
func (l *SearchUserVerificationsLogic) SearchUserVerifications(in *pb.SearchUserVerificationsReq) (*pb.SearchUserVerificationsResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
if in.Limit > 1000 {
|
||||||
|
logx.Errorf("Limit exceeds max limit: %d", in.Limit)
|
||||||
return &pb.SearchUserVerificationsResp{}, nil
|
return nil, errors.New("limit exceeds max limit")
|
||||||
|
}
|
||||||
|
verifications, err := l.svcCtx.UserVeriModelRO.Query().Where(userverifications.Or(
|
||||||
|
userverifications.UserIDEQ(in.UserId),
|
||||||
|
userverifications.StatusEQ(in.Status),
|
||||||
|
userverifications.Role(in.Role),
|
||||||
|
)).
|
||||||
|
Offset(int(in.Page * in.Limit)).
|
||||||
|
Limit(int(in.Limit)).
|
||||||
|
All(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("Get all verifications err: %s", err.Error())
|
||||||
|
return nil, errors.New("get all verifications err")
|
||||||
|
}
|
||||||
|
return &pb.SearchUserVerificationsResp{
|
||||||
|
UserVerifications: convertModelUserVerificationsToProto(verifications),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertModelUserVerificationToProto(modelUserVerification *models.UserVerifications) *pb.UserVerifications {
|
||||||
|
|
||||||
|
if modelUserVerification == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := &pb.UserVerifications{}
|
||||||
|
err := copier.Copy(out, modelUserVerification)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("copy modelUserVerification err: %s", err.Error())
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
out.CreatedAt = modelUserVerification.CreatedAt.Unix()
|
||||||
|
out.UpdatedAt = modelUserVerification.UpdatedAt.Unix()
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertModelUserVerificationsToProto(modelUserVerifications []*models.UserVerifications) []*pb.UserVerifications {
|
||||||
|
|
||||||
|
out := make([]*pb.UserVerifications, 0, len(modelUserVerifications))
|
||||||
|
for _, modelUserVerification := range modelUserVerifications {
|
||||||
|
out = append(out, convertModelUserVerificationToProto(modelUserVerification))
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
|
|
||||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||||
"juwan-backend/app/user_verifications/rpc/pb"
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
@@ -24,7 +27,31 @@ func NewUpdateUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *UpdateUserVerificationsLogic) UpdateUserVerifications(in *pb.UpdateUserVerificationsReq) (*pb.UpdateUserVerificationsResp, error) {
|
func (l *UpdateUserVerificationsLogic) UpdateUserVerifications(in *pb.UpdateUserVerificationsReq) (*pb.UpdateUserVerificationsResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
var materials *schema.MaterialStruct
|
||||||
|
materials = nil
|
||||||
|
if in.Materials != nil {
|
||||||
|
err := json.Unmarshal([]byte(*in.Materials), &materials)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("Unmarshal materials failed, err:%v.", err)
|
||||||
|
return nil, errors.New("bad input materials")
|
||||||
|
}
|
||||||
|
if len(materials.GameScreenshots) > 20 {
|
||||||
|
logx.Errorf("User %v upload oo many game screenshots: %d", in.UserId, len(materials.GameScreenshots))
|
||||||
|
return nil, errors.New("too many game screenshots")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := l.svcCtx.UserVeriModelRW.UpdateOneID(in.Id).
|
||||||
|
SetNillableRejectReason(in.RejectReason).
|
||||||
|
SetNillableMaterials(materials).
|
||||||
|
SetNillableRole(in.Role).
|
||||||
|
SetNillableStatus(in.Status).
|
||||||
|
SetReviewedBy(in.ReviewedBy).
|
||||||
|
Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("save user verifications failed, err:%v.", err)
|
||||||
|
return nil, errors.New("save user verifications failed")
|
||||||
|
}
|
||||||
|
|
||||||
return &pb.UpdateUserVerificationsResp{}, nil
|
return &pb.UpdateUserVerificationsResp{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,341 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/migrate"
|
||||||
|
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client is the client that holds all ent builders.
|
||||||
|
type Client struct {
|
||||||
|
config
|
||||||
|
// Schema is the client for creating, migrating and dropping schema.
|
||||||
|
Schema *migrate.Schema
|
||||||
|
// UserVerifications is the client for interacting with the UserVerifications builders.
|
||||||
|
UserVerifications *UserVerificationsClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new client configured with the given options.
|
||||||
|
func NewClient(opts ...Option) *Client {
|
||||||
|
client := &Client{config: newConfig(opts...)}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) init() {
|
||||||
|
c.Schema = migrate.NewSchema(c.driver)
|
||||||
|
c.UserVerifications = NewUserVerificationsClient(c.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// config is the configuration for the client and its builder.
|
||||||
|
config struct {
|
||||||
|
// driver used for executing database requests.
|
||||||
|
driver dialect.Driver
|
||||||
|
// debug enable a debug logging.
|
||||||
|
debug bool
|
||||||
|
// log used for logging on debug mode.
|
||||||
|
log func(...any)
|
||||||
|
// hooks to execute on mutations.
|
||||||
|
hooks *hooks
|
||||||
|
// interceptors to execute on queries.
|
||||||
|
inters *inters
|
||||||
|
}
|
||||||
|
// Option function to configure the client.
|
||||||
|
Option func(*config)
|
||||||
|
)
|
||||||
|
|
||||||
|
// newConfig creates a new config for the client.
|
||||||
|
func newConfig(opts ...Option) config {
|
||||||
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||||
|
cfg.options(opts...)
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
// options applies the options on the config object.
|
||||||
|
func (c *config) options(opts ...Option) {
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
if c.debug {
|
||||||
|
c.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug enables debug logging on the ent.Driver.
|
||||||
|
func Debug() Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.debug = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log sets the logging function for debug mode.
|
||||||
|
func Log(fn func(...any)) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.log = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Driver configures the client driver.
|
||||||
|
func Driver(driver dialect.Driver) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.driver = driver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open opens a database/sql.DB specified by the driver name and
|
||||||
|
// the data source name, and returns a new client attached to it.
|
||||||
|
// Optional parameters can be added for configuring the client.
|
||||||
|
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||||
|
switch driverName {
|
||||||
|
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||||
|
drv, err := sql.Open(driverName, dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewClient(append(options, Driver(drv))...), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||||
|
var ErrTxStarted = errors.New("models: cannot start a transaction within a transaction")
|
||||||
|
|
||||||
|
// Tx returns a new transactional client. The provided context
|
||||||
|
// is used until the transaction is committed or rolled back.
|
||||||
|
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, ErrTxStarted
|
||||||
|
}
|
||||||
|
tx, err := newTx(ctx, c.driver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("models: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = tx
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
UserVerifications: NewUserVerificationsClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeginTx returns a transactional client with specified options.
|
||||||
|
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, errors.New("ent: cannot start a transaction within a transaction")
|
||||||
|
}
|
||||||
|
tx, err := c.driver.(interface {
|
||||||
|
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
|
||||||
|
}).BeginTx(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
UserVerifications: NewUserVerificationsClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||||
|
//
|
||||||
|
// client.Debug().
|
||||||
|
// UserVerifications.
|
||||||
|
// Query().
|
||||||
|
// Count(ctx)
|
||||||
|
func (c *Client) Debug() *Client {
|
||||||
|
if c.debug {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the database connection and prevents new queries from starting.
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
return c.driver.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds the mutation hooks to all the entity clients.
|
||||||
|
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||||
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
|
c.UserVerifications.Use(hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds the query interceptors to all the entity clients.
|
||||||
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||||
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.UserVerifications.Intercept(interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate implements the ent.Mutator interface.
|
||||||
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *UserVerificationsMutation:
|
||||||
|
return c.UserVerifications.mutate(ctx, m)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown mutation type %T", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserVerificationsClient is a client for the UserVerifications schema.
|
||||||
|
type UserVerificationsClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUserVerificationsClient returns a client for the UserVerifications from the given config.
|
||||||
|
func NewUserVerificationsClient(c config) *UserVerificationsClient {
|
||||||
|
return &UserVerificationsClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `userverifications.Hooks(f(g(h())))`.
|
||||||
|
func (c *UserVerificationsClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.UserVerifications = append(c.hooks.UserVerifications, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `userverifications.Intercept(f(g(h())))`.
|
||||||
|
func (c *UserVerificationsClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.UserVerifications = append(c.inters.UserVerifications, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a UserVerifications entity.
|
||||||
|
func (c *UserVerificationsClient) Create() *UserVerificationsCreate {
|
||||||
|
mutation := newUserVerificationsMutation(c.config, OpCreate)
|
||||||
|
return &UserVerificationsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of UserVerifications entities.
|
||||||
|
func (c *UserVerificationsClient) CreateBulk(builders ...*UserVerificationsCreate) *UserVerificationsCreateBulk {
|
||||||
|
return &UserVerificationsCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *UserVerificationsClient) MapCreateBulk(slice any, setFunc func(*UserVerificationsCreate, int)) *UserVerificationsCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &UserVerificationsCreateBulk{err: fmt.Errorf("calling to UserVerificationsClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*UserVerificationsCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &UserVerificationsCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for UserVerifications.
|
||||||
|
func (c *UserVerificationsClient) Update() *UserVerificationsUpdate {
|
||||||
|
mutation := newUserVerificationsMutation(c.config, OpUpdate)
|
||||||
|
return &UserVerificationsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *UserVerificationsClient) UpdateOne(_m *UserVerifications) *UserVerificationsUpdateOne {
|
||||||
|
mutation := newUserVerificationsMutation(c.config, OpUpdateOne, withUserVerifications(_m))
|
||||||
|
return &UserVerificationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *UserVerificationsClient) UpdateOneID(id int64) *UserVerificationsUpdateOne {
|
||||||
|
mutation := newUserVerificationsMutation(c.config, OpUpdateOne, withUserVerificationsID(id))
|
||||||
|
return &UserVerificationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for UserVerifications.
|
||||||
|
func (c *UserVerificationsClient) Delete() *UserVerificationsDelete {
|
||||||
|
mutation := newUserVerificationsMutation(c.config, OpDelete)
|
||||||
|
return &UserVerificationsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *UserVerificationsClient) DeleteOne(_m *UserVerifications) *UserVerificationsDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *UserVerificationsClient) DeleteOneID(id int64) *UserVerificationsDeleteOne {
|
||||||
|
builder := c.Delete().Where(userverifications.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &UserVerificationsDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for UserVerifications.
|
||||||
|
func (c *UserVerificationsClient) Query() *UserVerificationsQuery {
|
||||||
|
return &UserVerificationsQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeUserVerifications},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a UserVerifications entity by its id.
|
||||||
|
func (c *UserVerificationsClient) Get(ctx context.Context, id int64) (*UserVerifications, error) {
|
||||||
|
return c.Query().Where(userverifications.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *UserVerificationsClient) GetX(ctx context.Context, id int64) *UserVerifications {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *UserVerificationsClient) Hooks() []Hook {
|
||||||
|
return c.hooks.UserVerifications
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *UserVerificationsClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.UserVerifications
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *UserVerificationsClient) mutate(ctx context.Context, m *UserVerificationsMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&UserVerificationsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&UserVerificationsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&UserVerificationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&UserVerificationsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown UserVerifications mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hooks and interceptors per client, for fast access.
|
||||||
|
type (
|
||||||
|
hooks struct {
|
||||||
|
UserVerifications []ent.Hook
|
||||||
|
}
|
||||||
|
inters struct {
|
||||||
|
UserVerifications []ent.Interceptor
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -0,0 +1,608 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
"reflect"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ent aliases to avoid import conflicts in user's code.
|
||||||
|
type (
|
||||||
|
Op = ent.Op
|
||||||
|
Hook = ent.Hook
|
||||||
|
Value = ent.Value
|
||||||
|
Query = ent.Query
|
||||||
|
QueryContext = ent.QueryContext
|
||||||
|
Querier = ent.Querier
|
||||||
|
QuerierFunc = ent.QuerierFunc
|
||||||
|
Interceptor = ent.Interceptor
|
||||||
|
InterceptFunc = ent.InterceptFunc
|
||||||
|
Traverser = ent.Traverser
|
||||||
|
TraverseFunc = ent.TraverseFunc
|
||||||
|
Policy = ent.Policy
|
||||||
|
Mutator = ent.Mutator
|
||||||
|
Mutation = ent.Mutation
|
||||||
|
MutateFunc = ent.MutateFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
type clientCtxKey struct{}
|
||||||
|
|
||||||
|
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||||
|
func FromContext(ctx context.Context) *Client {
|
||||||
|
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext returns a new context with the given Client attached.
|
||||||
|
func NewContext(parent context.Context, c *Client) context.Context {
|
||||||
|
return context.WithValue(parent, clientCtxKey{}, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
type txCtxKey struct{}
|
||||||
|
|
||||||
|
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||||
|
func TxFromContext(ctx context.Context) *Tx {
|
||||||
|
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTxContext returns a new context with the given Tx attached.
|
||||||
|
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||||
|
return context.WithValue(parent, txCtxKey{}, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderFunc applies an ordering on the sql selector.
|
||||||
|
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||||
|
type OrderFunc func(*sql.Selector)
|
||||||
|
|
||||||
|
var (
|
||||||
|
initCheck sync.Once
|
||||||
|
columnCheck sql.ColumnCheck
|
||||||
|
)
|
||||||
|
|
||||||
|
// checkColumn checks if the column exists in the given table.
|
||||||
|
func checkColumn(t, c string) error {
|
||||||
|
initCheck.Do(func() {
|
||||||
|
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||||
|
userverifications.Table: userverifications.ValidColumn,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return columnCheck(t, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asc applies the given fields in ASC order.
|
||||||
|
func Asc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Asc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desc applies the given fields in DESC order.
|
||||||
|
func Desc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Desc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||||
|
type AggregateFunc func(*sql.Selector) string
|
||||||
|
|
||||||
|
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||||
|
//
|
||||||
|
// GroupBy(field1, field2).
|
||||||
|
// Aggregate(models.As(models.Sum(field1), "sum_field1"), (models.As(models.Sum(field2), "sum_field2")).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.As(fn(s), end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count applies the "count" aggregation function on each group.
|
||||||
|
func Count() AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.Count("*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max applies the "max" aggregation function on the given field of each group.
|
||||||
|
func Max(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Max(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||||
|
func Mean(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Avg(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Min applies the "min" aggregation function on the given field of each group.
|
||||||
|
func Min(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Min(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||||
|
func Sum(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Sum(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidationError returns when validating a field or edge fails.
|
||||||
|
type ValidationError struct {
|
||||||
|
Name string // Field or edge name.
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *ValidationError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ValidationError) Unwrap() error {
|
||||||
|
return e.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||||
|
func IsValidationError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ValidationError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||||
|
type NotFoundError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotFoundError) Error() string {
|
||||||
|
return "models: " + e.label + " not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||||
|
func IsNotFound(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotFoundError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaskNotFound masks not found error.
|
||||||
|
func MaskNotFound(err error) error {
|
||||||
|
if IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||||
|
type NotSingularError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotSingularError) Error() string {
|
||||||
|
return "models: " + e.label + " not singular"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||||
|
func IsNotSingular(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotSingularError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||||
|
type NotLoadedError struct {
|
||||||
|
edge string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotLoadedError) Error() string {
|
||||||
|
return "models: " + e.edge + " edge was not loaded"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||||
|
func IsNotLoaded(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotLoadedError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConstraintError returns when trying to create/update one or more entities and
|
||||||
|
// one or more of their constraints failed. For example, violation of edge or
|
||||||
|
// field uniqueness.
|
||||||
|
type ConstraintError struct {
|
||||||
|
msg string
|
||||||
|
wrap error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ConstraintError) Error() string {
|
||||||
|
return "models: constraint failed: " + e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ConstraintError) Unwrap() error {
|
||||||
|
return e.wrap
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||||
|
func IsConstraintError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ConstraintError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// selector embedded by the different Select/GroupBy builders.
|
||||||
|
type selector struct {
|
||||||
|
label string
|
||||||
|
flds *[]string
|
||||||
|
fns []AggregateFunc
|
||||||
|
scan func(context.Context, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||||
|
if err := s.scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Strings is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (s *selector) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := s.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = s.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (s *selector) StringX(ctx context.Context) string {
|
||||||
|
v, err := s.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Ints is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (s *selector) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := s.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = s.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (s *selector) IntX(ctx context.Context) int {
|
||||||
|
v, err := s.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Float64s is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := s.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = s.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := s.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Bools is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := s.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = s.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := s.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// withHooks invokes the builder operation with the given hooks, if any.
|
||||||
|
func withHooks[V Value, M any, PM interface {
|
||||||
|
*M
|
||||||
|
Mutation
|
||||||
|
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||||
|
if len(hooks) == 0 {
|
||||||
|
return exec(ctx)
|
||||||
|
}
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutationT, ok := any(m).(PM)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
// Set the mutation to the builder.
|
||||||
|
*mutation = *mutationT
|
||||||
|
return exec(ctx)
|
||||||
|
})
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
if hooks[i] == nil {
|
||||||
|
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = hooks[i](mut)
|
||||||
|
}
|
||||||
|
v, err := mut.Mutate(ctx, mutation)
|
||||||
|
if err != nil {
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
nv, ok := v.(V)
|
||||||
|
if !ok {
|
||||||
|
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||||
|
}
|
||||||
|
return nv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||||
|
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||||
|
if ent.QueryFromContext(ctx) == nil {
|
||||||
|
qc.Op = op
|
||||||
|
ctx = ent.NewQueryContext(ctx, qc)
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierAll[V Value, Q interface {
|
||||||
|
sqlAll(context.Context, ...queryHook) (V, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlAll(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierCount[Q interface {
|
||||||
|
sqlCount(context.Context) (int, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlCount(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
rv, err := qr.Query(ctx, q)
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
vt, ok := rv.(V)
|
||||||
|
if !ok {
|
||||||
|
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||||
|
}
|
||||||
|
return vt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||||
|
sqlScan(context.Context, Q1, any) error
|
||||||
|
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||||
|
rv := reflect.ValueOf(v)
|
||||||
|
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q1)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||||
|
return rv.Elem().Interface(), nil
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
})
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
vv, err := qr.Query(ctx, rootQuery)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch rv2 := reflect.ValueOf(vv); {
|
||||||
|
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||||
|
case rv.Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2.Elem())
|
||||||
|
case rv.Elem().Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// queryHook describes an internal hook for the different sqlAll methods.
|
||||||
|
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package enttest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models"
|
||||||
|
// required by schema hooks.
|
||||||
|
_ "juwan-backend/app/user_verifications/rpc/internal/models/runtime"
|
||||||
|
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/migrate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TestingT is the interface that is shared between
|
||||||
|
// testing.T and testing.B and used by enttest.
|
||||||
|
TestingT interface {
|
||||||
|
FailNow()
|
||||||
|
Error(...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option configures client creation.
|
||||||
|
Option func(*options)
|
||||||
|
|
||||||
|
options struct {
|
||||||
|
opts []models.Option
|
||||||
|
migrateOpts []schema.MigrateOption
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithOptions forwards options to client creation.
|
||||||
|
func WithOptions(opts ...models.Option) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.opts = append(o.opts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMigrateOptions forwards options to auto migration.
|
||||||
|
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOptions(opts []Option) *options {
|
||||||
|
o := &options{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(o)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open calls models.Open and auto-run migration.
|
||||||
|
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *models.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c, err := models.Open(driverName, dataSourceName, o.opts...)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient calls models.NewClient and auto-run migration.
|
||||||
|
func NewClient(t TestingT, opts ...Option) *models.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c := models.NewClient(o.opts...)
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
func migrateSchema(t TestingT, c *models.Client, o *options) {
|
||||||
|
tables, err := schema.CopyTables(migrate.Tables)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package hook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The UserVerificationsFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as UserVerifications mutator.
|
||||||
|
type UserVerificationsFunc func(context.Context, *models.UserVerificationsMutation) (models.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f UserVerificationsFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if mv, ok := m.(*models.UserVerificationsMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.UserVerificationsMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Condition is a hook condition function.
|
||||||
|
type Condition func(context.Context, models.Mutation) bool
|
||||||
|
|
||||||
|
// And groups conditions with the AND operator.
|
||||||
|
func And(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
if !first(ctx, m) || !second(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if !cond(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups conditions with the OR operator.
|
||||||
|
func Or(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
if first(ctx, m) || second(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not negates a given condition.
|
||||||
|
func Not(cond Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
return !cond(ctx, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasOp is a condition testing mutation operation.
|
||||||
|
func HasOp(op models.Op) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
return m.Op().Is(op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||||
|
func HasAddedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||||
|
func HasClearedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasFields is a condition validating `.Field` on fields.
|
||||||
|
func HasFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If executes the given hook under condition.
|
||||||
|
//
|
||||||
|
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||||
|
func If(hk models.Hook, cond Condition) models.Hook {
|
||||||
|
return func(next models.Mutator) models.Mutator {
|
||||||
|
return models.MutateFunc(func(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return hk(next).Mutate(ctx, m)
|
||||||
|
}
|
||||||
|
return next.Mutate(ctx, m)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On executes the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.On(Log, models.Delete|models.Create)
|
||||||
|
func On(hk models.Hook, op models.Op) models.Hook {
|
||||||
|
return If(hk, HasOp(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unless skips the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.Unless(Log, models.Update|models.UpdateOne)
|
||||||
|
func Unless(hk models.Hook, op models.Op) models.Hook {
|
||||||
|
return If(hk, Not(HasOp(op)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedError is a hook returning a fixed error.
|
||||||
|
func FixedError(err error) models.Hook {
|
||||||
|
return func(models.Mutator) models.Mutator {
|
||||||
|
return models.MutateFunc(func(context.Context, models.Mutation) (models.Value, error) {
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject returns a hook that rejects all operations that match op.
|
||||||
|
//
|
||||||
|
// func (T) Hooks() []models.Hook {
|
||||||
|
// return []models.Hook{
|
||||||
|
// Reject(models.Delete|models.Update),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
func Reject(op models.Op) models.Hook {
|
||||||
|
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||||
|
return On(hk, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chain acts as a list of hooks and is effectively immutable.
|
||||||
|
// Once created, it will always hold the same set of hooks in the same order.
|
||||||
|
type Chain struct {
|
||||||
|
hooks []models.Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewChain creates a new chain of hooks.
|
||||||
|
func NewChain(hooks ...models.Hook) Chain {
|
||||||
|
return Chain{append([]models.Hook(nil), hooks...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook chains the list of hooks and returns the final hook.
|
||||||
|
func (c Chain) Hook() models.Hook {
|
||||||
|
return func(mutator models.Mutator) models.Mutator {
|
||||||
|
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||||
|
mutator = c.hooks[i](mutator)
|
||||||
|
}
|
||||||
|
return mutator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append extends a chain, adding the specified hook
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Append(hooks ...models.Hook) Chain {
|
||||||
|
newHooks := make([]models.Hook, 0, len(c.hooks)+len(hooks))
|
||||||
|
newHooks = append(newHooks, c.hooks...)
|
||||||
|
newHooks = append(newHooks, hooks...)
|
||||||
|
return Chain{newHooks}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend extends a chain, adding the specified chain
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Extend(chain Chain) Chain {
|
||||||
|
return c.Append(chain.hooks...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||||
|
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||||
|
// for the ids of each entity (table).
|
||||||
|
// Note that this option cannot be applied on tables that already exist.
|
||||||
|
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||||
|
// WithDropColumn sets the drop column option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old columns
|
||||||
|
// that were used for both fields and edges. This defaults to false.
|
||||||
|
WithDropColumn = schema.WithDropColumn
|
||||||
|
// WithDropIndex sets the drop index option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old indexes
|
||||||
|
// that were defined in the schema. This defaults to false.
|
||||||
|
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||||
|
// and therefore, it's recommended to enable this option to get more
|
||||||
|
// flexibility in the schema changes.
|
||||||
|
WithDropIndex = schema.WithDropIndex
|
||||||
|
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||||
|
WithForeignKeys = schema.WithForeignKeys
|
||||||
|
)
|
||||||
|
|
||||||
|
// Schema is the API for creating, migrating and dropping a schema.
|
||||||
|
type Schema struct {
|
||||||
|
drv dialect.Driver
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSchema creates a new schema client.
|
||||||
|
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||||
|
|
||||||
|
// Create creates all schema resources.
|
||||||
|
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, s, Tables, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates all table resources using the given schema driver.
|
||||||
|
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||||
|
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ent/migrate: %w", err)
|
||||||
|
}
|
||||||
|
return migrate.Create(ctx, tables...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||||
|
//
|
||||||
|
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// UserVerificationsColumns holds the columns for the "user_verifications" table.
|
||||||
|
UserVerificationsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "user_id", Type: field.TypeInt64, Unique: true},
|
||||||
|
{Name: "role", Type: field.TypeString, Unique: true},
|
||||||
|
{Name: "status", Type: field.TypeString, Default: "pending"},
|
||||||
|
{Name: "materials", Type: field.TypeJSON},
|
||||||
|
{Name: "reject_reason", Type: field.TypeString, Default: ""},
|
||||||
|
{Name: "reviewed_by", Type: field.TypeInt64},
|
||||||
|
{Name: "reviewed_at", Type: field.TypeTime},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
}
|
||||||
|
// UserVerificationsTable holds the schema information for the "user_verifications" table.
|
||||||
|
UserVerificationsTable = &schema.Table{
|
||||||
|
Name: "user_verifications",
|
||||||
|
Columns: UserVerificationsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{UserVerificationsColumns[0]},
|
||||||
|
}
|
||||||
|
// Tables holds all the tables in the schema.
|
||||||
|
Tables = []*schema.Table{
|
||||||
|
UserVerificationsTable,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,862 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/predicate"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Operation types.
|
||||||
|
OpCreate = ent.OpCreate
|
||||||
|
OpDelete = ent.OpDelete
|
||||||
|
OpDeleteOne = ent.OpDeleteOne
|
||||||
|
OpUpdate = ent.OpUpdate
|
||||||
|
OpUpdateOne = ent.OpUpdateOne
|
||||||
|
|
||||||
|
// Node types.
|
||||||
|
TypeUserVerifications = "UserVerifications"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserVerificationsMutation represents an operation that mutates the UserVerifications nodes in the graph.
|
||||||
|
type UserVerificationsMutation struct {
|
||||||
|
config
|
||||||
|
op Op
|
||||||
|
typ string
|
||||||
|
id *int64
|
||||||
|
user_id *int64
|
||||||
|
adduser_id *int64
|
||||||
|
role *string
|
||||||
|
status *string
|
||||||
|
materials *schema.MaterialStruct
|
||||||
|
reject_reason *string
|
||||||
|
reviewed_by *int64
|
||||||
|
addreviewed_by *int64
|
||||||
|
reviewed_at *time.Time
|
||||||
|
created_at *time.Time
|
||||||
|
updated_at *time.Time
|
||||||
|
clearedFields map[string]struct{}
|
||||||
|
done bool
|
||||||
|
oldValue func(context.Context) (*UserVerifications, error)
|
||||||
|
predicates []predicate.UserVerifications
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ent.Mutation = (*UserVerificationsMutation)(nil)
|
||||||
|
|
||||||
|
// userverificationsOption allows management of the mutation configuration using functional options.
|
||||||
|
type userverificationsOption func(*UserVerificationsMutation)
|
||||||
|
|
||||||
|
// newUserVerificationsMutation creates new mutation for the UserVerifications entity.
|
||||||
|
func newUserVerificationsMutation(c config, op Op, opts ...userverificationsOption) *UserVerificationsMutation {
|
||||||
|
m := &UserVerificationsMutation{
|
||||||
|
config: c,
|
||||||
|
op: op,
|
||||||
|
typ: TypeUserVerifications,
|
||||||
|
clearedFields: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(m)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// withUserVerificationsID sets the ID field of the mutation.
|
||||||
|
func withUserVerificationsID(id int64) userverificationsOption {
|
||||||
|
return func(m *UserVerificationsMutation) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
once sync.Once
|
||||||
|
value *UserVerifications
|
||||||
|
)
|
||||||
|
m.oldValue = func(ctx context.Context) (*UserVerifications, error) {
|
||||||
|
once.Do(func() {
|
||||||
|
if m.done {
|
||||||
|
err = errors.New("querying old values post mutation is not allowed")
|
||||||
|
} else {
|
||||||
|
value, err = m.Client().UserVerifications.Get(ctx, id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
m.id = &id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// withUserVerifications sets the old UserVerifications of the mutation.
|
||||||
|
func withUserVerifications(node *UserVerifications) userverificationsOption {
|
||||||
|
return func(m *UserVerificationsMutation) {
|
||||||
|
m.oldValue = func(context.Context) (*UserVerifications, error) {
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
|
m.id = &node.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||||
|
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||||
|
func (m UserVerificationsMutation) Client() *Client {
|
||||||
|
client := &Client{config: m.config}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||||
|
// it returns an error otherwise.
|
||||||
|
func (m UserVerificationsMutation) Tx() (*Tx, error) {
|
||||||
|
if _, ok := m.driver.(*txDriver); !ok {
|
||||||
|
return nil, errors.New("models: mutation is not running in a transaction")
|
||||||
|
}
|
||||||
|
tx := &Tx{config: m.config}
|
||||||
|
tx.init()
|
||||||
|
return tx, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the value of the id field. Note that this
|
||||||
|
// operation is only accepted on creation of UserVerifications entities.
|
||||||
|
func (m *UserVerificationsMutation) SetID(id int64) {
|
||||||
|
m.id = &id
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||||
|
// if it was provided to the builder or after it was returned from the database.
|
||||||
|
func (m *UserVerificationsMutation) ID() (id int64, exists bool) {
|
||||||
|
if m.id == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *m.id, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||||
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||||
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||||
|
// or updated by the mutation.
|
||||||
|
func (m *UserVerificationsMutation) IDs(ctx context.Context) ([]int64, error) {
|
||||||
|
switch {
|
||||||
|
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||||
|
id, exists := m.ID()
|
||||||
|
if exists {
|
||||||
|
return []int64{id}, nil
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
case m.op.Is(OpUpdate | OpDelete):
|
||||||
|
return m.Client().UserVerifications.Query().Where(m.predicates...).IDs(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (m *UserVerificationsMutation) SetUserID(i int64) {
|
||||||
|
m.user_id = &i
|
||||||
|
m.adduser_id = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID returns the value of the "user_id" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) UserID() (r int64, exists bool) {
|
||||||
|
v := m.user_id
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldUserID returns the old "user_id" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldUserID(ctx context.Context) (v int64, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldUserID requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.UserID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUserID adds i to the "user_id" field.
|
||||||
|
func (m *UserVerificationsMutation) AddUserID(i int64) {
|
||||||
|
if m.adduser_id != nil {
|
||||||
|
*m.adduser_id += i
|
||||||
|
} else {
|
||||||
|
m.adduser_id = &i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedUserID returns the value that was added to the "user_id" field in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) AddedUserID() (r int64, exists bool) {
|
||||||
|
v := m.adduser_id
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetUserID resets all changes to the "user_id" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetUserID() {
|
||||||
|
m.user_id = nil
|
||||||
|
m.adduser_id = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRole sets the "role" field.
|
||||||
|
func (m *UserVerificationsMutation) SetRole(s string) {
|
||||||
|
m.role = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Role returns the value of the "role" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) Role() (r string, exists bool) {
|
||||||
|
v := m.role
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldRole returns the old "role" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldRole(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldRole is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldRole requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldRole: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Role, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetRole resets all changes to the "role" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetRole() {
|
||||||
|
m.role = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (m *UserVerificationsMutation) SetStatus(s string) {
|
||||||
|
m.status = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status returns the value of the "status" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) Status() (r string, exists bool) {
|
||||||
|
v := m.status
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldStatus returns the old "status" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldStatus(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldStatus requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldStatus: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetStatus resets all changes to the "status" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetStatus() {
|
||||||
|
m.status = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaterials sets the "materials" field.
|
||||||
|
func (m *UserVerificationsMutation) SetMaterials(ss schema.MaterialStruct) {
|
||||||
|
m.materials = &ss
|
||||||
|
}
|
||||||
|
|
||||||
|
// Materials returns the value of the "materials" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) Materials() (r schema.MaterialStruct, exists bool) {
|
||||||
|
v := m.materials
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldMaterials returns the old "materials" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldMaterials(ctx context.Context) (v schema.MaterialStruct, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldMaterials is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldMaterials requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldMaterials: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Materials, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetMaterials resets all changes to the "materials" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetMaterials() {
|
||||||
|
m.materials = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRejectReason sets the "reject_reason" field.
|
||||||
|
func (m *UserVerificationsMutation) SetRejectReason(s string) {
|
||||||
|
m.reject_reason = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReason returns the value of the "reject_reason" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) RejectReason() (r string, exists bool) {
|
||||||
|
v := m.reject_reason
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldRejectReason returns the old "reject_reason" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldRejectReason(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldRejectReason is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldRejectReason requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldRejectReason: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.RejectReason, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetRejectReason resets all changes to the "reject_reason" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetRejectReason() {
|
||||||
|
m.reject_reason = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReviewedBy sets the "reviewed_by" field.
|
||||||
|
func (m *UserVerificationsMutation) SetReviewedBy(i int64) {
|
||||||
|
m.reviewed_by = &i
|
||||||
|
m.addreviewed_by = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedBy returns the value of the "reviewed_by" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) ReviewedBy() (r int64, exists bool) {
|
||||||
|
v := m.reviewed_by
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldReviewedBy returns the old "reviewed_by" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldReviewedBy(ctx context.Context) (v int64, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldReviewedBy is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldReviewedBy requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldReviewedBy: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.ReviewedBy, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddReviewedBy adds i to the "reviewed_by" field.
|
||||||
|
func (m *UserVerificationsMutation) AddReviewedBy(i int64) {
|
||||||
|
if m.addreviewed_by != nil {
|
||||||
|
*m.addreviewed_by += i
|
||||||
|
} else {
|
||||||
|
m.addreviewed_by = &i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedReviewedBy returns the value that was added to the "reviewed_by" field in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) AddedReviewedBy() (r int64, exists bool) {
|
||||||
|
v := m.addreviewed_by
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetReviewedBy resets all changes to the "reviewed_by" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetReviewedBy() {
|
||||||
|
m.reviewed_by = nil
|
||||||
|
m.addreviewed_by = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReviewedAt sets the "reviewed_at" field.
|
||||||
|
func (m *UserVerificationsMutation) SetReviewedAt(t time.Time) {
|
||||||
|
m.reviewed_at = &t
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAt returns the value of the "reviewed_at" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) ReviewedAt() (r time.Time, exists bool) {
|
||||||
|
v := m.reviewed_at
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldReviewedAt returns the old "reviewed_at" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldReviewedAt(ctx context.Context) (v time.Time, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldReviewedAt is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldReviewedAt requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldReviewedAt: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.ReviewedAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetReviewedAt resets all changes to the "reviewed_at" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetReviewedAt() {
|
||||||
|
m.reviewed_at = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (m *UserVerificationsMutation) SetCreatedAt(t time.Time) {
|
||||||
|
m.created_at = &t
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt returns the value of the "created_at" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) CreatedAt() (r time.Time, exists bool) {
|
||||||
|
v := m.created_at
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldCreatedAt returns the old "created_at" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.CreatedAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetCreatedAt resets all changes to the "created_at" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetCreatedAt() {
|
||||||
|
m.created_at = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (m *UserVerificationsMutation) SetUpdatedAt(t time.Time) {
|
||||||
|
m.updated_at = &t
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt returns the value of the "updated_at" field in the mutation.
|
||||||
|
func (m *UserVerificationsMutation) UpdatedAt() (r time.Time, exists bool) {
|
||||||
|
v := m.updated_at
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldUpdatedAt returns the old "updated_at" field's value of the UserVerifications entity.
|
||||||
|
// If the UserVerifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *UserVerificationsMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.UpdatedAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
||||||
|
func (m *UserVerificationsMutation) ResetUpdatedAt() {
|
||||||
|
m.updated_at = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserVerificationsMutation builder.
|
||||||
|
func (m *UserVerificationsMutation) Where(ps ...predicate.UserVerifications) {
|
||||||
|
m.predicates = append(m.predicates, ps...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereP appends storage-level predicates to the UserVerificationsMutation builder. Using this method,
|
||||||
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||||
|
func (m *UserVerificationsMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||||
|
p := make([]predicate.UserVerifications, len(ps))
|
||||||
|
for i := range ps {
|
||||||
|
p[i] = ps[i]
|
||||||
|
}
|
||||||
|
m.Where(p...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Op returns the operation name.
|
||||||
|
func (m *UserVerificationsMutation) Op() Op {
|
||||||
|
return m.op
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOp allows setting the mutation operation.
|
||||||
|
func (m *UserVerificationsMutation) SetOp(op Op) {
|
||||||
|
m.op = op
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the node type of this mutation (UserVerifications).
|
||||||
|
func (m *UserVerificationsMutation) Type() string {
|
||||||
|
return m.typ
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields returns all fields that were changed during this mutation. Note that in
|
||||||
|
// order to get all numeric fields that were incremented/decremented, call
|
||||||
|
// AddedFields().
|
||||||
|
func (m *UserVerificationsMutation) Fields() []string {
|
||||||
|
fields := make([]string, 0, 9)
|
||||||
|
if m.user_id != nil {
|
||||||
|
fields = append(fields, userverifications.FieldUserID)
|
||||||
|
}
|
||||||
|
if m.role != nil {
|
||||||
|
fields = append(fields, userverifications.FieldRole)
|
||||||
|
}
|
||||||
|
if m.status != nil {
|
||||||
|
fields = append(fields, userverifications.FieldStatus)
|
||||||
|
}
|
||||||
|
if m.materials != nil {
|
||||||
|
fields = append(fields, userverifications.FieldMaterials)
|
||||||
|
}
|
||||||
|
if m.reject_reason != nil {
|
||||||
|
fields = append(fields, userverifications.FieldRejectReason)
|
||||||
|
}
|
||||||
|
if m.reviewed_by != nil {
|
||||||
|
fields = append(fields, userverifications.FieldReviewedBy)
|
||||||
|
}
|
||||||
|
if m.reviewed_at != nil {
|
||||||
|
fields = append(fields, userverifications.FieldReviewedAt)
|
||||||
|
}
|
||||||
|
if m.created_at != nil {
|
||||||
|
fields = append(fields, userverifications.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
if m.updated_at != nil {
|
||||||
|
fields = append(fields, userverifications.FieldUpdatedAt)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// Field returns the value of a field with the given name. The second boolean
|
||||||
|
// return value indicates that this field was not set, or was not defined in the
|
||||||
|
// schema.
|
||||||
|
func (m *UserVerificationsMutation) Field(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case userverifications.FieldUserID:
|
||||||
|
return m.UserID()
|
||||||
|
case userverifications.FieldRole:
|
||||||
|
return m.Role()
|
||||||
|
case userverifications.FieldStatus:
|
||||||
|
return m.Status()
|
||||||
|
case userverifications.FieldMaterials:
|
||||||
|
return m.Materials()
|
||||||
|
case userverifications.FieldRejectReason:
|
||||||
|
return m.RejectReason()
|
||||||
|
case userverifications.FieldReviewedBy:
|
||||||
|
return m.ReviewedBy()
|
||||||
|
case userverifications.FieldReviewedAt:
|
||||||
|
return m.ReviewedAt()
|
||||||
|
case userverifications.FieldCreatedAt:
|
||||||
|
return m.CreatedAt()
|
||||||
|
case userverifications.FieldUpdatedAt:
|
||||||
|
return m.UpdatedAt()
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldField returns the old value of the field from the database. An error is
|
||||||
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||||
|
// database failed.
|
||||||
|
func (m *UserVerificationsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||||
|
switch name {
|
||||||
|
case userverifications.FieldUserID:
|
||||||
|
return m.OldUserID(ctx)
|
||||||
|
case userverifications.FieldRole:
|
||||||
|
return m.OldRole(ctx)
|
||||||
|
case userverifications.FieldStatus:
|
||||||
|
return m.OldStatus(ctx)
|
||||||
|
case userverifications.FieldMaterials:
|
||||||
|
return m.OldMaterials(ctx)
|
||||||
|
case userverifications.FieldRejectReason:
|
||||||
|
return m.OldRejectReason(ctx)
|
||||||
|
case userverifications.FieldReviewedBy:
|
||||||
|
return m.OldReviewedBy(ctx)
|
||||||
|
case userverifications.FieldReviewedAt:
|
||||||
|
return m.OldReviewedAt(ctx)
|
||||||
|
case userverifications.FieldCreatedAt:
|
||||||
|
return m.OldCreatedAt(ctx)
|
||||||
|
case userverifications.FieldUpdatedAt:
|
||||||
|
return m.OldUpdatedAt(ctx)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unknown UserVerifications field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetField sets the value of a field with the given name. It returns an error if
|
||||||
|
// the field is not defined in the schema, or if the type mismatched the field
|
||||||
|
// type.
|
||||||
|
func (m *UserVerificationsMutation) SetField(name string, value ent.Value) error {
|
||||||
|
switch name {
|
||||||
|
case userverifications.FieldUserID:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetUserID(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldRole:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetRole(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldStatus:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetStatus(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldMaterials:
|
||||||
|
v, ok := value.(schema.MaterialStruct)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetMaterials(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldRejectReason:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetRejectReason(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldReviewedBy:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetReviewedBy(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldReviewedAt:
|
||||||
|
v, ok := value.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetReviewedAt(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldCreatedAt:
|
||||||
|
v, ok := value.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetCreatedAt(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldUpdatedAt:
|
||||||
|
v, ok := value.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetUpdatedAt(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown UserVerifications field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||||
|
// this mutation.
|
||||||
|
func (m *UserVerificationsMutation) AddedFields() []string {
|
||||||
|
var fields []string
|
||||||
|
if m.adduser_id != nil {
|
||||||
|
fields = append(fields, userverifications.FieldUserID)
|
||||||
|
}
|
||||||
|
if m.addreviewed_by != nil {
|
||||||
|
fields = append(fields, userverifications.FieldReviewedBy)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||||
|
// with the given name. The second boolean return value indicates that this field
|
||||||
|
// was not set, or was not defined in the schema.
|
||||||
|
func (m *UserVerificationsMutation) AddedField(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case userverifications.FieldUserID:
|
||||||
|
return m.AddedUserID()
|
||||||
|
case userverifications.FieldReviewedBy:
|
||||||
|
return m.AddedReviewedBy()
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddField adds the value to the field with the given name. It returns an error if
|
||||||
|
// the field is not defined in the schema, or if the type mismatched the field
|
||||||
|
// type.
|
||||||
|
func (m *UserVerificationsMutation) AddField(name string, value ent.Value) error {
|
||||||
|
switch name {
|
||||||
|
case userverifications.FieldUserID:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.AddUserID(v)
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldReviewedBy:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.AddReviewedBy(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown UserVerifications numeric field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearedFields returns all nullable fields that were cleared during this
|
||||||
|
// mutation.
|
||||||
|
func (m *UserVerificationsMutation) ClearedFields() []string {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||||
|
// cleared in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) FieldCleared(name string) bool {
|
||||||
|
_, ok := m.clearedFields[name]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearField clears the value of the field with the given name. It returns an
|
||||||
|
// error if the field is not defined in the schema.
|
||||||
|
func (m *UserVerificationsMutation) ClearField(name string) error {
|
||||||
|
return fmt.Errorf("unknown UserVerifications nullable field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetField resets all changes in the mutation for the field with the given name.
|
||||||
|
// It returns an error if the field is not defined in the schema.
|
||||||
|
func (m *UserVerificationsMutation) ResetField(name string) error {
|
||||||
|
switch name {
|
||||||
|
case userverifications.FieldUserID:
|
||||||
|
m.ResetUserID()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldRole:
|
||||||
|
m.ResetRole()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldStatus:
|
||||||
|
m.ResetStatus()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldMaterials:
|
||||||
|
m.ResetMaterials()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldRejectReason:
|
||||||
|
m.ResetRejectReason()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldReviewedBy:
|
||||||
|
m.ResetReviewedBy()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldReviewedAt:
|
||||||
|
m.ResetReviewedAt()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldCreatedAt:
|
||||||
|
m.ResetCreatedAt()
|
||||||
|
return nil
|
||||||
|
case userverifications.FieldUpdatedAt:
|
||||||
|
m.ResetUpdatedAt()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown UserVerifications field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) AddedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||||
|
// name in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) AddedIDs(name string) []ent.Value {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) RemovedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||||
|
// the given name in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) RemovedIDs(name string) []ent.Value {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) ClearedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||||
|
// was cleared in this mutation.
|
||||||
|
func (m *UserVerificationsMutation) EdgeCleared(name string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||||
|
// if that edge is not defined in the schema.
|
||||||
|
func (m *UserVerificationsMutation) ClearEdge(name string) error {
|
||||||
|
return fmt.Errorf("unknown UserVerifications unique edge %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||||
|
// It returns an error if the edge is not defined in the schema.
|
||||||
|
func (m *UserVerificationsMutation) ResetEdge(name string) error {
|
||||||
|
return fmt.Errorf("unknown UserVerifications edge %s", name)
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package predicate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserVerifications is the predicate function for userverifications builders.
|
||||||
|
type UserVerifications func(*sql.Selector)
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The init function reads all schema descriptors with runtime code
|
||||||
|
// (default values, validators, hooks and policies) and stitches it
|
||||||
|
// to their package variables.
|
||||||
|
func init() {
|
||||||
|
userverificationsFields := schema.UserVerifications{}.Fields()
|
||||||
|
_ = userverificationsFields
|
||||||
|
// userverificationsDescStatus is the schema descriptor for status field.
|
||||||
|
userverificationsDescStatus := userverificationsFields[3].Descriptor()
|
||||||
|
// userverifications.DefaultStatus holds the default value on creation for the status field.
|
||||||
|
userverifications.DefaultStatus = userverificationsDescStatus.Default.(string)
|
||||||
|
// userverificationsDescRejectReason is the schema descriptor for reject_reason field.
|
||||||
|
userverificationsDescRejectReason := userverificationsFields[5].Descriptor()
|
||||||
|
// userverifications.DefaultRejectReason holds the default value on creation for the reject_reason field.
|
||||||
|
userverifications.DefaultRejectReason = userverificationsDescRejectReason.Default.(string)
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
// The schema-stitching logic is generated in juwan-backend/app/user_verifications/rpc/internal/models/runtime.go
|
||||||
|
|
||||||
|
const (
|
||||||
|
Version = "v0.14.5" // Version of ent codegen.
|
||||||
|
Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen.
|
||||||
|
)
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserVerifications holds the schema definition for the UserVerifications entity.
|
||||||
|
type UserVerifications struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
type MaterialStruct struct {
|
||||||
|
IdCardFront string `json:"idCardFront"`
|
||||||
|
IdCardBack string `json:"idCardBack"`
|
||||||
|
GameScreenshots []string `json:"gameScreenshots"`
|
||||||
|
VoiceDemo string `json:"voiceDemo"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the UserVerifications.
|
||||||
|
func (UserVerifications) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.Int64("id").Immutable().Unique(),
|
||||||
|
field.Int64("user_id").Immutable().Unique(),
|
||||||
|
field.String("role").Unique(),
|
||||||
|
field.String("status").Default("pending"),
|
||||||
|
field.JSON("materials", MaterialStruct{}),
|
||||||
|
field.String("reject_reason").Default(""),
|
||||||
|
field.Int64("reviewed_by"),
|
||||||
|
field.Time("reviewed_at").Immutable(),
|
||||||
|
field.Time("created_at").Immutable(),
|
||||||
|
field.Time("updated_at").Immutable(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the UserVerifications.
|
||||||
|
func (UserVerifications) Edges() []ent.Edge {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tx is a transactional client that is created by calling Client.Tx().
|
||||||
|
type Tx struct {
|
||||||
|
config
|
||||||
|
// UserVerifications is the client for interacting with the UserVerifications builders.
|
||||||
|
UserVerifications *UserVerificationsClient
|
||||||
|
|
||||||
|
// lazily loaded.
|
||||||
|
client *Client
|
||||||
|
clientOnce sync.Once
|
||||||
|
// ctx lives for the life of the transaction. It is
|
||||||
|
// the same context used by the underlying connection.
|
||||||
|
ctx context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Committer is the interface that wraps the Commit method.
|
||||||
|
Committer interface {
|
||||||
|
Commit(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Committer. If f is a function with the appropriate
|
||||||
|
// signature, CommitFunc(f) is a Committer that calls f.
|
||||||
|
CommitFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||||
|
// and returns a Committer. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Committer) ent.Committer {
|
||||||
|
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Commit(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
CommitHook func(Committer) Committer
|
||||||
|
)
|
||||||
|
|
||||||
|
// Commit calls f(ctx, m).
|
||||||
|
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit commits the transaction.
|
||||||
|
func (tx *Tx) Commit() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Commit()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]CommitHook(nil), txDriver.onCommit...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Commit(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnCommit adds a hook to call on commit.
|
||||||
|
func (tx *Tx) OnCommit(f CommitHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onCommit = append(txDriver.onCommit, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Rollbacker is the interface that wraps the Rollback method.
|
||||||
|
Rollbacker interface {
|
||||||
|
Rollback(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Rollbacker. If f is a function with the appropriate
|
||||||
|
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||||
|
RollbackFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||||
|
// and returns a Rollbacker. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||||
|
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Rollback(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
RollbackHook func(Rollbacker) Rollbacker
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rollback calls f(ctx, m).
|
||||||
|
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollback rollbacks the transaction.
|
||||||
|
func (tx *Tx) Rollback() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Rollback()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Rollback(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnRollback adds a hook to call on rollback.
|
||||||
|
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onRollback = append(txDriver.onRollback, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a Client that binds to current transaction.
|
||||||
|
func (tx *Tx) Client() *Client {
|
||||||
|
tx.clientOnce.Do(func() {
|
||||||
|
tx.client = &Client{config: tx.config}
|
||||||
|
tx.client.init()
|
||||||
|
})
|
||||||
|
return tx.client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) init() {
|
||||||
|
tx.UserVerifications = NewUserVerificationsClient(tx.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||||
|
// The idea is to support transactions without adding any extra code to the builders.
|
||||||
|
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||||
|
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||||
|
// of them in order to commit or rollback the transaction.
|
||||||
|
//
|
||||||
|
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||||
|
// applies a query, for example: UserVerifications.QueryXXX(), the query will be executed
|
||||||
|
// through the driver which created this transaction.
|
||||||
|
//
|
||||||
|
// Note that txDriver is not goroutine safe.
|
||||||
|
type txDriver struct {
|
||||||
|
// the driver we started the transaction from.
|
||||||
|
drv dialect.Driver
|
||||||
|
// tx is the underlying transaction.
|
||||||
|
tx dialect.Tx
|
||||||
|
// completion hooks.
|
||||||
|
mu sync.Mutex
|
||||||
|
onCommit []CommitHook
|
||||||
|
onRollback []RollbackHook
|
||||||
|
}
|
||||||
|
|
||||||
|
// newTx creates a new transactional driver.
|
||||||
|
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||||
|
tx, err := drv.Tx(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &txDriver{tx: tx, drv: drv}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||||
|
// from the internal builders. Should be called only by the internal builders.
|
||||||
|
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||||
|
|
||||||
|
// Dialect returns the dialect of the driver we started the transaction from.
|
||||||
|
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||||
|
|
||||||
|
// Close is a nop close.
|
||||||
|
func (*txDriver) Close() error { return nil }
|
||||||
|
|
||||||
|
// Commit is a nop commit for the internal builders.
|
||||||
|
// User must call `Tx.Commit` in order to commit the transaction.
|
||||||
|
func (*txDriver) Commit() error { return nil }
|
||||||
|
|
||||||
|
// Rollback is a nop rollback for the internal builders.
|
||||||
|
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||||
|
func (*txDriver) Rollback() error { return nil }
|
||||||
|
|
||||||
|
// Exec calls tx.Exec.
|
||||||
|
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Exec(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query calls tx.Query.
|
||||||
|
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Query(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ dialect.Driver = (*txDriver)(nil)
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserVerifications is the models entity for the UserVerifications schema.
|
||||||
|
type UserVerifications struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// UserID holds the value of the "user_id" field.
|
||||||
|
UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// Role holds the value of the "role" field.
|
||||||
|
Role string `json:"role,omitempty"`
|
||||||
|
// Status holds the value of the "status" field.
|
||||||
|
Status string `json:"status,omitempty"`
|
||||||
|
// Materials holds the value of the "materials" field.
|
||||||
|
Materials schema.MaterialStruct `json:"materials,omitempty"`
|
||||||
|
// RejectReason holds the value of the "reject_reason" field.
|
||||||
|
RejectReason string `json:"reject_reason,omitempty"`
|
||||||
|
// ReviewedBy holds the value of the "reviewed_by" field.
|
||||||
|
ReviewedBy int64 `json:"reviewed_by,omitempty"`
|
||||||
|
// ReviewedAt holds the value of the "reviewed_at" field.
|
||||||
|
ReviewedAt time.Time `json:"reviewed_at,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*UserVerifications) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case userverifications.FieldMaterials:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case userverifications.FieldID, userverifications.FieldUserID, userverifications.FieldReviewedBy:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case userverifications.FieldRole, userverifications.FieldStatus, userverifications.FieldRejectReason:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case userverifications.FieldReviewedAt, userverifications.FieldCreatedAt, userverifications.FieldUpdatedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the UserVerifications fields.
|
||||||
|
func (_m *UserVerifications) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case userverifications.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
_m.ID = int64(value.Int64)
|
||||||
|
case userverifications.FieldUserID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UserID = value.Int64
|
||||||
|
}
|
||||||
|
case userverifications.FieldRole:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field role", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Role = value.String
|
||||||
|
}
|
||||||
|
case userverifications.FieldStatus:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Status = value.String
|
||||||
|
}
|
||||||
|
case userverifications.FieldMaterials:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field materials", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.Materials); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field materials: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case userverifications.FieldRejectReason:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field reject_reason", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.RejectReason = value.String
|
||||||
|
}
|
||||||
|
case userverifications.FieldReviewedBy:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field reviewed_by", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ReviewedBy = value.Int64
|
||||||
|
}
|
||||||
|
case userverifications.FieldReviewedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field reviewed_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ReviewedAt = value.Time
|
||||||
|
}
|
||||||
|
case userverifications.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case userverifications.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the UserVerifications.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *UserVerifications) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this UserVerifications.
|
||||||
|
// Note that you need to call UserVerifications.Unwrap() before calling this method if this UserVerifications
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *UserVerifications) Update() *UserVerificationsUpdateOne {
|
||||||
|
return NewUserVerificationsClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the UserVerifications entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (_m *UserVerifications) Unwrap() *UserVerifications {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("models: UserVerifications is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *UserVerifications) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("UserVerifications(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||||
|
builder.WriteString("user_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("role=")
|
||||||
|
builder.WriteString(_m.Role)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("status=")
|
||||||
|
builder.WriteString(_m.Status)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("materials=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Materials))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("reject_reason=")
|
||||||
|
builder.WriteString(_m.RejectReason)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("reviewed_by=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.ReviewedBy))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("reviewed_at=")
|
||||||
|
builder.WriteString(_m.ReviewedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserVerificationsSlice is a parsable slice of UserVerifications.
|
||||||
|
type UserVerificationsSlice []*UserVerifications
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package userverifications
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the userverifications type in the database.
|
||||||
|
Label = "user_verifications"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldUserID holds the string denoting the user_id field in the database.
|
||||||
|
FieldUserID = "user_id"
|
||||||
|
// FieldRole holds the string denoting the role field in the database.
|
||||||
|
FieldRole = "role"
|
||||||
|
// FieldStatus holds the string denoting the status field in the database.
|
||||||
|
FieldStatus = "status"
|
||||||
|
// FieldMaterials holds the string denoting the materials field in the database.
|
||||||
|
FieldMaterials = "materials"
|
||||||
|
// FieldRejectReason holds the string denoting the reject_reason field in the database.
|
||||||
|
FieldRejectReason = "reject_reason"
|
||||||
|
// FieldReviewedBy holds the string denoting the reviewed_by field in the database.
|
||||||
|
FieldReviewedBy = "reviewed_by"
|
||||||
|
// FieldReviewedAt holds the string denoting the reviewed_at field in the database.
|
||||||
|
FieldReviewedAt = "reviewed_at"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// Table holds the table name of the userverifications in the database.
|
||||||
|
Table = "user_verifications"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for userverifications fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldUserID,
|
||||||
|
FieldRole,
|
||||||
|
FieldStatus,
|
||||||
|
FieldMaterials,
|
||||||
|
FieldRejectReason,
|
||||||
|
FieldReviewedBy,
|
||||||
|
FieldReviewedAt,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultStatus holds the default value on creation for the "status" field.
|
||||||
|
DefaultStatus string
|
||||||
|
// DefaultRejectReason holds the default value on creation for the "reject_reason" field.
|
||||||
|
DefaultRejectReason string
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the UserVerifications queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserID orders the results by the user_id field.
|
||||||
|
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByRole orders the results by the role field.
|
||||||
|
func ByRole(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldRole, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByStatus orders the results by the status field.
|
||||||
|
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByRejectReason orders the results by the reject_reason field.
|
||||||
|
func ByRejectReason(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldRejectReason, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByReviewedBy orders the results by the reviewed_by field.
|
||||||
|
func ByReviewedBy(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldReviewedBy, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByReviewedAt orders the results by the reviewed_at field.
|
||||||
|
func ByReviewedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldReviewedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
@@ -0,0 +1,505 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package userverifications
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||||
|
func UserID(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Role applies equality check predicate on the "role" field. It's identical to RoleEQ.
|
||||||
|
func Role(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
|
||||||
|
func Status(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReason applies equality check predicate on the "reject_reason" field. It's identical to RejectReasonEQ.
|
||||||
|
func RejectReason(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedBy applies equality check predicate on the "reviewed_by" field. It's identical to ReviewedByEQ.
|
||||||
|
func ReviewedBy(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldReviewedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAt applies equality check predicate on the "reviewed_at" field. It's identical to ReviewedAtEQ.
|
||||||
|
func ReviewedAt(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldReviewedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||||
|
func UserIDEQ(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||||
|
func UserIDNEQ(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDIn applies the In predicate on the "user_id" field.
|
||||||
|
func UserIDIn(vs ...int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||||
|
func UserIDNotIn(vs ...int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDGT applies the GT predicate on the "user_id" field.
|
||||||
|
func UserIDGT(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDGTE applies the GTE predicate on the "user_id" field.
|
||||||
|
func UserIDGTE(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDLT applies the LT predicate on the "user_id" field.
|
||||||
|
func UserIDLT(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDLTE applies the LTE predicate on the "user_id" field.
|
||||||
|
func UserIDLTE(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleEQ applies the EQ predicate on the "role" field.
|
||||||
|
func RoleEQ(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleNEQ applies the NEQ predicate on the "role" field.
|
||||||
|
func RoleNEQ(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleIn applies the In predicate on the "role" field.
|
||||||
|
func RoleIn(vs ...string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldRole, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleNotIn applies the NotIn predicate on the "role" field.
|
||||||
|
func RoleNotIn(vs ...string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldRole, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleGT applies the GT predicate on the "role" field.
|
||||||
|
func RoleGT(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleGTE applies the GTE predicate on the "role" field.
|
||||||
|
func RoleGTE(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleLT applies the LT predicate on the "role" field.
|
||||||
|
func RoleLT(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleLTE applies the LTE predicate on the "role" field.
|
||||||
|
func RoleLTE(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleContains applies the Contains predicate on the "role" field.
|
||||||
|
func RoleContains(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldContains(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleHasPrefix applies the HasPrefix predicate on the "role" field.
|
||||||
|
func RoleHasPrefix(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldHasPrefix(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleHasSuffix applies the HasSuffix predicate on the "role" field.
|
||||||
|
func RoleHasSuffix(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldHasSuffix(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleEqualFold applies the EqualFold predicate on the "role" field.
|
||||||
|
func RoleEqualFold(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEqualFold(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleContainsFold applies the ContainsFold predicate on the "role" field.
|
||||||
|
func RoleContainsFold(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldContainsFold(FieldRole, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusEQ applies the EQ predicate on the "status" field.
|
||||||
|
func StatusEQ(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||||
|
func StatusNEQ(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusIn applies the In predicate on the "status" field.
|
||||||
|
func StatusIn(vs ...string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldStatus, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||||
|
func StatusNotIn(vs ...string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldStatus, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusGT applies the GT predicate on the "status" field.
|
||||||
|
func StatusGT(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusGTE applies the GTE predicate on the "status" field.
|
||||||
|
func StatusGTE(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusLT applies the LT predicate on the "status" field.
|
||||||
|
func StatusLT(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusLTE applies the LTE predicate on the "status" field.
|
||||||
|
func StatusLTE(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusContains applies the Contains predicate on the "status" field.
|
||||||
|
func StatusContains(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldContains(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
|
||||||
|
func StatusHasPrefix(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldHasPrefix(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
|
||||||
|
func StatusHasSuffix(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldHasSuffix(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusEqualFold applies the EqualFold predicate on the "status" field.
|
||||||
|
func StatusEqualFold(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEqualFold(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
|
||||||
|
func StatusContainsFold(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldContainsFold(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonEQ applies the EQ predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonEQ(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonNEQ applies the NEQ predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonNEQ(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonIn applies the In predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonIn(vs ...string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldRejectReason, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonNotIn applies the NotIn predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonNotIn(vs ...string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldRejectReason, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonGT applies the GT predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonGT(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonGTE applies the GTE predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonGTE(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonLT applies the LT predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonLT(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonLTE applies the LTE predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonLTE(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonContains applies the Contains predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonContains(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldContains(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonHasPrefix applies the HasPrefix predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonHasPrefix(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldHasPrefix(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonHasSuffix applies the HasSuffix predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonHasSuffix(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldHasSuffix(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonEqualFold applies the EqualFold predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonEqualFold(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEqualFold(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RejectReasonContainsFold applies the ContainsFold predicate on the "reject_reason" field.
|
||||||
|
func RejectReasonContainsFold(v string) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldContainsFold(FieldRejectReason, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByEQ applies the EQ predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByEQ(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldReviewedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByNEQ applies the NEQ predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByNEQ(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldReviewedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByIn applies the In predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByIn(vs ...int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldReviewedBy, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByNotIn applies the NotIn predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByNotIn(vs ...int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldReviewedBy, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByGT applies the GT predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByGT(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldReviewedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByGTE applies the GTE predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByGTE(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldReviewedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByLT applies the LT predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByLT(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldReviewedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedByLTE applies the LTE predicate on the "reviewed_by" field.
|
||||||
|
func ReviewedByLTE(v int64) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldReviewedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtEQ applies the EQ predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtEQ(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldReviewedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtNEQ applies the NEQ predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtNEQ(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldReviewedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtIn applies the In predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtIn(vs ...time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldReviewedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtNotIn applies the NotIn predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtNotIn(vs ...time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldReviewedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtGT applies the GT predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtGT(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldReviewedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtGTE applies the GTE predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtGTE(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldReviewedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtLT applies the LT predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtLT(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldReviewedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReviewedAtLTE applies the LTE predicate on the "reviewed_at" field.
|
||||||
|
func ReviewedAtLTE(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldReviewedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.UserVerifications) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.UserVerifications) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.UserVerifications) predicate.UserVerifications {
|
||||||
|
return predicate.UserVerifications(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
@@ -0,0 +1,331 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserVerificationsCreate is the builder for creating a UserVerifications entity.
|
||||||
|
type UserVerificationsCreate struct {
|
||||||
|
config
|
||||||
|
mutation *UserVerificationsMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetUserID(v int64) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetUserID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRole sets the "role" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetRole(v string) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetRole(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetStatus(v string) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetStatus(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (_c *UserVerificationsCreate) SetNillableStatus(v *string) *UserVerificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetStatus(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaterials sets the "materials" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetMaterials(v schema.MaterialStruct) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetMaterials(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRejectReason sets the "reject_reason" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetRejectReason(v string) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetRejectReason(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRejectReason sets the "reject_reason" field if the given value is not nil.
|
||||||
|
func (_c *UserVerificationsCreate) SetNillableRejectReason(v *string) *UserVerificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetRejectReason(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReviewedBy sets the "reviewed_by" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetReviewedBy(v int64) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetReviewedBy(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReviewedAt sets the "reviewed_at" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetReviewedAt(v time.Time) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetReviewedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetCreatedAt(v time.Time) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetUpdatedAt(v time.Time) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (_c *UserVerificationsCreate) SetID(v int64) *UserVerificationsCreate {
|
||||||
|
_c.mutation.SetID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the UserVerificationsMutation object of the builder.
|
||||||
|
func (_c *UserVerificationsCreate) Mutation() *UserVerificationsMutation {
|
||||||
|
return _c.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the UserVerifications in the database.
|
||||||
|
func (_c *UserVerificationsCreate) Save(ctx context.Context) (*UserVerifications, error) {
|
||||||
|
_c.defaults()
|
||||||
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (_c *UserVerificationsCreate) SaveX(ctx context.Context) *UserVerifications {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *UserVerificationsCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *UserVerificationsCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := _c.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_c *UserVerificationsCreate) defaults() {
|
||||||
|
if _, ok := _c.mutation.Status(); !ok {
|
||||||
|
v := userverifications.DefaultStatus
|
||||||
|
_c.mutation.SetStatus(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.RejectReason(); !ok {
|
||||||
|
v := userverifications.DefaultRejectReason
|
||||||
|
_c.mutation.SetRejectReason(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_c *UserVerificationsCreate) check() error {
|
||||||
|
if _, ok := _c.mutation.UserID(); !ok {
|
||||||
|
return &ValidationError{Name: "user_id", err: errors.New(`models: missing required field "UserVerifications.user_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Role(); !ok {
|
||||||
|
return &ValidationError{Name: "role", err: errors.New(`models: missing required field "UserVerifications.role"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Status(); !ok {
|
||||||
|
return &ValidationError{Name: "status", err: errors.New(`models: missing required field "UserVerifications.status"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Materials(); !ok {
|
||||||
|
return &ValidationError{Name: "materials", err: errors.New(`models: missing required field "UserVerifications.materials"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.RejectReason(); !ok {
|
||||||
|
return &ValidationError{Name: "reject_reason", err: errors.New(`models: missing required field "UserVerifications.reject_reason"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.ReviewedBy(); !ok {
|
||||||
|
return &ValidationError{Name: "reviewed_by", err: errors.New(`models: missing required field "UserVerifications.reviewed_by"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.ReviewedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "reviewed_at", err: errors.New(`models: missing required field "UserVerifications.reviewed_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "UserVerifications.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "UserVerifications.updated_at"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *UserVerificationsCreate) sqlSave(ctx context.Context) (*UserVerifications, error) {
|
||||||
|
if err := _c.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := _c.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
_c.mutation.id = &_node.ID
|
||||||
|
_c.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *UserVerificationsCreate) createSpec() (*UserVerifications, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &UserVerifications{config: _c.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(userverifications.Table, sqlgraph.NewFieldSpec(userverifications.FieldID, field.TypeInt64))
|
||||||
|
)
|
||||||
|
if id, ok := _c.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UserID(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldUserID, field.TypeInt64, value)
|
||||||
|
_node.UserID = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Role(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldRole, field.TypeString, value)
|
||||||
|
_node.Role = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Status(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldStatus, field.TypeString, value)
|
||||||
|
_node.Status = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Materials(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldMaterials, field.TypeJSON, value)
|
||||||
|
_node.Materials = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.RejectReason(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
||||||
|
_node.RejectReason = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.ReviewedBy(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
|
_node.ReviewedBy = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.ReviewedAt(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldReviewedAt, field.TypeTime, value)
|
||||||
|
_node.ReviewedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserVerificationsCreateBulk is the builder for creating many UserVerifications entities in bulk.
|
||||||
|
type UserVerificationsCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*UserVerificationsCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the UserVerifications entities in the database.
|
||||||
|
func (_c *UserVerificationsCreateBulk) Save(ctx context.Context) ([]*UserVerifications, error) {
|
||||||
|
if _c.err != nil {
|
||||||
|
return nil, _c.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||||
|
nodes := make([]*UserVerifications, len(_c.builders))
|
||||||
|
mutators := make([]Mutator, len(_c.builders))
|
||||||
|
for i := range _c.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := _c.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*UserVerificationsMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_c *UserVerificationsCreateBulk) SaveX(ctx context.Context) []*UserVerifications {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *UserVerificationsCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *UserVerificationsCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := _c.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/predicate"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserVerificationsDelete is the builder for deleting a UserVerifications entity.
|
||||||
|
type UserVerificationsDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UserVerificationsMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserVerificationsDelete builder.
|
||||||
|
func (_d *UserVerificationsDelete) Where(ps ...predicate.UserVerifications) *UserVerificationsDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *UserVerificationsDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *UserVerificationsDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *UserVerificationsDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(userverifications.Table, sqlgraph.NewFieldSpec(userverifications.FieldID, field.TypeInt64))
|
||||||
|
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
_d.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserVerificationsDeleteOne is the builder for deleting a single UserVerifications entity.
|
||||||
|
type UserVerificationsDeleteOne struct {
|
||||||
|
_d *UserVerificationsDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserVerificationsDelete builder.
|
||||||
|
func (_d *UserVerificationsDeleteOne) Where(ps ...predicate.UserVerifications) *UserVerificationsDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *UserVerificationsDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{userverifications.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *UserVerificationsDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,527 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/predicate"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserVerificationsQuery is the builder for querying UserVerifications entities.
|
||||||
|
type UserVerificationsQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []userverifications.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.UserVerifications
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the UserVerificationsQuery builder.
|
||||||
|
func (_q *UserVerificationsQuery) Where(ps ...predicate.UserVerifications) *UserVerificationsQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *UserVerificationsQuery) Limit(limit int) *UserVerificationsQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *UserVerificationsQuery) Offset(offset int) *UserVerificationsQuery {
|
||||||
|
_q.ctx.Offset = &offset
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (_q *UserVerificationsQuery) Unique(unique bool) *UserVerificationsQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *UserVerificationsQuery) Order(o ...userverifications.OrderOption) *UserVerificationsQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first UserVerifications entity from the query.
|
||||||
|
// Returns a *NotFoundError when no UserVerifications was found.
|
||||||
|
func (_q *UserVerificationsQuery) First(ctx context.Context) (*UserVerifications, error) {
|
||||||
|
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{userverifications.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *UserVerificationsQuery) FirstX(ctx context.Context) *UserVerifications {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first UserVerifications ID from the query.
|
||||||
|
// Returns a *NotFoundError when no UserVerifications ID was found.
|
||||||
|
func (_q *UserVerificationsQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{userverifications.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *UserVerificationsQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single UserVerifications entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one UserVerifications entity is found.
|
||||||
|
// Returns a *NotFoundError when no UserVerifications entities are found.
|
||||||
|
func (_q *UserVerificationsQuery) Only(ctx context.Context) (*UserVerifications, error) {
|
||||||
|
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{userverifications.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{userverifications.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *UserVerificationsQuery) OnlyX(ctx context.Context) *UserVerifications {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only UserVerifications ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one UserVerifications ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *UserVerificationsQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{userverifications.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{userverifications.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *UserVerificationsQuery) OnlyIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of UserVerificationsSlice.
|
||||||
|
func (_q *UserVerificationsQuery) All(ctx context.Context) ([]*UserVerifications, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*UserVerifications, *UserVerificationsQuery]()
|
||||||
|
return withInterceptors[[]*UserVerifications](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *UserVerificationsQuery) AllX(ctx context.Context) []*UserVerifications {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of UserVerifications IDs.
|
||||||
|
func (_q *UserVerificationsQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||||
|
if _q.ctx.Unique == nil && _q.path != nil {
|
||||||
|
_q.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||||
|
if err = _q.Select(userverifications.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *UserVerificationsQuery) IDsX(ctx context.Context) []int64 {
|
||||||
|
ids, err := _q.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (_q *UserVerificationsQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, _q, querierCount[*UserVerificationsQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *UserVerificationsQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := _q.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (_q *UserVerificationsQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := _q.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("models: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (_q *UserVerificationsQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the UserVerificationsQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (_q *UserVerificationsQuery) Clone() *UserVerificationsQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &UserVerificationsQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]userverifications.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.UserVerifications{}, _q.predicates...),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.UserVerifications.Query().
|
||||||
|
// GroupBy(userverifications.FieldUserID).
|
||||||
|
// Aggregate(models.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *UserVerificationsQuery) GroupBy(field string, fields ...string) *UserVerificationsGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &UserVerificationsGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = userverifications.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.UserVerifications.Query().
|
||||||
|
// Select(userverifications.FieldUserID).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *UserVerificationsQuery) Select(fields ...string) *UserVerificationsSelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &UserVerificationsSelect{UserVerificationsQuery: _q}
|
||||||
|
sbuild.label = userverifications.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a UserVerificationsSelect configured with the given aggregations.
|
||||||
|
func (_q *UserVerificationsQuery) Aggregate(fns ...AggregateFunc) *UserVerificationsSelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UserVerificationsQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range _q.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("models: uninitialized interceptor (forgotten import models/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, _q); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range _q.ctx.Fields {
|
||||||
|
if !userverifications.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.path != nil {
|
||||||
|
prev, err := _q.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_q.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UserVerificationsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*UserVerifications, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*UserVerifications{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*UserVerifications).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &UserVerifications{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UserVerificationsQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := _q.querySpec()
|
||||||
|
_spec.Node.Columns = _q.ctx.Fields
|
||||||
|
if len(_q.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UserVerificationsQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(userverifications.Table, userverifications.Columns, sqlgraph.NewFieldSpec(userverifications.FieldID, field.TypeInt64))
|
||||||
|
_spec.From = _q.sql
|
||||||
|
if unique := _q.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if _q.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, userverifications.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != userverifications.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _q.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := _q.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UserVerificationsQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(userverifications.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = userverifications.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if _q.sql != nil {
|
||||||
|
selector = _q.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range _q.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range _q.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserVerificationsGroupBy is the group-by builder for UserVerifications entities.
|
||||||
|
type UserVerificationsGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *UserVerificationsQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *UserVerificationsGroupBy) Aggregate(fns ...AggregateFunc) *UserVerificationsGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *UserVerificationsGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*UserVerificationsQuery, *UserVerificationsGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *UserVerificationsGroupBy) sqlScan(ctx context.Context, root *UserVerificationsQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(_g.fns))
|
||||||
|
for _, fn := range _g.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||||
|
for _, f := range *_g.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserVerificationsSelect is the builder for selecting fields of UserVerifications entities.
|
||||||
|
type UserVerificationsSelect struct {
|
||||||
|
*UserVerificationsQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *UserVerificationsSelect) Aggregate(fns ...AggregateFunc) *UserVerificationsSelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *UserVerificationsSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||||
|
if err := _s.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*UserVerificationsQuery, *UserVerificationsSelect](ctx, _s.UserVerificationsQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *UserVerificationsSelect) sqlScan(ctx context.Context, root *UserVerificationsQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(_s.fns))
|
||||||
|
for _, fn := range _s.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*_s.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
@@ -0,0 +1,366 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/predicate"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models/userverifications"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserVerificationsUpdate is the builder for updating UserVerifications entities.
|
||||||
|
type UserVerificationsUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UserVerificationsMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserVerificationsUpdate builder.
|
||||||
|
func (_u *UserVerificationsUpdate) Where(ps ...predicate.UserVerifications) *UserVerificationsUpdate {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRole sets the "role" field.
|
||||||
|
func (_u *UserVerificationsUpdate) SetRole(v string) *UserVerificationsUpdate {
|
||||||
|
_u.mutation.SetRole(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRole sets the "role" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdate) SetNillableRole(v *string) *UserVerificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetRole(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (_u *UserVerificationsUpdate) SetStatus(v string) *UserVerificationsUpdate {
|
||||||
|
_u.mutation.SetStatus(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdate) SetNillableStatus(v *string) *UserVerificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetStatus(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaterials sets the "materials" field.
|
||||||
|
func (_u *UserVerificationsUpdate) SetMaterials(v schema.MaterialStruct) *UserVerificationsUpdate {
|
||||||
|
_u.mutation.SetMaterials(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableMaterials sets the "materials" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdate) SetNillableMaterials(v *schema.MaterialStruct) *UserVerificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetMaterials(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRejectReason sets the "reject_reason" field.
|
||||||
|
func (_u *UserVerificationsUpdate) SetRejectReason(v string) *UserVerificationsUpdate {
|
||||||
|
_u.mutation.SetRejectReason(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRejectReason sets the "reject_reason" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdate) SetNillableRejectReason(v *string) *UserVerificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetRejectReason(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReviewedBy sets the "reviewed_by" field.
|
||||||
|
func (_u *UserVerificationsUpdate) SetReviewedBy(v int64) *UserVerificationsUpdate {
|
||||||
|
_u.mutation.ResetReviewedBy()
|
||||||
|
_u.mutation.SetReviewedBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableReviewedBy sets the "reviewed_by" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdate) SetNillableReviewedBy(v *int64) *UserVerificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetReviewedBy(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddReviewedBy adds value to the "reviewed_by" field.
|
||||||
|
func (_u *UserVerificationsUpdate) AddReviewedBy(v int64) *UserVerificationsUpdate {
|
||||||
|
_u.mutation.AddReviewedBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the UserVerificationsMutation object of the builder.
|
||||||
|
func (_u *UserVerificationsUpdate) Mutation() *UserVerificationsMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *UserVerificationsUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *UserVerificationsUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *UserVerificationsUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *UserVerificationsUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *UserVerificationsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(userverifications.Table, userverifications.Columns, sqlgraph.NewFieldSpec(userverifications.FieldID, field.TypeInt64))
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Role(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldRole, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Status(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldStatus, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Materials(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldMaterials, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.RejectReason(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ReviewedBy(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedReviewedBy(); ok {
|
||||||
|
_spec.AddField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{userverifications.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserVerificationsUpdateOne is the builder for updating a single UserVerifications entity.
|
||||||
|
type UserVerificationsUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UserVerificationsMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRole sets the "role" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetRole(v string) *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.SetRole(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRole sets the "role" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetNillableRole(v *string) *UserVerificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetRole(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetStatus(v string) *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.SetStatus(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetNillableStatus(v *string) *UserVerificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetStatus(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaterials sets the "materials" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetMaterials(v schema.MaterialStruct) *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.SetMaterials(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableMaterials sets the "materials" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetNillableMaterials(v *schema.MaterialStruct) *UserVerificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetMaterials(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRejectReason sets the "reject_reason" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetRejectReason(v string) *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.SetRejectReason(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRejectReason sets the "reject_reason" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetNillableRejectReason(v *string) *UserVerificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetRejectReason(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReviewedBy sets the "reviewed_by" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetReviewedBy(v int64) *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.ResetReviewedBy()
|
||||||
|
_u.mutation.SetReviewedBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableReviewedBy sets the "reviewed_by" field if the given value is not nil.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SetNillableReviewedBy(v *int64) *UserVerificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetReviewedBy(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddReviewedBy adds value to the "reviewed_by" field.
|
||||||
|
func (_u *UserVerificationsUpdateOne) AddReviewedBy(v int64) *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.AddReviewedBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the UserVerificationsMutation object of the builder.
|
||||||
|
func (_u *UserVerificationsUpdateOne) Mutation() *UserVerificationsMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserVerificationsUpdate builder.
|
||||||
|
func (_u *UserVerificationsUpdateOne) Where(ps ...predicate.UserVerifications) *UserVerificationsUpdateOne {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (_u *UserVerificationsUpdateOne) Select(field string, fields ...string) *UserVerificationsUpdateOne {
|
||||||
|
_u.fields = append([]string{field}, fields...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated UserVerifications entity.
|
||||||
|
func (_u *UserVerificationsUpdateOne) Save(ctx context.Context) (*UserVerifications, error) {
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *UserVerificationsUpdateOne) SaveX(ctx context.Context) *UserVerifications {
|
||||||
|
node, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *UserVerificationsUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *UserVerificationsUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *UserVerificationsUpdateOne) sqlSave(ctx context.Context) (_node *UserVerifications, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(userverifications.Table, userverifications.Columns, sqlgraph.NewFieldSpec(userverifications.FieldID, field.TypeInt64))
|
||||||
|
id, ok := _u.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "UserVerifications.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := _u.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, userverifications.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !userverifications.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != userverifications.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Role(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldRole, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Status(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldStatus, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Materials(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldMaterials, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.RejectReason(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldRejectReason, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ReviewedBy(); ok {
|
||||||
|
_spec.SetField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedReviewedBy(); ok {
|
||||||
|
_spec.AddField(userverifications.FieldReviewedBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
_node = &UserVerifications{config: _u.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{userverifications.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@@ -1,13 +1,55 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import "juwan-backend/app/user_verifications/rpc/internal/config"
|
import (
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/config"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/internal/models"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/userverifications"
|
||||||
|
"juwan-backend/common/redisx"
|
||||||
|
"juwan-backend/common/snowflakex"
|
||||||
|
"juwan-backend/pkg/adapter"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"ariga.io/entcache"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
|
UserVeriModelRW *models.UserVerificationsClient
|
||||||
|
UserVeriModelRO *models.UserVerificationsClient
|
||||||
|
RedisClient *redis.ClusterClient
|
||||||
|
UserVeriRpc userverifications.UserVerificationsZrpcClient
|
||||||
|
SnowflakeRpc snowflake.SnowflakeServiceClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
RWConn, err := sql.Open("pgx", c.DB.Master)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
ROConn, err := sql.Open("pgx", c.DB.Slave)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
redisConn, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||||
|
if err != nil || redisConn == nil {
|
||||||
|
logx.Errorf("redis connect master error: %s", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
RWDrv := entcache.NewDriver(RWConn, entcache.TTL(time.Second*30), entcache.Levels(adapter.NewRedisCache(redisConn.Client)))
|
||||||
|
RODrv := entcache.NewDriver(ROConn, entcache.TTL(time.Second*30), entcache.Levels(adapter.NewRedisCache(redisConn.Client)))
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
UserVeriModelRW: models.NewClient(models.Driver(RWDrv)).UserVerifications,
|
||||||
|
UserVeriModelRO: models.NewClient(models.Driver(RODrv)).UserVerifications,
|
||||||
|
RedisClient: redisConn.Client,
|
||||||
|
UserVeriRpc: userverifications.NewUserVerificationsZrpcClient(zrpc.MustNewClient(c.UserVeriRpcConf)),
|
||||||
|
SnowflakeRpc: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package svc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ UserVerificationsModel = (*customUserVerificationsModel)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// UserVerificationsModel is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in customUserVerificationsModel.
|
|
||||||
UserVerificationsModel interface {
|
|
||||||
userVerificationsModel
|
|
||||||
}
|
|
||||||
|
|
||||||
customUserVerificationsModel struct {
|
|
||||||
*defaultUserVerificationsModel
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewUserVerificationsModel returns a model for the database table.
|
|
||||||
func NewUserVerificationsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) UserVerificationsModel {
|
|
||||||
return &customUserVerificationsModel{
|
|
||||||
defaultUserVerificationsModel: newUserVerificationsModel(conn, c, opts...),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
// versions:
|
|
||||||
// goctl version: 1.9.2
|
|
||||||
|
|
||||||
package svc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
userVerificationsFieldNames = builder.RawFieldNames(&UserVerifications{}, true)
|
|
||||||
userVerificationsRows = strings.Join(userVerificationsFieldNames, ",")
|
|
||||||
userVerificationsRowsExpectAutoSet = strings.Join(stringx.Remove(userVerificationsFieldNames, "create_at", "create_time", "created_at", "update_at", "update_time", "updated_at"), ",")
|
|
||||||
userVerificationsRowsWithPlaceHolder = builder.PostgreSqlJoin(stringx.Remove(userVerificationsFieldNames, "id", "create_at", "create_time", "created_at", "update_at", "update_time", "updated_at"))
|
|
||||||
|
|
||||||
cachePublicUserVerificationsIdPrefix = "cache:public:userVerifications:id:"
|
|
||||||
cachePublicUserVerificationsUserIdRolePrefix = "cache:public:userVerifications:userId:role:"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
userVerificationsModel interface {
|
|
||||||
Insert(ctx context.Context, data *UserVerifications) (sql.Result, error)
|
|
||||||
FindOne(ctx context.Context, id int64) (*UserVerifications, error)
|
|
||||||
FindOneByUserIdRole(ctx context.Context, userId int64, role string) (*UserVerifications, error)
|
|
||||||
Update(ctx context.Context, data *UserVerifications) error
|
|
||||||
Delete(ctx context.Context, id int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultUserVerificationsModel struct {
|
|
||||||
sqlc.CachedConn
|
|
||||||
table string
|
|
||||||
}
|
|
||||||
|
|
||||||
UserVerifications struct {
|
|
||||||
Id int64 `db:"id"`
|
|
||||||
UserId int64 `db:"user_id"`
|
|
||||||
Role string `db:"role"`
|
|
||||||
Status string `db:"status"`
|
|
||||||
Materials string `db:"materials"`
|
|
||||||
RejectReason sql.NullString `db:"reject_reason"`
|
|
||||||
ReviewedBy sql.NullInt64 `db:"reviewed_by"`
|
|
||||||
ReviewedAt sql.NullTime `db:"reviewed_at"`
|
|
||||||
CreatedAt time.Time `db:"created_at"`
|
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func newUserVerificationsModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultUserVerificationsModel {
|
|
||||||
return &defaultUserVerificationsModel{
|
|
||||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
|
||||||
table: `"public"."user_verifications"`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultUserVerificationsModel) Delete(ctx context.Context, id int64) error {
|
|
||||||
data, err := m.FindOne(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
publicUserVerificationsIdKey := fmt.Sprintf("%s%v", cachePublicUserVerificationsIdPrefix, id)
|
|
||||||
publicUserVerificationsUserIdRoleKey := fmt.Sprintf("%s%v:%v", cachePublicUserVerificationsUserIdRolePrefix, data.UserId, data.Role)
|
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("delete from %s where id = $1", m.table)
|
|
||||||
return conn.ExecCtx(ctx, query, id)
|
|
||||||
}, publicUserVerificationsIdKey, publicUserVerificationsUserIdRoleKey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultUserVerificationsModel) FindOne(ctx context.Context, id int64) (*UserVerifications, error) {
|
|
||||||
publicUserVerificationsIdKey := fmt.Sprintf("%s%v", cachePublicUserVerificationsIdPrefix, id)
|
|
||||||
var resp UserVerifications
|
|
||||||
err := m.QueryRowCtx(ctx, &resp, publicUserVerificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
|
||||||
query := fmt.Sprintf("select %s from %s where id = $1 limit 1", userVerificationsRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, id)
|
|
||||||
})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultUserVerificationsModel) FindOneByUserIdRole(ctx context.Context, userId int64, role string) (*UserVerifications, error) {
|
|
||||||
publicUserVerificationsUserIdRoleKey := fmt.Sprintf("%s%v:%v", cachePublicUserVerificationsUserIdRolePrefix, userId, role)
|
|
||||||
var resp UserVerifications
|
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, publicUserVerificationsUserIdRoleKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
|
||||||
query := fmt.Sprintf("select %s from %s where user_id = $1 and role = $2 limit 1", userVerificationsRows, m.table)
|
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, userId, role); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Id, nil
|
|
||||||
}, m.queryPrimary)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultUserVerificationsModel) Insert(ctx context.Context, data *UserVerifications) (sql.Result, error) {
|
|
||||||
publicUserVerificationsIdKey := fmt.Sprintf("%s%v", cachePublicUserVerificationsIdPrefix, data.Id)
|
|
||||||
publicUserVerificationsUserIdRoleKey := fmt.Sprintf("%s%v:%v", cachePublicUserVerificationsUserIdRolePrefix, data.UserId, data.Role)
|
|
||||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("insert into %s (%s) values ($1, $2, $3, $4, $5, $6, $7, $8)", m.table, userVerificationsRowsExpectAutoSet)
|
|
||||||
return conn.ExecCtx(ctx, query, data.Id, data.UserId, data.Role, data.Status, data.Materials, data.RejectReason, data.ReviewedBy, data.ReviewedAt)
|
|
||||||
}, publicUserVerificationsIdKey, publicUserVerificationsUserIdRoleKey)
|
|
||||||
return ret, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultUserVerificationsModel) Update(ctx context.Context, newData *UserVerifications) error {
|
|
||||||
data, err := m.FindOne(ctx, newData.Id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
publicUserVerificationsIdKey := fmt.Sprintf("%s%v", cachePublicUserVerificationsIdPrefix, data.Id)
|
|
||||||
publicUserVerificationsUserIdRoleKey := fmt.Sprintf("%s%v:%v", cachePublicUserVerificationsUserIdRolePrefix, data.UserId, data.Role)
|
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("update %s set %s where id = $1", m.table, userVerificationsRowsWithPlaceHolder)
|
|
||||||
return conn.ExecCtx(ctx, query, newData.Id, newData.UserId, newData.Role, newData.Status, newData.Materials, newData.RejectReason, newData.ReviewedBy, newData.ReviewedAt)
|
|
||||||
}, publicUserVerificationsIdKey, publicUserVerificationsUserIdRoleKey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultUserVerificationsModel) formatPrimary(primary any) string {
|
|
||||||
return fmt.Sprintf("%s%v", cachePublicUserVerificationsIdPrefix, primary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultUserVerificationsModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
|
||||||
query := fmt.Sprintf("select %s from %s where id = $1 limit 1", userVerificationsRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultUserVerificationsModel) tableName() string {
|
|
||||||
return m.table
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package svc
|
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
|
|
||||||
var ErrNotFound = sqlx.ErrNotFound
|
|
||||||
@@ -22,7 +22,7 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c, conf.UseEnv())
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|
||||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.11
|
// protoc-gen-go v1.36.11
|
||||||
// protoc v5.29.6
|
// protoc v3.19.4
|
||||||
// source: user_verifications.proto
|
// source: user_verifications.proto
|
||||||
|
|
||||||
package pb
|
package pb
|
||||||
@@ -285,11 +285,11 @@ func (*AddUserVerificationsResp) Descriptor() ([]byte, []int) {
|
|||||||
type UpdateUserVerificationsReq struct {
|
type UpdateUserVerificationsReq struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||||
UserId int64 `protobuf:"varint,2,opt,name=userId,proto3" json:"userId,omitempty"` //userId
|
UserId *int64 `protobuf:"varint,2,opt,name=userId,proto3,oneof" json:"userId,omitempty"` //userId
|
||||||
Role string `protobuf:"bytes,3,opt,name=role,proto3" json:"role,omitempty"` //role
|
Role *string `protobuf:"bytes,3,opt,name=role,proto3,oneof" json:"role,omitempty"` //role
|
||||||
Status string `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"` //status
|
Status *string `protobuf:"bytes,4,opt,name=status,proto3,oneof" json:"status,omitempty"` //status
|
||||||
Materials string `protobuf:"bytes,5,opt,name=materials,proto3" json:"materials,omitempty"` //materials
|
Materials *string `protobuf:"bytes,5,opt,name=materials,proto3,oneof" json:"materials,omitempty"` //materials
|
||||||
RejectReason string `protobuf:"bytes,6,opt,name=rejectReason,proto3" json:"rejectReason,omitempty"` //rejectReason
|
RejectReason *string `protobuf:"bytes,6,opt,name=rejectReason,proto3,oneof" json:"rejectReason,omitempty"` //rejectReason
|
||||||
ReviewedBy int64 `protobuf:"varint,7,opt,name=reviewedBy,proto3" json:"reviewedBy,omitempty"` //reviewedBy
|
ReviewedBy int64 `protobuf:"varint,7,opt,name=reviewedBy,proto3" json:"reviewedBy,omitempty"` //reviewedBy
|
||||||
ReviewedAt int64 `protobuf:"varint,8,opt,name=reviewedAt,proto3" json:"reviewedAt,omitempty"` //reviewedAt
|
ReviewedAt int64 `protobuf:"varint,8,opt,name=reviewedAt,proto3" json:"reviewedAt,omitempty"` //reviewedAt
|
||||||
CreatedAt int64 `protobuf:"varint,9,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
CreatedAt int64 `protobuf:"varint,9,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
|
||||||
@@ -336,36 +336,36 @@ func (x *UpdateUserVerificationsReq) GetId() int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *UpdateUserVerificationsReq) GetUserId() int64 {
|
func (x *UpdateUserVerificationsReq) GetUserId() int64 {
|
||||||
if x != nil {
|
if x != nil && x.UserId != nil {
|
||||||
return x.UserId
|
return *x.UserId
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *UpdateUserVerificationsReq) GetRole() string {
|
func (x *UpdateUserVerificationsReq) GetRole() string {
|
||||||
if x != nil {
|
if x != nil && x.Role != nil {
|
||||||
return x.Role
|
return *x.Role
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *UpdateUserVerificationsReq) GetStatus() string {
|
func (x *UpdateUserVerificationsReq) GetStatus() string {
|
||||||
if x != nil {
|
if x != nil && x.Status != nil {
|
||||||
return x.Status
|
return *x.Status
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *UpdateUserVerificationsReq) GetMaterials() string {
|
func (x *UpdateUserVerificationsReq) GetMaterials() string {
|
||||||
if x != nil {
|
if x != nil && x.Materials != nil {
|
||||||
return x.Materials
|
return *x.Materials
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *UpdateUserVerificationsReq) GetRejectReason() string {
|
func (x *UpdateUserVerificationsReq) GetRejectReason() string {
|
||||||
if x != nil {
|
if x != nil && x.RejectReason != nil {
|
||||||
return x.RejectReason
|
return *x.RejectReason
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -813,14 +813,14 @@ const file_user_verifications_proto_rawDesc = "" +
|
|||||||
"reviewedAt\x12\x1c\n" +
|
"reviewedAt\x12\x1c\n" +
|
||||||
"\tcreatedAt\x18\b \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
"\tcreatedAt\x18\b \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
"\tupdatedAt\x18\t \x01(\x03R\tupdatedAt\"\x1a\n" +
|
"\tupdatedAt\x18\t \x01(\x03R\tupdatedAt\"\x1a\n" +
|
||||||
"\x18AddUserVerificationsResp\"\xae\x02\n" +
|
"\x18AddUserVerificationsResp\"\x85\x03\n" +
|
||||||
"\x1aUpdateUserVerificationsReq\x12\x0e\n" +
|
"\x1aUpdateUserVerificationsReq\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" +
|
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x1b\n" +
|
||||||
"\x06userId\x18\x02 \x01(\x03R\x06userId\x12\x12\n" +
|
"\x06userId\x18\x02 \x01(\x03H\x00R\x06userId\x88\x01\x01\x12\x17\n" +
|
||||||
"\x04role\x18\x03 \x01(\tR\x04role\x12\x16\n" +
|
"\x04role\x18\x03 \x01(\tH\x01R\x04role\x88\x01\x01\x12\x1b\n" +
|
||||||
"\x06status\x18\x04 \x01(\tR\x06status\x12\x1c\n" +
|
"\x06status\x18\x04 \x01(\tH\x02R\x06status\x88\x01\x01\x12!\n" +
|
||||||
"\tmaterials\x18\x05 \x01(\tR\tmaterials\x12\"\n" +
|
"\tmaterials\x18\x05 \x01(\tH\x03R\tmaterials\x88\x01\x01\x12'\n" +
|
||||||
"\frejectReason\x18\x06 \x01(\tR\frejectReason\x12\x1e\n" +
|
"\frejectReason\x18\x06 \x01(\tH\x04R\frejectReason\x88\x01\x01\x12\x1e\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"reviewedBy\x18\a \x01(\x03R\n" +
|
"reviewedBy\x18\a \x01(\x03R\n" +
|
||||||
"reviewedBy\x12\x1e\n" +
|
"reviewedBy\x12\x1e\n" +
|
||||||
@@ -829,7 +829,13 @@ const file_user_verifications_proto_rawDesc = "" +
|
|||||||
"reviewedAt\x12\x1c\n" +
|
"reviewedAt\x12\x1c\n" +
|
||||||
"\tcreatedAt\x18\t \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
"\tcreatedAt\x18\t \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
"\tupdatedAt\x18\n" +
|
"\tupdatedAt\x18\n" +
|
||||||
" \x01(\x03R\tupdatedAt\"\x1d\n" +
|
" \x01(\x03R\tupdatedAtB\t\n" +
|
||||||
|
"\a_userIdB\a\n" +
|
||||||
|
"\x05_roleB\t\n" +
|
||||||
|
"\a_statusB\f\n" +
|
||||||
|
"\n" +
|
||||||
|
"_materialsB\x0f\n" +
|
||||||
|
"\r_rejectReason\"\x1d\n" +
|
||||||
"\x1bUpdateUserVerificationsResp\")\n" +
|
"\x1bUpdateUserVerificationsResp\")\n" +
|
||||||
"\x17DelUserVerificationsReq\x12\x0e\n" +
|
"\x17DelUserVerificationsReq\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\x03R\x02id\"\x1a\n" +
|
"\x02id\x18\x01 \x01(\x03R\x02id\"\x1a\n" +
|
||||||
@@ -916,6 +922,7 @@ func file_user_verifications_proto_init() {
|
|||||||
if File_user_verifications_proto != nil {
|
if File_user_verifications_proto != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
file_user_verifications_proto_msgTypes[3].OneofWrappers = []any{}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
File: protoimpl.DescBuilder{
|
File: protoimpl.DescBuilder{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.1
|
// - protoc-gen-go-grpc v1.6.1
|
||||||
// - protoc v5.29.6
|
// - protoc v3.19.4
|
||||||
// source: user_verifications.proto
|
// source: user_verifications.proto
|
||||||
|
|
||||||
package pb
|
package pb
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ Prometheus:
|
|||||||
Port: 4001
|
Port: 4001
|
||||||
Path: /metrics
|
Path: /metrics
|
||||||
|
|
||||||
UsercenterRpcConf:
|
|
||||||
Target: k8s://juwan/user-rpc-svc:9001
|
|
||||||
|
|
||||||
SnowflakeRpcConf:
|
SnowflakeRpcConf:
|
||||||
Target: k8s://juwan/snowflake-svc:8080
|
Target: k8s://juwan/snowflake-svc:8080
|
||||||
|
|
||||||
|
UserVerificationRpc:
|
||||||
|
Target: k8s://juwan/user_verifications-svc:8080
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
UsercenterRpcConf zrpc.RpcClientConf
|
UsercenterRpcConf zrpc.RpcClientConf
|
||||||
SnowflakeRpcConf zrpc.RpcClientConf
|
UserVerificationRpc zrpc.RpcClientConf
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/auth"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 忘记密码-发送验证码
|
||||||
|
func ForgotPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.ForgotPasswordReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := auth.NewForgotPasswordLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ForgotPassword(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-10
@@ -1,19 +1,19 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
|
|
||||||
package user
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"juwan-backend/app/users/api/internal/logic/user"
|
"net/http"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/logic/auth"
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
"juwan-backend/common/utils"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 用户登录接口
|
// 用户登录
|
||||||
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.LoginReq
|
var req types.LoginReq
|
||||||
@@ -22,14 +22,13 @@ func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewLoginLogic(r.Context(), svcCtx)
|
l := auth.NewLoginLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.Login(&req)
|
resp, err := l.Login(&req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, utils.NewErrorResp(400, err))
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
} else {
|
} else {
|
||||||
token := resp.Token
|
token := resp.RefreshToken
|
||||||
resp.Token = ""
|
resp.RefreshToken = ""
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "JToken",
|
Name: "JToken",
|
||||||
Value: token,
|
Value: token,
|
||||||
+7
-5
@@ -1,18 +1,19 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
|
|
||||||
package user
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"juwan-backend/app/users/api/internal/logic/auth"
|
||||||
"juwan-backend/app/users/api/internal/logic/user"
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 用户登出
|
// 退出登录
|
||||||
func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.LogoutReq
|
var req types.LogoutReq
|
||||||
@@ -21,7 +22,8 @@ func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewLogoutLogic(r.Context(), svcCtx)
|
// TODO: add userId from http header x-auth-user-id
|
||||||
|
l := auth.NewLogoutLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.Logout(&req)
|
resp, err := l.Logout(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/logic/auth"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 用户注册
|
||||||
|
func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.RegisterReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := auth.NewRegisterLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.Register(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
token := resp.RefreshToken
|
||||||
|
resp.RefreshToken = ""
|
||||||
|
http.SetCookie(w, &http.Cookie{
|
||||||
|
Name: "JToken",
|
||||||
|
Value: token,
|
||||||
|
Quoted: false,
|
||||||
|
Path: "/",
|
||||||
|
Domain: "",
|
||||||
|
RawExpires: "",
|
||||||
|
MaxAge: 691200,
|
||||||
|
Secure: false,
|
||||||
|
HttpOnly: true,
|
||||||
|
SameSite: http.SameSiteStrictMode,
|
||||||
|
Partitioned: false,
|
||||||
|
})
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/auth"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 重置密码
|
||||||
|
func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.ResetPasswordReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := auth.NewResetPasswordLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ResetPassword(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,10 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
auth "juwan-backend/app/users/api/internal/handler/auth"
|
||||||
user "juwan-backend/app/users/api/internal/handler/user"
|
user "juwan-backend/app/users/api/internal/handler/user"
|
||||||
|
verification_admin "juwan-backend/app/users/api/internal/handler/verification_admin"
|
||||||
|
verification_user "juwan-backend/app/users/api/internal/handler/verification_user"
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
@@ -14,41 +17,44 @@ import (
|
|||||||
|
|
||||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
rest.WithMiddlewares(
|
|
||||||
[]rest.Middleware{serverCtx.Logger},
|
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
// 用户登出
|
// 忘记密码-发送验证码
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/:userId/logout",
|
Path: "/forgot-password",
|
||||||
Handler: user.LogoutHandler(serverCtx),
|
Handler: auth.ForgotPasswordHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// 修改用户密码
|
// 用户登录
|
||||||
Method: http.MethodPut,
|
|
||||||
Path: "/:userId/password",
|
|
||||||
Handler: user.UpdatePasswordHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// 修改密码-使用验证码
|
|
||||||
Method: http.MethodPut,
|
|
||||||
Path: "/forgot-password/reset",
|
|
||||||
Handler: user.UpdatePasswordByVcodeHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// 用户登录接口
|
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/login",
|
Path: "/login",
|
||||||
Handler: user.LoginHandler(serverCtx),
|
Handler: auth.LoginHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// 用户注册接口
|
// 用户注册
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/register",
|
Path: "/register",
|
||||||
Handler: user.RegisterHandler(serverCtx),
|
Handler: auth.RegisterHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 重置密码
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/reset-password",
|
||||||
|
Handler: auth.ResetPasswordHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rest.WithPrefix("/api/v1/auth"),
|
||||||
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 退出登录
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/logout",
|
||||||
|
Handler: auth.LogoutHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}...,
|
|
||||||
),
|
|
||||||
rest.WithPrefix("/api/v1/auth"),
|
rest.WithPrefix("/api/v1/auth"),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,16 +63,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
[]rest.Middleware{serverCtx.Logger},
|
[]rest.Middleware{serverCtx.Logger},
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
// 获取用户信息
|
// 关注用户
|
||||||
Method: http.MethodGet,
|
Method: http.MethodPost,
|
||||||
Path: "/:userId",
|
Path: "/:id/follow",
|
||||||
Handler: user.GetUserInfoHandler(serverCtx),
|
Handler: user.FollowUserHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// 修改用户信息
|
// 取消关注用户
|
||||||
Method: http.MethodPut,
|
Method: http.MethodDelete,
|
||||||
Path: "/:userId",
|
Path: "/:id/follow",
|
||||||
Handler: user.UpdateUserInfoHandler(serverCtx),
|
Handler: user.UnfollowUserHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// 获取当前登录用户信息
|
// 获取当前登录用户信息
|
||||||
@@ -75,13 +81,88 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Handler: user.GetMeHandler(serverCtx),
|
Handler: user.GetMeHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// 更改当前登录用户信息
|
// 更新个人资料
|
||||||
Method: http.MethodPut,
|
Method: http.MethodPut,
|
||||||
Path: "/me",
|
Path: "/me",
|
||||||
Handler: user.UpdateMeHandler(serverCtx),
|
Handler: user.UpdateMeHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// 更新通知偏好
|
||||||
|
Method: http.MethodPut,
|
||||||
|
Path: "/me/preferences/notifications",
|
||||||
|
Handler: user.UpdateNotificationSettingsHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 更新主题偏好
|
||||||
|
Method: http.MethodPut,
|
||||||
|
Path: "/me/preferences/theme",
|
||||||
|
Handler: user.UpdateThemeSettingsHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 切换当前激活角色
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/me/switch-role",
|
||||||
|
Handler: user.SwitchRoleHandler(serverCtx),
|
||||||
|
},
|
||||||
}...,
|
}...,
|
||||||
),
|
),
|
||||||
rest.WithPrefix("/api/v1/user"),
|
rest.WithPrefix("/api/v1/users"),
|
||||||
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 获取指定用户信息
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/:id",
|
||||||
|
Handler: user.GetUserInfoHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rest.WithPrefix("/api/v1/users"),
|
||||||
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 管理员获取认证申请列表 (分页)
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/verifications",
|
||||||
|
Handler: verification_admin.GetVerificationsHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 管理员通过申请
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/verifications/:id/approve",
|
||||||
|
Handler: verification_admin.ApproveVerificationHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 管理员驳回申请
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/verifications/:id/reject",
|
||||||
|
Handler: verification_admin.RejectVerificationHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rest.WithPrefix("/api/v1/admin"),
|
||||||
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
rest.WithMiddlewares(
|
||||||
|
[]rest.Middleware{serverCtx.Logger},
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
// 提交或修改角色认证申请 (支持幂等更新)
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/me/verification",
|
||||||
|
Handler: verification_user.ApplyVerificationHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 获取我的所有认证状态
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/me/verification",
|
||||||
|
Handler: verification_user.GetMyVerificationsHandler(serverCtx),
|
||||||
|
},
|
||||||
|
}...,
|
||||||
|
),
|
||||||
|
rest.WithPrefix("/api/v1/users"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -12,17 +12,17 @@ import (
|
|||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 修改用户密码
|
// 关注用户
|
||||||
func UpdatePasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func FollowUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdatePasswordReq
|
var req types.FollowUserReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewUpdatePasswordLogic(r.Context(), svcCtx)
|
l := user.NewFollowUserLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.UpdatePassword(&req)
|
resp, err := l.FollowUser(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
} else {
|
} else {
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
|
||||||
// goctl 1.9.2
|
|
||||||
|
|
||||||
package user
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"juwan-backend/app/users/api/internal/contextx"
|
|
||||||
"juwan-backend/common/utils"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/logic/user"
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
|
||||||
"juwan-backend/app/users/api/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 用户注册接口
|
|
||||||
func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if err := normalizeRegisterBody(r); err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req types.RegisterReq
|
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
requestId := r.Header.Get("X-Request-ID")
|
|
||||||
//regCtx := context.WithValue(r.Context(), "request_id", requestId)
|
|
||||||
regCtx := contextx.WithRequestId(r.Context(), requestId)
|
|
||||||
if requestId == "" {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, errors.New("bad request"))
|
|
||||||
}
|
|
||||||
|
|
||||||
l := user.NewRegisterLogic(regCtx, svcCtx)
|
|
||||||
resp, err := l.Register(&req)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
httpx.ErrorCtx(r.Context(), w, utils.NewErrorResp(400, err))
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func normalizeRegisterBody(r *http.Request) error {
|
|
||||||
body, err := io.ReadAll(r.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer r.Body.Close()
|
|
||||||
|
|
||||||
if len(body) == 0 {
|
|
||||||
r.Body = io.NopCloser(bytes.NewReader(body))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var payload map[string]any
|
|
||||||
if err := json.Unmarshal(body, &payload); err != nil {
|
|
||||||
r.Body = io.NopCloser(bytes.NewReader(body))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
vcode, exists := payload["vcode"]
|
|
||||||
if exists {
|
|
||||||
switch value := vcode.(type) {
|
|
||||||
case string:
|
|
||||||
parsed, convErr := strconv.Atoi(value)
|
|
||||||
if convErr != nil {
|
|
||||||
return fmt.Errorf("invalid vcode format")
|
|
||||||
}
|
|
||||||
payload["vcode"] = parsed
|
|
||||||
case float64:
|
|
||||||
payload["vcode"] = int(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
normalized, err := json.Marshal(payload)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Body = io.NopCloser(bytes.NewReader(normalized))
|
|
||||||
r.ContentLength = int64(len(normalized))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
+5
-5
@@ -12,17 +12,17 @@ import (
|
|||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 修改密码-使用验证码
|
// 切换当前激活角色
|
||||||
func UpdatePasswordByVcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func SwitchRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.ResetPasswordByVcode
|
var req types.SwitchRoleReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewUpdatePasswordByVcodeLogic(r.Context(), svcCtx)
|
l := user.NewSwitchRoleLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.UpdatePasswordByVcode(&req)
|
resp, err := l.SwitchRole(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
} else {
|
} else {
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/user"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 取消关注用户
|
||||||
|
func UnfollowUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.UnfollowUserReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := user.NewUnfollowUserLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.UnfollowUser(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/logic/user"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 更新通知偏好
|
||||||
|
func UpdateNotificationSettingsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.UpdateNotifySettingsReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := user.NewUpdateNotificationSettingsLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.UpdateNotificationSettings(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/user"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 更新主题偏好
|
||||||
|
func UpdateThemeSettingsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.UpdateThemeSettingsReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := user.NewUpdateThemeSettingsLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.UpdateThemeSettings(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/verification_admin"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 管理员通过申请
|
||||||
|
func ApproveVerificationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.VerificationIdReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := verification_admin.NewApproveVerificationLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ApproveVerification(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/verification_admin"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 管理员获取认证申请列表 (分页)
|
||||||
|
func GetVerificationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetPendingListReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := verification_admin.NewGetVerificationsLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetVerifications(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/verification_admin"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 管理员驳回申请
|
||||||
|
func RejectVerificationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.RejectVerificationReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := verification_admin.NewRejectVerificationLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.RejectVerification(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/verification_user"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 提交或修改角色认证申请 (支持幂等更新)
|
||||||
|
func ApplyVerificationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.ApplyVerificationReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := verification_user.NewApplyVerificationLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ApplyVerification(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"juwan-backend/app/users/api/internal/logic/verification_user"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取我的所有认证状态
|
||||||
|
func GetMyVerificationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
l := verification_user.NewGetMyVerificationsLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetMyVerifications()
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ForgotPasswordLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 忘记密码-发送验证码
|
||||||
|
func NewForgotPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForgotPasswordLogic {
|
||||||
|
return &ForgotPasswordLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ForgotPasswordLogic) ForgotPassword(req *types.ForgotPasswordReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
+8
-9
@@ -1,15 +1,15 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
|
|
||||||
package user
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -20,7 +20,7 @@ type LoginLogic struct {
|
|||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户登录接口
|
// 用户登录
|
||||||
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
|
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
|
||||||
return &LoginLogic{
|
return &LoginLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
@@ -30,6 +30,7 @@ func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
|
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
if len(req.Username) < 3 || len(req.Password) < 8 || len(req.Password) > 20 {
|
if len(req.Username) < 3 || len(req.Password) < 8 || len(req.Password) > 20 {
|
||||||
return nil, errors.New("the information is illegal")
|
return nil, errors.New("the information is illegal")
|
||||||
}
|
}
|
||||||
@@ -50,10 +51,8 @@ func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &types.LoginResp{
|
return &types.LoginResp{
|
||||||
UserId: res.Id,
|
AccessToken: "",
|
||||||
Username: res.Username,
|
RefreshToken: res.Token,
|
||||||
Email: res.Email,
|
User: types.User{},
|
||||||
Token: res.Token,
|
|
||||||
Expires: int64((7 * 24 * time.Hour).Seconds()),
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
+13
-8
@@ -1,15 +1,16 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
|
|
||||||
package user
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -20,7 +21,7 @@ type LogoutLogic struct {
|
|||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户登出
|
// 退出登录
|
||||||
func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
|
func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
|
||||||
return &LogoutLogic{
|
return &LogoutLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
@@ -29,15 +30,19 @@ func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LogoutLogic) Logout(req *types.LogoutReq) (resp *types.LogoutResp, err error) {
|
func (l *LogoutLogic) Logout(_ *types.LogoutReq) (resp *types.EmptyResp, err error) {
|
||||||
if req.UserId <= 0 {
|
// todo: add your logic here and delete this line
|
||||||
|
userId, err := contextx.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("illegal id")
|
||||||
|
}
|
||||||
|
if userId <= 0 {
|
||||||
return nil, errors.New("invalid userId")
|
return nil, errors.New("invalid userId")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = l.svcCtx.UserRpc.Logout(l.ctx, &usercenter.LogoutReq{UserId: req.UserId})
|
_, err = l.svcCtx.UserRpc.Logout(l.ctx, &usercenter.LogoutReq{UserId: userId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return &types.EmptyResp{}, nil
|
||||||
return &types.LogoutResp{Message: "logout success"}, nil
|
|
||||||
}
|
}
|
||||||
+11
-12
@@ -1,19 +1,19 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
|
|
||||||
package user
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/users/api/internal/contextx"
|
"juwan-backend/app/users/rpc/pb"
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
"juwan-backend/common/utils/pwdUtils"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
"juwan-backend/app/users/rpc/pb"
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
|
||||||
"juwan-backend/common/utils"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -24,7 +24,7 @@ type RegisterLogic struct {
|
|||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户注册接口
|
// 用户注册
|
||||||
func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
|
func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
|
||||||
return &RegisterLogic{
|
return &RegisterLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
@@ -52,7 +52,7 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterRe
|
|||||||
return nil, errors.New("user already exists")
|
return nil, errors.New("user already exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
hashedPassword, err := utils.HashPassword(req.Password)
|
hashedPassword, err := pwdUtils.HashPassword(req.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("hash password failed")
|
return nil, errors.New("hash password failed")
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterRe
|
|||||||
return nil, errors.New("contextx.RequestIdFrom failed")
|
return nil, errors.New("contextx.RequestIdFrom failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = l.svcCtx.UserRpc.Register(l.ctx, &usercenter.RegisterReq{
|
res, err := l.svcCtx.UserRpc.Register(l.ctx, &usercenter.RegisterReq{
|
||||||
Username: req.Username,
|
Username: req.Username,
|
||||||
Passwd: hashedPassword,
|
Passwd: hashedPassword,
|
||||||
Phone: req.Username,
|
Phone: req.Username,
|
||||||
@@ -78,9 +78,8 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterRe
|
|||||||
|
|
||||||
// 返回响应
|
// 返回响应
|
||||||
return &types.RegisterResp{
|
return &types.RegisterResp{
|
||||||
UserId: 0,
|
AccessToken: "",
|
||||||
Username: req.Username,
|
RefreshToken: res.Res,
|
||||||
Email: req.Email,
|
User: types.User{},
|
||||||
Message: "register success",
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
+9
-10
@@ -1,14 +1,14 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
|
|
||||||
package user
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/users/api/internal/contextx"
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/utils"
|
"juwan-backend/common/utils/contextx"
|
||||||
|
"juwan-backend/common/utils/pwdUtils"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
@@ -16,29 +16,28 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdatePasswordByVcodeLogic struct {
|
type ResetPasswordLogic struct {
|
||||||
logx.Logger
|
logx.Logger
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改密码-使用验证码
|
// 重置密码
|
||||||
func NewUpdatePasswordByVcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordByVcodeLogic {
|
func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPasswordLogic {
|
||||||
return &UpdatePasswordByVcodeLogic{
|
return &ResetPasswordLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
svcCtx: svcCtx,
|
svcCtx: svcCtx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UpdatePasswordByVcodeLogic) UpdatePasswordByVcode(req *types.ResetPasswordByVcode) (resp *types.EmptyResp, err error) {
|
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordReq) (resp *types.EmptyResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
|
||||||
requestId, err := contextx.RequestIdFrom(l.ctx)
|
requestId, err := contextx.RequestIdFrom(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("get request id from context failed, err:%v.", err)
|
logx.Errorf("get request id from context failed, err:%v.", err)
|
||||||
return nil, errors.New("bad request")
|
return nil, errors.New("bad request")
|
||||||
}
|
}
|
||||||
hashedPassword, err := utils.HashPassword(req.Password)
|
hashedPassword, err := pwdUtils.HashPassword(req.NewPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("hash password failed, err:%v.", err)
|
logx.Errorf("hash password failed, err:%v.", err)
|
||||||
return nil, errors.New("bad password")
|
return nil, errors.New("bad password")
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FollowUserLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关注用户
|
||||||
|
func NewFollowUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FollowUserLogic {
|
||||||
|
return &FollowUserLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FollowUserLogic) FollowUser(req *types.FollowUserReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -6,9 +6,10 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/users/api/internal/contextx"
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/converter"
|
"juwan-backend/common/converter"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
"time"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
@@ -31,7 +32,7 @@ func NewGetMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMeLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetMeLogic) GetMe() (resp *types.UserInfo, err error) {
|
func (l *GetMeLogic) GetMe() (resp *types.User, err error) {
|
||||||
userId, err := contextx.UserIDFrom(l.ctx)
|
userId, err := contextx.UserIDFrom(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("illegal id")
|
return nil, errors.New("illegal id")
|
||||||
@@ -43,6 +44,8 @@ func (l *GetMeLogic) GetMe() (resp *types.UserInfo, err error) {
|
|||||||
return nil, errors.New("get user by id error")
|
return nil, errors.New("get user by id error")
|
||||||
}
|
}
|
||||||
err = converter.StructToStruct(user, &resp)
|
err = converter.StructToStruct(user, &resp)
|
||||||
|
createAt := time.Unix(user.Users.CreatedAt, 0)
|
||||||
|
resp.CreatedAt = createAt.Format(time.DateTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("to struct error")
|
return nil, errors.New("to struct error")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
|
||||||
"juwan-backend/common/converter"
|
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,21 +29,21 @@ func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetUserInfoLogic) GetUserInfo(req *types.GetUserInfoReq) (resp types.UserInfo, err error) {
|
func (l *GetUserInfoLogic) GetUserInfo(req *types.GetUserReq) (resp types.User, err error) {
|
||||||
|
|
||||||
pbUser, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
pbUser, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
||||||
Id: req.UserId,
|
Id: req.Id,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.UserInfo{}, errors.New("failed to get user info by userid")
|
return types.User{}, errors.New("failed to get user info by userid")
|
||||||
}
|
}
|
||||||
user := types.UserInfo{}
|
|
||||||
err = converter.StructToStruct(&pbUser.Users, &user)
|
user := types.User{}
|
||||||
if err != nil {
|
err = copier.Copy(&user, &pbUser.Users)
|
||||||
logx.Errorf("struct to user info failed, err:%v.", err)
|
if err != nil {
|
||||||
return types.UserInfo{}, errors.New("failed to get user info by userid")
|
logx.Errorf("struct to user info failed, err:%v.", err)
|
||||||
|
return types.User{}, errors.New("failed to get user info by userid")
|
||||||
}
|
}
|
||||||
|
|
||||||
//req.UserId
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SwitchRoleLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 切换当前激活角色
|
||||||
|
func NewSwitchRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SwitchRoleLogic {
|
||||||
|
return &SwitchRoleLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *SwitchRoleLogic) SwitchRole(req *types.SwitchRoleReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
id, err := contextx.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("get user id from context: %v", err)
|
||||||
|
return nil, errors.New("illegal id")
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
||||||
|
Id: id,
|
||||||
|
CurrentRole: proto.String(req.Role),
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("update user info by id: %v", err)
|
||||||
|
return nil, errors.New("update user info by userid")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UnfollowUserLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消关注用户
|
||||||
|
func NewUnfollowUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnfollowUserLogic {
|
||||||
|
return &UnfollowUserLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UnfollowUserLogic) UnfollowUser(req *types.UnfollowUserReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -6,9 +6,10 @@ package user
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/users/api/internal/contextx"
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
"juwan-backend/app/users/rpc/usercenter"
|
||||||
"juwan-backend/common/converter"
|
"juwan-backend/common/converter"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
"juwan-backend/app/users/api/internal/types"
|
"juwan-backend/app/users/api/internal/types"
|
||||||
@@ -31,16 +32,16 @@ func NewUpdateMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UpdateMeLogic) UpdateMe(req *types.UpdateUserInfoReq) (resp *types.UserInfo, err error) {
|
func (l *UpdateMeLogic) UpdateMe(req *types.UpdateUserProfileReq) (resp *types.UpdateUserProfileReq, err error) {
|
||||||
userId, err := contextx.UserIDFrom(l.ctx)
|
userId, err := contextx.UserIDFrom(l.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res, err := l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
res, err := l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
||||||
Id: userId,
|
Id: userId,
|
||||||
Nickname: req.Nickname,
|
Nickname: proto_string(req.Nickname),
|
||||||
Avatar: req.Avatar,
|
Avatar: proto_string(req.Avatar),
|
||||||
Bio: req.Bio,
|
Bio: proto_string(req.Bio),
|
||||||
VerifiedRoles: nil,
|
VerifiedRoles: nil,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,3 +54,10 @@ func (l *UpdateMeLogic) UpdateMe(req *types.UpdateUserInfoReq) (resp *types.User
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func proto_string(s string) *string {
|
||||||
|
if len(s) == 0 || strings.Contains(s, " ") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &s
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateNotificationSettingsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新通知偏好
|
||||||
|
func NewUpdateNotificationSettingsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNotificationSettingsLogic {
|
||||||
|
return &UpdateNotificationSettingsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdateNotificationSettingsLogic) UpdateNotificationSettings(req *types.UpdateNotifySettingsReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
|
||||||
// goctl 1.9.2
|
|
||||||
|
|
||||||
package user
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"juwan-backend/app/users/api/internal/contextx"
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
|
||||||
"juwan-backend/common/utils"
|
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
|
||||||
"juwan-backend/app/users/api/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ChangeUserPassFailed = errors.New("change user pass failed")
|
|
||||||
|
|
||||||
type UpdatePasswordLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改用户密码
|
|
||||||
func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
|
|
||||||
return &UpdatePasswordLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *UpdatePasswordLogic) UpdatePassword(req *types.UpdatePasswordReq) (resp *types.UpdatePasswordResp, err error) {
|
|
||||||
// todo: add your logic here and delete this line
|
|
||||||
userId, err := contextx.UserIDFrom(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
logx.Errorf("get user id from context failed, err:%v.", err)
|
|
||||||
return nil, ChangeUserPassFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := l.svcCtx.UserRpc.GetUsersById(l.ctx, &usercenter.GetUsersByIdReq{
|
|
||||||
Id: userId,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logx.Errorf("get user info failed, err:%v.", err)
|
|
||||||
return nil, ChangeUserPassFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
oldPasswd, err := utils.HashPassword(req.OldPassword)
|
|
||||||
if err != nil {
|
|
||||||
logx.Errorf("hash old password failed, err:%v.", err)
|
|
||||||
return nil, ChangeUserPassFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
if oldPasswd != user.Users.PasswordHash {
|
|
||||||
return nil, ChangeUserPassFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
|
||||||
Id: userId,
|
|
||||||
Username: &user.Users.Username,
|
|
||||||
PasswordHash: &req.NewPassword,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logx.Errorf("update user password failed, err:%v.", err)
|
|
||||||
return nil, ChangeUserPassFailed
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateThemeSettingsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新主题偏好
|
||||||
|
func NewUpdateThemeSettingsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateThemeSettingsLogic {
|
||||||
|
return &UpdateThemeSettingsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdateThemeSettingsLogic) UpdateThemeSettings(req *types.UpdateThemeSettingsReq) (resp *types.EmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
// Code scaffolded by goctl. Safe to edit.
|
|
||||||
// goctl 1.9.2
|
|
||||||
|
|
||||||
package user
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"juwan-backend/app/users/api/internal/contextx"
|
|
||||||
"juwan-backend/app/users/rpc/usercenter"
|
|
||||||
|
|
||||||
"juwan-backend/app/users/api/internal/svc"
|
|
||||||
"juwan-backend/app/users/api/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateUserInfoLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改用户信息
|
|
||||||
func NewUpdateUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserInfoLogic {
|
|
||||||
return &UpdateUserInfoLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *UpdateUserInfoLogic) UpdateUserInfo(req *types.UpdateUserInfoReq) (resp *types.UpdateUserInfoResp, err error) {
|
|
||||||
userId, err := contextx.UserIDFrom(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("user not found")
|
|
||||||
}
|
|
||||||
_, err = l.svcCtx.UserRpc.UpdateUsers(l.ctx, &usercenter.UpdateUsersReq{
|
|
||||||
Id: userId,
|
|
||||||
Nickname: req.Nickname,
|
|
||||||
Avatar: req.Avatar,
|
|
||||||
Bio: req.Bio,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("update user info failed")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ApproveVerificationLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 管理员通过申请
|
||||||
|
func NewApproveVerificationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApproveVerificationLogic {
|
||||||
|
return &ApproveVerificationLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
APPROVE = "approved"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (l *ApproveVerificationLogic) ApproveVerification(req *types.VerificationIdReq) (resp *types.VerificationEmptyResp, err error) {
|
||||||
|
adminId, err := contextx.AdminIdFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.UserVerificationsRpc.UpdateUserVerifications(l.ctx, &pb.UpdateUserVerificationsReq{
|
||||||
|
Id: req.Id,
|
||||||
|
Status: &APPROVE,
|
||||||
|
ReviewedBy: adminId,
|
||||||
|
ReviewedAt: time.Now().Unix(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetVerificationsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 管理员获取认证申请列表 (分页)
|
||||||
|
func NewGetVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetVerificationsLogic {
|
||||||
|
return &GetVerificationsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetVerificationsLogic) GetVerifications(req *types.GetPendingListReq) (resp *types.GetPendingListResp, err error) {
|
||||||
|
_, err = contextx.AdminIdFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
verifications, err := l.svcCtx.UserVerificationsRpc.SearchUserVerifications(l.ctx, &pb.SearchUserVerificationsReq{
|
||||||
|
Page: req.Page,
|
||||||
|
Limit: req.Size,
|
||||||
|
Role: req.Role,
|
||||||
|
Status: req.Status,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var searchResults []types.VerificationItem
|
||||||
|
for _, v := range verifications.UserVerifications {
|
||||||
|
temp := types.VerificationItem{}
|
||||||
|
err = copier.Copy(&temp, v)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("copy verification item err: %s", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
temp.CreatedAt = time.Unix(v.CreatedAt, 0).Format(time.DateTime)
|
||||||
|
temp.ReviewedAt = time.Unix(v.ReviewedAt, 0).Format(time.DateTime)
|
||||||
|
searchResults = append(searchResults, temp)
|
||||||
|
}
|
||||||
|
resp = &types.GetPendingListResp{
|
||||||
|
List: searchResults,
|
||||||
|
Total: 0,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RejectVerificationLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 管理员驳回申请
|
||||||
|
func NewRejectVerificationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RejectVerificationLogic {
|
||||||
|
return &RejectVerificationLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var REJECTED = "rejected"
|
||||||
|
|
||||||
|
func (l *RejectVerificationLogic) RejectVerification(req *types.RejectVerificationReq) (resp *types.VerificationEmptyResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
adminId, err := contextx.AdminIdFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.UserVerificationsRpc.UpdateUserVerifications(l.ctx, &pb.UpdateUserVerificationsReq{
|
||||||
|
Id: req.Id,
|
||||||
|
Status: &REJECTED,
|
||||||
|
RejectReason: &req.Reason,
|
||||||
|
ReviewedBy: adminId,
|
||||||
|
ReviewedAt: time.Now().Unix(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ApplyVerificationLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交或修改角色认证申请 (支持幂等更新)
|
||||||
|
func NewApplyVerificationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyVerificationLogic {
|
||||||
|
return &ApplyVerificationLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ApplyVerificationLogic) ApplyVerification(req *types.ApplyVerificationReq) (resp *types.VerificationEmptyResp, err error) {
|
||||||
|
userId, err := contextx.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("get user id from context: %v", err)
|
||||||
|
return nil, contextx.ERRILLEGALUSER
|
||||||
|
}
|
||||||
|
verifications, err := l.svcCtx.UserVerificationsRpc.SearchUserVerifications(l.ctx, &pb.SearchUserVerificationsReq{
|
||||||
|
UserId: userId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("search user verifications: %v", err)
|
||||||
|
return nil, errors.New("search user verifications failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
materials, err := json.Marshal(req.Materials)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("marshal materials: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if verifications == nil || len(verifications.UserVerifications) == 0 {
|
||||||
|
// 如果没有则增加
|
||||||
|
_, err = l.svcCtx.UserVerificationsRpc.AddUserVerifications(l.ctx, &pb.AddUserVerificationsReq{
|
||||||
|
Role: req.Role,
|
||||||
|
Materials: string(materials),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("add user verifications: %v", err)
|
||||||
|
return nil, errors.New("add user verifications failed")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.VerificationEmptyResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package verification_user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/user_verifications/rpc/pb"
|
||||||
|
"juwan-backend/common/utils/contextx"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/users/api/internal/svc"
|
||||||
|
"juwan-backend/app/users/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetMyVerificationsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取我的所有认证状态
|
||||||
|
func NewGetMyVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMyVerificationsLogic {
|
||||||
|
return &GetMyVerificationsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetMyVerificationsLogic) GetMyVerifications() (resp *types.GetMyVerificationsResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
userId, err := contextx.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("get user id from context: %v", err)
|
||||||
|
return nil, contextx.ERRILLEGALUSER
|
||||||
|
}
|
||||||
|
|
||||||
|
verifications, err := l.svcCtx.UserVerificationsRpc.SearchUserVerifications(l.ctx, &pb.SearchUserVerificationsReq{
|
||||||
|
UserId: userId,
|
||||||
|
Page: 1,
|
||||||
|
Limit: 100, // assuming a user won't have more than 100 verification records, adjust as needed
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var searchResults []types.VerificationItem
|
||||||
|
for _, v := range verifications.UserVerifications {
|
||||||
|
temp := types.VerificationItem{}
|
||||||
|
err = copier.Copy(&temp, v)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("copy verification item err: %s", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
temp.CreatedAt = time.Unix(v.CreatedAt, 0).Format(time.DateTime)
|
||||||
|
temp.ReviewedAt = time.Unix(v.ReviewedAt, 0).Format(time.DateTime)
|
||||||
|
searchResults = append(searchResults, temp)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = &types.GetMyVerificationsResp{
|
||||||
|
List: searchResults,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.9.2
|
||||||
|
|
||||||
|
package middleware
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
type JwtAuthMiddleware struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJwtAuthMiddleware() *JwtAuthMiddleware {
|
||||||
|
return &JwtAuthMiddleware{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *JwtAuthMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// TODO generate middleware implement function, delete after code implementation
|
||||||
|
|
||||||
|
// Passthrough to next handler if need
|
||||||
|
next(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user