repo: add some more sql for events

This commit is contained in:
Muyao CHEN 2024-10-18 21:41:53 +02:00
parent dde4eb337c
commit a55fd26f90
4 changed files with 60 additions and 5 deletions

View File

@ -422,7 +422,7 @@ The following basic use cases are to be implemented at the first time.
- [X] A user signs up
- [X] A user logs in
- [X] A user lists their events (pagination)
- [] A user sees the detail of an event (description, members, amount)
- [X] A user sees the detail of an event (description, members, amount)
- [] A user sees the expenses of an event (total amount, personal expenses, pagination)
- [] A user sees the detail of an expense: (time, amount, payers, recipients)
- [] A user adds an expense
@ -431,13 +431,18 @@ The following basic use cases are to be implemented at the first time.
- [] A user restore a deleted expense
- [] A user can pay the debt to other members
- [X] A user creates an event (and participate to it)
- [] A user updates the event info
- [] A user invites another user by sending a mail with a token.
- [] A user joins an event by accepting an invitation
- [] A user quits an event (they cannot actually, but we can make as if they quitted)
- [X] A user updates the event info
- [X] A user invites another user by sending a mail with a token.
- [X] A user joins an event by accepting an invitation
- [] ~A user quits an event (they cannot actually, but we can make as if they quitted)~
**No we can't quit!**
- [] A user cannot see other user's information
- [] A user cannot see the events that they didn't participated in.
For the second stage:
- [] A user can archive an event
With those functionalities, there will be an usable product. And then we can
work on other aspects. For example:

View File

@ -56,3 +56,9 @@ GROUP BY
e.total_amount, e.default_currency,
o.id, o.first_name, o.last_name;
-- name: UpdateEventByID :exec
UPDATE "event"
SET name = $2, description = $3, updated_at = $4
WHERE id = $1;

View File

@ -172,3 +172,26 @@ func (q *Queries) ListEventsByUserID(ctx context.Context, userID int32) ([]ListE
}
return items, nil
}
const updateEventByID = `-- name: UpdateEventByID :exec
UPDATE "event"
SET name = $2, description = $3, updated_at = $4
WHERE id = $1
`
type UpdateEventByIDParams struct {
ID int32
Name string
Description sql.NullString
UpdatedAt time.Time
}
func (q *Queries) UpdateEventByID(ctx context.Context, arg UpdateEventByIDParams) error {
_, err := q.db.ExecContext(ctx, updateEventByID,
arg.ID,
arg.Name,
arg.Description,
arg.UpdatedAt,
)
return err
}

View File

@ -5,6 +5,7 @@
package sqlc
import (
"database/sql"
"time"
)
@ -15,6 +16,26 @@ type Admin struct {
AccessLevel int32
}
type Event struct {
ID int32
Name string
Description sql.NullString
DefaultCurrency string
OwnerID int32
CreatedAt time.Time
UpdatedAt time.Time
TotalAmount sql.NullInt32
}
type Participation struct {
ID int32
UserID int32
EventID int32
InvitedByUserID sql.NullInt32
CreatedAt time.Time
UpdatedAt time.Time
}
type User struct {
ID int32
Email string