|
|
|
@@ -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
|
|
|
|
|
}
|