This commit is contained in:
@@ -13,11 +13,11 @@ import (
|
||||
|
||||
const createMedia = `-- name: CreateMedia :one
|
||||
INSERT INTO medias (
|
||||
user_id, storage_key, original_name, mime_type, size, target_type, target_id, file_metadata
|
||||
user_id, storage_key, original_name, mime_type, size, file_metadata
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, $8
|
||||
$1, $2, $3, $4, $5, $6
|
||||
)
|
||||
RETURNING id, user_id, storage_key, original_name, mime_type, size, target_type, target_id, file_metadata, created_at, updated_at
|
||||
RETURNING id, user_id, storage_key, original_name, mime_type, size, file_metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateMediaParams struct {
|
||||
@@ -26,8 +26,6 @@ type CreateMediaParams struct {
|
||||
OriginalName string `json:"original_name"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Size int64 `json:"size"`
|
||||
TargetType string `json:"target_type"`
|
||||
TargetID pgtype.UUID `json:"target_id"`
|
||||
FileMetadata []byte `json:"file_metadata"`
|
||||
}
|
||||
|
||||
@@ -38,8 +36,6 @@ func (q *Queries) CreateMedia(ctx context.Context, arg CreateMediaParams) (Media
|
||||
arg.OriginalName,
|
||||
arg.MimeType,
|
||||
arg.Size,
|
||||
arg.TargetType,
|
||||
arg.TargetID,
|
||||
arg.FileMetadata,
|
||||
)
|
||||
var i Media
|
||||
@@ -50,8 +46,6 @@ func (q *Queries) CreateMedia(ctx context.Context, arg CreateMediaParams) (Media
|
||||
&i.OriginalName,
|
||||
&i.MimeType,
|
||||
&i.Size,
|
||||
&i.TargetType,
|
||||
&i.TargetID,
|
||||
&i.FileMetadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
@@ -70,7 +64,7 @@ func (q *Queries) DeleteMedia(ctx context.Context, id pgtype.UUID) error {
|
||||
}
|
||||
|
||||
const getMediaByID = `-- name: GetMediaByID :one
|
||||
SELECT id, user_id, storage_key, original_name, mime_type, size, target_type, target_id, file_metadata, created_at, updated_at FROM medias
|
||||
SELECT id, user_id, storage_key, original_name, mime_type, size, file_metadata, created_at, updated_at FROM medias
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
@@ -84,8 +78,6 @@ func (q *Queries) GetMediaByID(ctx context.Context, id pgtype.UUID) (Media, erro
|
||||
&i.OriginalName,
|
||||
&i.MimeType,
|
||||
&i.Size,
|
||||
&i.TargetType,
|
||||
&i.TargetID,
|
||||
&i.FileMetadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
@@ -93,51 +85,8 @@ func (q *Queries) GetMediaByID(ctx context.Context, id pgtype.UUID) (Media, erro
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getMediasByTarget = `-- name: GetMediasByTarget :many
|
||||
SELECT id, user_id, storage_key, original_name, mime_type, size, target_type, target_id, file_metadata, created_at, updated_at FROM medias
|
||||
WHERE target_type = $1 AND target_id = $2
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
type GetMediasByTargetParams struct {
|
||||
TargetType string `json:"target_type"`
|
||||
TargetID pgtype.UUID `json:"target_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetMediasByTarget(ctx context.Context, arg GetMediasByTargetParams) ([]Media, error) {
|
||||
rows, err := q.db.Query(ctx, getMediasByTarget, arg.TargetType, arg.TargetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Media{}
|
||||
for rows.Next() {
|
||||
var i Media
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.StorageKey,
|
||||
&i.OriginalName,
|
||||
&i.MimeType,
|
||||
&i.Size,
|
||||
&i.TargetType,
|
||||
&i.TargetID,
|
||||
&i.FileMetadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getMediasByUserID = `-- name: GetMediasByUserID :many
|
||||
SELECT id, user_id, storage_key, original_name, mime_type, size, target_type, target_id, file_metadata, created_at, updated_at FROM medias
|
||||
SELECT id, user_id, storage_key, original_name, mime_type, size, file_metadata, created_at, updated_at FROM medias
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
@@ -158,8 +107,6 @@ func (q *Queries) GetMediasByUserID(ctx context.Context, userID pgtype.UUID) ([]
|
||||
&i.OriginalName,
|
||||
&i.MimeType,
|
||||
&i.Size,
|
||||
&i.TargetType,
|
||||
&i.TargetID,
|
||||
&i.FileMetadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
@@ -175,34 +122,27 @@ func (q *Queries) GetMediasByUserID(ctx context.Context, userID pgtype.UUID) ([]
|
||||
}
|
||||
|
||||
const searchMedias = `-- name: SearchMedias :many
|
||||
SELECT id, user_id, storage_key, original_name, mime_type, size, target_type, target_id, file_metadata, created_at, updated_at
|
||||
SELECT id, user_id, storage_key, original_name, mime_type, size, file_metadata, created_at, updated_at
|
||||
FROM medias
|
||||
WHERE
|
||||
($1::uuid IS NULL OR id > $1::uuid)
|
||||
AND ($2::varchar[] IS NULL OR target_type = ANY($2::varchar[]))
|
||||
AND (
|
||||
$3::text IS NULL OR
|
||||
original_name ILIKE '%' || $3::text || '%' OR
|
||||
storage_key ILIKE '%' || $3::text || '%'
|
||||
$2::text IS NULL OR
|
||||
original_name ILIKE '%' || $2::text || '%' OR
|
||||
storage_key ILIKE '%' || $2::text || '%'
|
||||
)
|
||||
ORDER BY id ASC
|
||||
LIMIT $4
|
||||
LIMIT $3
|
||||
`
|
||||
|
||||
type SearchMediasParams struct {
|
||||
Cursor pgtype.UUID `json:"cursor"`
|
||||
TargetTypes []string `json:"target_types"`
|
||||
SearchText pgtype.Text `json:"search_text"`
|
||||
Limit int32 `json:"limit"`
|
||||
Cursor pgtype.UUID `json:"cursor"`
|
||||
SearchText pgtype.Text `json:"search_text"`
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchMedias(ctx context.Context, arg SearchMediasParams) ([]Media, error) {
|
||||
rows, err := q.db.Query(ctx, searchMedias,
|
||||
arg.Cursor,
|
||||
arg.TargetTypes,
|
||||
arg.SearchText,
|
||||
arg.Limit,
|
||||
)
|
||||
rows, err := q.db.Query(ctx, searchMedias, arg.Cursor, arg.SearchText, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -217,8 +157,6 @@ func (q *Queries) SearchMedias(ctx context.Context, arg SearchMediasParams) ([]M
|
||||
&i.OriginalName,
|
||||
&i.MimeType,
|
||||
&i.Size,
|
||||
&i.TargetType,
|
||||
&i.TargetID,
|
||||
&i.FileMetadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
|
||||
@@ -15,8 +15,6 @@ type Media struct {
|
||||
OriginalName string `json:"original_name"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Size int64 `json:"size"`
|
||||
TargetType string `json:"target_type"`
|
||||
TargetID pgtype.UUID `json:"target_id"`
|
||||
FileMetadata []byte `json:"file_metadata"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
@@ -63,12 +61,17 @@ type UserRole struct {
|
||||
}
|
||||
|
||||
type UserVerification struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
VerifyType int16 `json:"verify_type"`
|
||||
DocumentUrl string `json:"document_url"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
VerifyType int16 `json:"verify_type"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type VerificationMedia struct {
|
||||
VerificationID pgtype.UUID `json:"verification_id"`
|
||||
MediaID pgtype.UUID `json:"media_id"`
|
||||
}
|
||||
|
||||
244
internal/gen/sqlc/verification.sql.go
Normal file
244
internal/gen/sqlc/verification.sql.go
Normal file
@@ -0,0 +1,244 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: verification.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createUserVerification = `-- name: CreateUserVerification :one
|
||||
INSERT INTO user_verifications (
|
||||
user_id, verify_type
|
||||
) VALUES (
|
||||
$1, $2
|
||||
)
|
||||
RETURNING id, user_id, verify_type, is_deleted, status, reviewed_by, reviewed_at, created_at
|
||||
`
|
||||
|
||||
type CreateUserVerificationParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
VerifyType int16 `json:"verify_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUserVerification(ctx context.Context, arg CreateUserVerificationParams) (UserVerification, error) {
|
||||
row := q.db.QueryRow(ctx, createUserVerification, arg.UserID, arg.VerifyType)
|
||||
var i UserVerification
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.VerifyType,
|
||||
&i.IsDeleted,
|
||||
&i.Status,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createVerificationMedia = `-- name: CreateVerificationMedia :exec
|
||||
INSERT INTO verification_medias (
|
||||
verification_id, media_id
|
||||
) VALUES (
|
||||
$1, $2
|
||||
)
|
||||
`
|
||||
|
||||
type CreateVerificationMediaParams struct {
|
||||
VerificationID pgtype.UUID `json:"verification_id"`
|
||||
MediaID pgtype.UUID `json:"media_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateVerificationMedia(ctx context.Context, arg CreateVerificationMediaParams) error {
|
||||
_, err := q.db.Exec(ctx, createVerificationMedia, arg.VerificationID, arg.MediaID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteUserVerification = `-- name: DeleteUserVerification :exec
|
||||
UPDATE user_verifications
|
||||
SET is_deleted = true
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUserVerification(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteUserVerification, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteVerificationMedia = `-- name: DeleteVerificationMedia :exec
|
||||
DELETE FROM verification_medias
|
||||
WHERE verification_id = $1 AND media_id = $2
|
||||
`
|
||||
|
||||
type DeleteVerificationMediaParams struct {
|
||||
VerificationID pgtype.UUID `json:"verification_id"`
|
||||
MediaID pgtype.UUID `json:"media_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteVerificationMedia(ctx context.Context, arg DeleteVerificationMediaParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteVerificationMedia, arg.VerificationID, arg.MediaID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getUserVerificationByID = `-- name: GetUserVerificationByID :one
|
||||
SELECT
|
||||
uv.id,
|
||||
uv.user_id,
|
||||
uv.verify_type,
|
||||
uv.is_deleted,
|
||||
uv.status,
|
||||
uv.reviewed_by,
|
||||
uv.reviewed_at,
|
||||
uv.created_at,
|
||||
(
|
||||
SELECT COALESCE(
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id', m.id,
|
||||
'storage_key', m.storage_key,
|
||||
'original_name', m.original_name,
|
||||
'mime_type', m.mime_type,
|
||||
'size', m.size,
|
||||
'file_metadata', m.file_metadata,
|
||||
'created_at', m.created_at
|
||||
)
|
||||
),
|
||||
'[]'
|
||||
)::json
|
||||
FROM verification_medias vm
|
||||
JOIN medias m ON vm.media_id = m.id
|
||||
WHERE vm.verification_id = uv.id
|
||||
) AS medias
|
||||
FROM user_verifications uv
|
||||
WHERE uv.id = $1 AND uv.is_deleted = false
|
||||
`
|
||||
|
||||
type GetUserVerificationByIDRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
VerifyType int16 `json:"verify_type"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Medias []byte `json:"medias"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserVerificationByID(ctx context.Context, id pgtype.UUID) (GetUserVerificationByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUserVerificationByID, id)
|
||||
var i GetUserVerificationByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.VerifyType,
|
||||
&i.IsDeleted,
|
||||
&i.Status,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedAt,
|
||||
&i.Medias,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserVerifications = `-- name: GetUserVerifications :many
|
||||
SELECT
|
||||
uv.id,
|
||||
uv.user_id,
|
||||
uv.verify_type,
|
||||
uv.is_deleted,
|
||||
uv.status,
|
||||
uv.reviewed_by,
|
||||
uv.reviewed_at,
|
||||
uv.created_at,
|
||||
(
|
||||
SELECT COALESCE(
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id', m.id,
|
||||
'storage_key', m.storage_key,
|
||||
'original_name', m.original_name,
|
||||
'mime_type', m.mime_type,
|
||||
'size', m.size,
|
||||
'file_metadata', m.file_metadata,
|
||||
'created_at', m.created_at
|
||||
)
|
||||
),
|
||||
'[]'
|
||||
)::json
|
||||
FROM verification_medias vm
|
||||
JOIN medias m ON vm.media_id = m.id
|
||||
WHERE vm.verification_id = uv.id
|
||||
) AS medias
|
||||
FROM user_verifications uv
|
||||
WHERE uv.user_id = $1 AND uv.is_deleted = false
|
||||
ORDER BY uv.created_at DESC
|
||||
`
|
||||
|
||||
type GetUserVerificationsRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
VerifyType int16 `json:"verify_type"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Medias []byte `json:"medias"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserVerifications(ctx context.Context, userID pgtype.UUID) ([]GetUserVerificationsRow, error) {
|
||||
rows, err := q.db.Query(ctx, getUserVerifications, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GetUserVerificationsRow{}
|
||||
for rows.Next() {
|
||||
var i GetUserVerificationsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.VerifyType,
|
||||
&i.IsDeleted,
|
||||
&i.Status,
|
||||
&i.ReviewedBy,
|
||||
&i.ReviewedAt,
|
||||
&i.CreatedAt,
|
||||
&i.Medias,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateUserVerificationStatus = `-- name: UpdateUserVerificationStatus :exec
|
||||
UPDATE user_verifications
|
||||
SET
|
||||
status = $2,
|
||||
reviewed_by = $3,
|
||||
reviewed_at = now()
|
||||
WHERE id = $1 AND is_deleted = false
|
||||
`
|
||||
|
||||
type UpdateUserVerificationStatusParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Status int16 `json:"status"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserVerificationStatus(ctx context.Context, arg UpdateUserVerificationStatusParams) error {
|
||||
_, err := q.db.Exec(ctx, updateUserVerificationStatus, arg.ID, arg.Status, arg.ReviewedBy)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user