add: some user api and all api desc

This commit is contained in:
wwweww
2026-02-27 19:17:01 +08:00
parent a0c720eb2f
commit 5930fb0dde
156 changed files with 9457 additions and 1086 deletions
@@ -1,13 +1,55 @@
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 {
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 {
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{
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