u
This commit is contained in:
1 parent
33ab76f73e
commit
3af982d669
31 files changed
+632
-316
No files matched your search
@@ -10,6 +10,20 @@ WHERE mr.user_id = $1
|
||||
AND mr.record_time BETWEEN $2 AND $3
|
||||
ORDER BY mr.record_time DESC, mr.create_time DESC;
|
||||
|
||||
-- name: FindMoneyRecordsBySpace :many
|
||||
SELECT
|
||||
mr.*,
|
||||
u.username AS username,
|
||||
muc.name AS category_name,
|
||||
muc.icon AS category_icon,
|
||||
muc.type AS category_type
|
||||
FROM money_record mr
|
||||
LEFT JOIN money_user_category muc ON mr.category_id = muc.id
|
||||
INNER JOIN space_user su ON mr.user_id = su.user_id AND su.space_id = $1
|
||||
LEFT JOIN user_info u ON mr.user_id = u.id
|
||||
WHERE mr.record_time BETWEEN $2 AND $3
|
||||
ORDER BY mr.record_time DESC, mr.create_time DESC;
|
||||
|
||||
-- name: InsertMoneyRecord :one
|
||||
INSERT INTO money_record (
|
||||
id,
|
||||
|
||||
@@ -20,6 +20,75 @@ func (q *Queries) DeleteMoneyRecord(ctx context.Context, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const findMoneyRecordsBySpace = `-- name: FindMoneyRecordsBySpace :many
|
||||
SELECT
|
||||
mr.id, mr.category_id, mr.user_id, mr.amount, mr.remark, mr.record_time, mr.create_time, mr.update_time,
|
||||
u.username AS username,
|
||||
muc.name AS category_name,
|
||||
muc.icon AS category_icon,
|
||||
muc.type AS category_type
|
||||
FROM money_record mr
|
||||
LEFT JOIN money_user_category muc ON mr.category_id = muc.id
|
||||
INNER JOIN space_user su ON mr.user_id = su.user_id AND su.space_id = $1
|
||||
LEFT JOIN user_info u ON mr.user_id = u.id
|
||||
WHERE mr.record_time BETWEEN $2 AND $3
|
||||
ORDER BY mr.record_time DESC, mr.create_time DESC
|
||||
`
|
||||
|
||||
type FindMoneyRecordsBySpaceParams struct {
|
||||
SpaceID int64
|
||||
RecordTime pgtype.Timestamp
|
||||
RecordTime_2 pgtype.Timestamp
|
||||
}
|
||||
|
||||
type FindMoneyRecordsBySpaceRow struct {
|
||||
ID int64
|
||||
CategoryID int64
|
||||
UserID int64
|
||||
Amount pgtype.Numeric
|
||||
Remark pgtype.Text
|
||||
RecordTime pgtype.Timestamp
|
||||
CreateTime pgtype.Timestamp
|
||||
UpdateTime pgtype.Timestamp
|
||||
Username pgtype.Text
|
||||
CategoryName pgtype.Text
|
||||
CategoryIcon pgtype.Text
|
||||
CategoryType pgtype.Int4
|
||||
}
|
||||
|
||||
func (q *Queries) FindMoneyRecordsBySpace(ctx context.Context, arg FindMoneyRecordsBySpaceParams) ([]FindMoneyRecordsBySpaceRow, error) {
|
||||
rows, err := q.db.Query(ctx, findMoneyRecordsBySpace, arg.SpaceID, arg.RecordTime, arg.RecordTime_2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []FindMoneyRecordsBySpaceRow
|
||||
for rows.Next() {
|
||||
var i FindMoneyRecordsBySpaceRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CategoryID,
|
||||
&i.UserID,
|
||||
&i.Amount,
|
||||
&i.Remark,
|
||||
&i.RecordTime,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
&i.Username,
|
||||
&i.CategoryName,
|
||||
&i.CategoryIcon,
|
||||
&i.CategoryType,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const findUserMoneyRecords = `-- name: FindUserMoneyRecords :many
|
||||
SELECT
|
||||
mr.id, mr.category_id, mr.user_id, mr.amount, mr.remark, mr.record_time, mr.create_time, mr.update_time,
|
||||
|
||||
Reference in new issue
Block a user