add: user accomplished
This commit is contained in:
@@ -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/user_verifications/rpc/internal/svc"
|
||||
"juwan-backend/app/user_verifications/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddUserVerificationsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserVerificationsLogic {
|
||||
return &AddUserVerificationsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------userVerifications-----------------------
|
||||
func (l *AddUserVerificationsLogic) AddUserVerifications(in *pb.AddUserVerificationsReq) (*pb.AddUserVerificationsResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.AddUserVerificationsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||
"juwan-backend/app/user_verifications/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelUserVerificationsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelUserVerificationsLogic {
|
||||
return &DelUserVerificationsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelUserVerificationsLogic) DelUserVerifications(in *pb.DelUserVerificationsReq) (*pb.DelUserVerificationsResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.DelUserVerificationsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||
"juwan-backend/app/user_verifications/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserVerificationsByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetUserVerificationsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserVerificationsByIdLogic {
|
||||
return &GetUserVerificationsByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserVerificationsByIdLogic) GetUserVerificationsById(in *pb.GetUserVerificationsByIdReq) (*pb.GetUserVerificationsByIdResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.GetUserVerificationsByIdResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||
"juwan-backend/app/user_verifications/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchUserVerificationsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchUserVerificationsLogic {
|
||||
return &SearchUserVerificationsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchUserVerificationsLogic) SearchUserVerifications(in *pb.SearchUserVerificationsReq) (*pb.SearchUserVerificationsResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.SearchUserVerificationsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||
"juwan-backend/app/user_verifications/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateUserVerificationsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserVerificationsLogic {
|
||||
return &UpdateUserVerificationsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateUserVerificationsLogic) UpdateUserVerifications(in *pb.UpdateUserVerificationsReq) (*pb.UpdateUserVerificationsResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &pb.UpdateUserVerificationsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// Source: user_verifications.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/user_verifications/rpc/internal/logic"
|
||||
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
||||
"juwan-backend/app/user_verifications/rpc/pb"
|
||||
)
|
||||
|
||||
type UserVerificationsServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
pb.UnimplementedUserVerificationsServer
|
||||
}
|
||||
|
||||
func NewUserVerificationsServer(svcCtx *svc.ServiceContext) *UserVerificationsServer {
|
||||
return &UserVerificationsServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------userVerifications-----------------------
|
||||
func (s *UserVerificationsServer) AddUserVerifications(ctx context.Context, in *pb.AddUserVerificationsReq) (*pb.AddUserVerificationsResp, error) {
|
||||
l := logic.NewAddUserVerificationsLogic(ctx, s.svcCtx)
|
||||
return l.AddUserVerifications(in)
|
||||
}
|
||||
|
||||
func (s *UserVerificationsServer) UpdateUserVerifications(ctx context.Context, in *pb.UpdateUserVerificationsReq) (*pb.UpdateUserVerificationsResp, error) {
|
||||
l := logic.NewUpdateUserVerificationsLogic(ctx, s.svcCtx)
|
||||
return l.UpdateUserVerifications(in)
|
||||
}
|
||||
|
||||
func (s *UserVerificationsServer) DelUserVerifications(ctx context.Context, in *pb.DelUserVerificationsReq) (*pb.DelUserVerificationsResp, error) {
|
||||
l := logic.NewDelUserVerificationsLogic(ctx, s.svcCtx)
|
||||
return l.DelUserVerifications(in)
|
||||
}
|
||||
|
||||
func (s *UserVerificationsServer) GetUserVerificationsById(ctx context.Context, in *pb.GetUserVerificationsByIdReq) (*pb.GetUserVerificationsByIdResp, error) {
|
||||
l := logic.NewGetUserVerificationsByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetUserVerificationsById(in)
|
||||
}
|
||||
|
||||
func (s *UserVerificationsServer) SearchUserVerifications(ctx context.Context, in *pb.SearchUserVerificationsReq) (*pb.SearchUserVerificationsResp, error) {
|
||||
l := logic.NewSearchUserVerificationsLogic(ctx, s.svcCtx)
|
||||
return l.SearchUserVerifications(in)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package svc
|
||||
|
||||
import "juwan-backend/app/user_verifications/rpc/internal/config"
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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...),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// 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
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package svc
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var ErrNotFound = sqlx.ErrNotFound
|
||||
Reference in New Issue
Block a user