u
This commit is contained in:
1 parent
500fab7a80
commit
8f3f6982db
54 files changed
+2076
-1877
No files matched your search
@@ -38,34 +38,32 @@ type MoneyUserCategory struct {
|
||||
CreateTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
// 共享空间(一个空间包含多个成员)
|
||||
type Space struct {
|
||||
// 空间ID
|
||||
ID int64
|
||||
// 空间名称
|
||||
Name pgtype.Text
|
||||
// 空间邀请码
|
||||
ID int64
|
||||
Name pgtype.Text
|
||||
InviteCode string
|
||||
// 空间创建时间
|
||||
CreateTime pgtype.Timestamp
|
||||
// 空间更新时间
|
||||
UpdateTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
// 共享空间成员表
|
||||
type SpaceUser struct {
|
||||
// 主键ID
|
||||
ID int64
|
||||
// 所属空间ID
|
||||
SpaceID int64
|
||||
// 用户ID(唯一,每用户只加入一个空间)
|
||||
UserID int64
|
||||
// 成员角色:0创建者 1管理员 2普通
|
||||
Role int32
|
||||
// 加入空间时间
|
||||
ID int64
|
||||
SpaceID int64
|
||||
UserID int64
|
||||
Role int32
|
||||
JoinTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int64
|
||||
Username string
|
||||
Avatar string
|
||||
Status int32
|
||||
LastLoginTime pgtype.Timestamptz
|
||||
CreateTime pgtype.Timestamptz
|
||||
UpdateTime pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
ID int64
|
||||
SeqNo pgtype.Int4
|
||||
@@ -79,3 +77,13 @@ type UserInfo struct {
|
||||
ActiveTime pgtype.Timestamp
|
||||
LastLoginTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
type UserOauth struct {
|
||||
ID int64
|
||||
UserID int64
|
||||
Type int32
|
||||
Openid string
|
||||
Unionid pgtype.Text
|
||||
CreateTime pgtype.Timestamptz
|
||||
UpdateTime pgtype.Timestamptz
|
||||
}
|
||||
@@ -19,13 +19,12 @@ func (q *Queries) DeleteSpace(ctx context.Context, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const getSpaceById = `-- name: GetSpaceById :one
|
||||
SELECT id, name, invite_code, create_time, update_time FROM space WHERE id = $1
|
||||
const findSpaceByInviteCode = `-- name: FindSpaceByInviteCode :one
|
||||
SELECT id, name, invite_code, create_time, update_time FROM space WHERE invite_code = $1
|
||||
`
|
||||
|
||||
// 根据id获取分享空间信息
|
||||
func (q *Queries) GetSpaceById(ctx context.Context, id int64) (Space, error) {
|
||||
row := q.db.QueryRow(ctx, getSpaceById, id)
|
||||
func (q *Queries) FindSpaceByInviteCode(ctx context.Context, inviteCode string) (Space, error) {
|
||||
row := q.db.QueryRow(ctx, findSpaceByInviteCode, inviteCode)
|
||||
var i Space
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
@@ -37,13 +36,13 @@ func (q *Queries) GetSpaceById(ctx context.Context, id int64) (Space, error) {
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getSpaceByInviteCode = `-- name: GetSpaceByInviteCode :one
|
||||
SELECT id, name, invite_code, create_time, update_time FROM space WHERE invite_code = $1
|
||||
const getSpaceById = `-- name: GetSpaceById :one
|
||||
SELECT id, name, invite_code, create_time, update_time FROM space WHERE id = $1
|
||||
`
|
||||
|
||||
// 根据验证码获取空间
|
||||
func (q *Queries) GetSpaceByInviteCode(ctx context.Context, inviteCode string) (Space, error) {
|
||||
row := q.db.QueryRow(ctx, getSpaceByInviteCode, inviteCode)
|
||||
// 根据id获取分享空间信息
|
||||
func (q *Queries) GetSpaceById(ctx context.Context, id int64) (Space, error) {
|
||||
row := q.db.QueryRow(ctx, getSpaceById, id)
|
||||
var i Space
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: user.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const findUserByOpenID = `-- name: FindUserByOpenID :one
|
||||
SELECT
|
||||
u.id AS user_id,
|
||||
u.username,
|
||||
u.avatar,
|
||||
u.status,
|
||||
o.type AS login_type,
|
||||
o.openid
|
||||
FROM user_oauth o
|
||||
JOIN "user" u ON u.id = o.user_id
|
||||
WHERE o.openid = $1
|
||||
AND o.type = $2
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type FindUserByOpenIDParams struct {
|
||||
Openid string
|
||||
Type int32
|
||||
}
|
||||
|
||||
type FindUserByOpenIDRow struct {
|
||||
UserID int64
|
||||
Username string
|
||||
Avatar string
|
||||
Status int32
|
||||
LoginType int32
|
||||
Openid string
|
||||
}
|
||||
|
||||
func (q *Queries) FindUserByOpenID(ctx context.Context, arg FindUserByOpenIDParams) (FindUserByOpenIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, findUserByOpenID, arg.Openid, arg.Type)
|
||||
var i FindUserByOpenIDRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.Username,
|
||||
&i.Avatar,
|
||||
&i.Status,
|
||||
&i.LoginType,
|
||||
&i.Openid,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertUser = `-- name: InsertUser :exec
|
||||
INSERT INTO "user" (
|
||||
id,
|
||||
username,
|
||||
avatar,
|
||||
status,
|
||||
create_time,
|
||||
update_time
|
||||
) VALUES (
|
||||
$1, $2, $3,$4, NOW(), NOW()
|
||||
)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type InsertUserParams struct {
|
||||
ID int64
|
||||
Username string
|
||||
Avatar string
|
||||
Status int32
|
||||
}
|
||||
|
||||
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) error {
|
||||
_, err := q.db.Exec(ctx, insertUser,
|
||||
arg.ID,
|
||||
arg.Username,
|
||||
arg.Avatar,
|
||||
arg.Status,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateUserLastLoginTime = `-- name: UpdateUserLastLoginTime :exec
|
||||
UPDATE "user"
|
||||
SET last_login_time = NOW()
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) UpdateUserLastLoginTime(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, updateUserLastLoginTime, id)
|
||||
return err
|
||||
}
|
||||
@@ -7,8 +7,6 @@ package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getUserByAccount = `-- name: GetUserByAccount :one
|
||||
@@ -95,32 +93,6 @@ func (q *Queries) GetUserForLogin(ctx context.Context, arg GetUserForLoginParams
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertUser = `-- name: InsertUser :execrows
|
||||
INSERT INTO user_info (id, account, password,username)
|
||||
VALUES ($1, $2, $3,$4)
|
||||
`
|
||||
|
||||
type InsertUserParams struct {
|
||||
ID int64
|
||||
Account string
|
||||
Password string
|
||||
Username pgtype.Text
|
||||
}
|
||||
|
||||
// 插入用户并返回刚创建的记录
|
||||
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, insertUser,
|
||||
arg.ID,
|
||||
arg.Account,
|
||||
arg.Password,
|
||||
arg.Username,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateUserActiveTime = `-- name: UpdateUserActiveTime :exec
|
||||
UPDATE user_info
|
||||
SET active_time = now()
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: user_oauth.sql
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const insertUserOAuth = `-- name: InsertUserOAuth :exec
|
||||
INSERT INTO user_oauth (
|
||||
id,
|
||||
user_id,
|
||||
type,
|
||||
openid,
|
||||
create_time,
|
||||
update_time
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, NOW(), NOW()
|
||||
)
|
||||
`
|
||||
|
||||
type InsertUserOAuthParams struct {
|
||||
ID int64
|
||||
UserID int64
|
||||
Type int32
|
||||
Openid string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertUserOAuth(ctx context.Context, arg InsertUserOAuthParams) error {
|
||||
_, err := q.db.Exec(ctx, insertUserOAuth,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Type,
|
||||
arg.Openid,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user