Add user detail API + modal. Closes #2002

This commit is contained in:
Gabe Kangas
2022-07-20 20:42:23 -07:00
parent 82a0b492a5
commit f3a16be0dd
21 changed files with 543 additions and 60 deletions

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
// sqlc v1.14.0
package db

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
// sqlc v1.14.0
package db
@@ -52,6 +52,19 @@ type IpBan struct {
CreatedAt sql.NullTime
}
type Message struct {
ID string
UserID sql.NullString
Body sql.NullString
EventType sql.NullString
HiddenAt sql.NullTime
Timestamp sql.NullTime
Title sql.NullString
Subtitle sql.NullString
Image sql.NullString
Link sql.NullString
}
type Notification struct {
ID int32
Channel string

View File

@@ -99,6 +99,9 @@ UPDATE user_access_tokens SET user_id = $1 WHERE token = $2;
-- name: SetUserAsAuthenticated :exec
UPDATE users SET authenticated_at = CURRENT_TIMESTAMP WHERE id = $1;
-- name: GetMessagesFromUser :many
SELECT id, body, hidden_at, timestamp FROM messages WHERE eventType = 'CHAT' AND user_id = $1 ORDER BY TIMESTAMP DESC;
-- name: IsDisplayNameAvailable :one
SELECT count(*) FROM users WHERE display_name = $1 AND authenticated_at is not null AND disabled_at is NULL;

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
// sqlc v1.14.0
// source: query.sql
package db
@@ -412,6 +412,45 @@ func (q *Queries) GetLocalPostCount(ctx context.Context) (int64, error) {
return count, err
}
const getMessagesFromUser = `-- name: GetMessagesFromUser :many
SELECT id, body, hidden_at, timestamp FROM messages WHERE eventType = 'CHAT' AND user_id = $1 ORDER BY TIMESTAMP DESC
`
type GetMessagesFromUserRow struct {
ID string
Body sql.NullString
HiddenAt sql.NullTime
Timestamp sql.NullTime
}
func (q *Queries) GetMessagesFromUser(ctx context.Context, userID sql.NullString) ([]GetMessagesFromUserRow, error) {
rows, err := q.db.QueryContext(ctx, getMessagesFromUser, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetMessagesFromUserRow
for rows.Next() {
var i GetMessagesFromUserRow
if err := rows.Scan(
&i.ID,
&i.Body,
&i.HiddenAt,
&i.Timestamp,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getNotificationDestinationsForChannel = `-- name: GetNotificationDestinationsForChannel :many
SELECT destination FROM notifications WHERE channel = $1
`

View File

@@ -79,3 +79,21 @@ CREATE TABLE IF NOT EXISTS auth (
"timestamp" DATE DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE INDEX auth_token ON auth (token);
CREATE TABLE IF NOT EXISTS messages (
"id" string NOT NULL,
"user_id" TEXT,
"body" TEXT,
"eventType" TEXT,
"hidden_at" DATE,
"timestamp" DATE,
"title" TEXT,
"subtitle" TEXT,
"image" TEXT,
"link" TEXT,
PRIMARY KEY (id)
);CREATE INDEX index ON messages (id, user_id, hidden_at, timestamp);
CREATE INDEX id ON messages (id);
CREATE INDEX user_id ON messages (user_id);
CREATE INDEX hidden_at ON messages (hidden_at);
CREATE INDEX timestamp ON messages (timestamp);