feat: implemented /users/{id} api route
This commit is contained in:
parent
71e2661fb9
commit
948e036e8c
10 changed files with 381 additions and 982 deletions
|
|
@ -25,7 +25,7 @@ CREATE TABLE images (
|
|||
|
||||
CREATE TABLE users (
|
||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
avatar_id int REFERENCES images (id),
|
||||
avatar_id bigint REFERENCES images (id),
|
||||
passhash text NOT NULL,
|
||||
mail text CHECK (mail ~ '[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+'),
|
||||
nickname text NOT NULL CHECK (nickname ~ '^[a-zA-Z0-9_-]+$'),
|
||||
|
|
@ -38,7 +38,7 @@ CREATE TABLE users (
|
|||
CREATE TABLE studios (
|
||||
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
studio_name text UNIQUE,
|
||||
illust_id int REFERENCES images (id),
|
||||
illust_id bigint REFERENCES images (id),
|
||||
studio_desc text
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package sqlc
|
|||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
|
@ -185,48 +186,42 @@ func (ns NullUsertitleStatusT) Value() (driver.Value, error) {
|
|||
}
|
||||
|
||||
type Image struct {
|
||||
ImageID int32 `json:"image_id"`
|
||||
ID int64 `json:"id"`
|
||||
StorageType StorageTypeT `json:"storage_type"`
|
||||
ImagePath string `json:"image_path"`
|
||||
}
|
||||
|
||||
type Provider struct {
|
||||
ProviderID int32 `json:"provider_id"`
|
||||
ID int64 `json:"id"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
}
|
||||
|
||||
type Review struct {
|
||||
ReviewID int32 `json:"review_id"`
|
||||
UserID int32 `json:"user_id"`
|
||||
TitleID int32 `json:"title_id"`
|
||||
ReviewText string `json:"review_text"`
|
||||
CreationDate pgtype.Timestamp `json:"creation_date"`
|
||||
Credentials []byte `json:"credentials"`
|
||||
}
|
||||
|
||||
type Signal struct {
|
||||
SignalID int32 `json:"signal_id"`
|
||||
ID int64 `json:"id"`
|
||||
TitleID *int64 `json:"title_id"`
|
||||
RawData []byte `json:"raw_data"`
|
||||
ProviderID int32 `json:"provider_id"`
|
||||
Dirty bool `json:"dirty"`
|
||||
ProviderID int64 `json:"provider_id"`
|
||||
Pending bool `json:"pending"`
|
||||
}
|
||||
|
||||
type Studio struct {
|
||||
StudioID int32 `json:"studio_id"`
|
||||
ID int64 `json:"id"`
|
||||
StudioName *string `json:"studio_name"`
|
||||
IllustID *int32 `json:"illust_id"`
|
||||
IllustID *int64 `json:"illust_id"`
|
||||
StudioDesc *string `json:"studio_desc"`
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
TagID int32 `json:"tag_id"`
|
||||
ID int64 `json:"id"`
|
||||
TagNames []byte `json:"tag_names"`
|
||||
}
|
||||
|
||||
type Title struct {
|
||||
TitleID int32 `json:"title_id"`
|
||||
ID int64 `json:"id"`
|
||||
TitleNames []byte `json:"title_names"`
|
||||
StudioID int32 `json:"studio_id"`
|
||||
PosterID *int32 `json:"poster_id"`
|
||||
StudioID int64 `json:"studio_id"`
|
||||
PosterID *int64 `json:"poster_id"`
|
||||
TitleStatus TitleStatusT `json:"title_status"`
|
||||
Rating *float64 `json:"rating"`
|
||||
RatingCount *int32 `json:"rating_count"`
|
||||
|
|
@ -239,26 +234,27 @@ type Title struct {
|
|||
}
|
||||
|
||||
type TitleTag struct {
|
||||
TitleID int32 `json:"title_id"`
|
||||
TagID int32 `json:"tag_id"`
|
||||
TitleID int64 `json:"title_id"`
|
||||
TagID int64 `json:"tag_id"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
UserID int32 `json:"user_id"`
|
||||
AvatarID *int32 `json:"avatar_id"`
|
||||
Passhash string `json:"passhash"`
|
||||
Mail *string `json:"mail"`
|
||||
Nickname string `json:"nickname"`
|
||||
DispName *string `json:"disp_name"`
|
||||
UserDesc *string `json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `json:"creation_date"`
|
||||
ID int64 `json:"id"`
|
||||
AvatarID *int64 `json:"avatar_id"`
|
||||
Passhash string `json:"passhash"`
|
||||
Mail *string `json:"mail"`
|
||||
Nickname string `json:"nickname"`
|
||||
DispName *string `json:"disp_name"`
|
||||
UserDesc *string `json:"user_desc"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
LastLogin pgtype.Timestamptz `json:"last_login"`
|
||||
}
|
||||
|
||||
type Usertitle struct {
|
||||
UsertitleID int32 `json:"usertitle_id"`
|
||||
UserID int32 `json:"user_id"`
|
||||
TitleID int32 `json:"title_id"`
|
||||
Status UsertitleStatusT `json:"status"`
|
||||
Rate *int32 `json:"rate"`
|
||||
ReviewID *int32 `json:"review_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
TitleID int64 `json:"title_id"`
|
||||
Status UsertitleStatusT `json:"status"`
|
||||
Rate *int32 `json:"rate"`
|
||||
ReviewText *string `json:"review_text"`
|
||||
ReviewDate pgtype.Timestamptz `json:"review_date"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,17 +7,67 @@ package sqlc
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const getImageByID = `-- name: GetImageByID :one
|
||||
SELECT image_id, storage_type, image_path
|
||||
FROM images
|
||||
WHERE image_id = $1
|
||||
const createImage = `-- name: CreateImage :one
|
||||
INSERT INTO images (storage_type, image_path)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id, storage_type, image_path
|
||||
`
|
||||
|
||||
func (q *Queries) GetImageByID(ctx context.Context, imageID int32) (Image, error) {
|
||||
row := q.db.QueryRow(ctx, getImageByID, imageID)
|
||||
type CreateImageParams struct {
|
||||
StorageType StorageTypeT `json:"storage_type"`
|
||||
ImagePath string `json:"image_path"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateImage(ctx context.Context, arg CreateImageParams) (Image, error) {
|
||||
row := q.db.QueryRow(ctx, createImage, arg.StorageType, arg.ImagePath)
|
||||
var i Image
|
||||
err := row.Scan(&i.ImageID, &i.StorageType, &i.ImagePath)
|
||||
err := row.Scan(&i.ID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getImageByID = `-- name: GetImageByID :one
|
||||
SELECT id, storage_type, image_path
|
||||
FROM images
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetImageByID(ctx context.Context, id int64) (Image, error) {
|
||||
row := q.db.QueryRow(ctx, getImageByID, id)
|
||||
var i Image
|
||||
err := row.Scan(&i.ID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, avatar_id, mail, nickname, disp_name, user_desc, creation_date
|
||||
FROM users
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type GetUserByIDRow struct {
|
||||
ID int64 `json:"id"`
|
||||
AvatarID *int64 `json:"avatar_id"`
|
||||
Mail *string `json:"mail"`
|
||||
Nickname string `json:"nickname"`
|
||||
DispName *string `json:"disp_name"`
|
||||
UserDesc *string `json:"user_desc"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id int64) (GetUserByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByID, id)
|
||||
var i GetUserByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AvatarID,
|
||||
&i.Mail,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,4 +11,17 @@ sql:
|
|||
sql_package: "pgx/v5"
|
||||
sql_driver: "github.com/jackc/pgx/v5"
|
||||
emit_json_tags: true
|
||||
emit_pointers_for_null_types: true
|
||||
emit_pointers_for_null_types: true
|
||||
overrides:
|
||||
- db_type: "uuid"
|
||||
nullable: false
|
||||
go_type:
|
||||
import: "github.com/gofrs/uuid"
|
||||
package: "gofrsuuid"
|
||||
type: UUID
|
||||
pointer: true
|
||||
- db_type: "timestamptz"
|
||||
nullable: false
|
||||
go_type:
|
||||
import: "time"
|
||||
type: "Time"
|
||||
Loading…
Add table
Add a link
Reference in a new issue