This commit is contained in:
@@ -7,14 +7,10 @@ CREATE TABLE medias (
|
|||||||
original_name VARCHAR(255) NOT NULL,
|
original_name VARCHAR(255) NOT NULL,
|
||||||
mime_type VARCHAR(100) NOT NULL,
|
mime_type VARCHAR(100) NOT NULL,
|
||||||
size BIGINT NOT NULL,
|
size BIGINT NOT NULL,
|
||||||
target_type VARCHAR(50) NOT NULL,
|
|
||||||
target_id UUID NOT NULL,
|
|
||||||
file_metadata JSONB DEFAULT '{}'::jsonb,
|
file_metadata JSONB DEFAULT '{}'::jsonb,
|
||||||
created_at TIMESTAMPTZ DEFAULT now(),
|
created_at TIMESTAMPTZ DEFAULT now(),
|
||||||
updated_at TIMESTAMPTZ DEFAULT now()
|
updated_at TIMESTAMPTZ DEFAULT now()
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_medias_target ON medias (target_type, target_id);
|
|
||||||
CREATE INDEX idx_medias_user_created ON medias (user_id, created_at DESC);
|
CREATE INDEX idx_medias_user_created ON medias (user_id, created_at DESC);
|
||||||
CREATE INDEX idx_medias_original_name_trgm ON medias USING GIN (original_name gin_trgm_ops);
|
CREATE INDEX idx_medias_original_name_trgm ON medias USING GIN (original_name gin_trgm_ops);
|
||||||
CREATE INDEX idx_medias_storage_key_trgm ON medias USING GIN (storage_key gin_trgm_ops);
|
|
||||||
@@ -1,28 +1,27 @@
|
|||||||
CREATE TABLE IF NOT EXISTS user_verifications (
|
CREATE TABLE IF NOT EXISTS user_verifications (
|
||||||
id UUID PRIMARY KEY DEFAULT uuidv7(),
|
id UUID PRIMARY KEY DEFAULT uuidv7(),
|
||||||
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
verify_type SMALLINT NOT NULL, -- 1 = ID_CARD, 2 = EDUCATION, 3 = EXPERT
|
verify_type SMALLINT NOT NULL,
|
||||||
document_url TEXT NOT NULL,
|
|
||||||
is_deleted BOOLEAN NOT NULL DEFAULT false,
|
is_deleted BOOLEAN NOT NULL DEFAULT false,
|
||||||
status SMALLINT NOT NULL DEFAULT 1, -- 1 pending, 2 approved, 3 rejected
|
status SMALLINT NOT NULL DEFAULT 1,
|
||||||
reviewed_by UUID REFERENCES users(id),
|
reviewed_by UUID REFERENCES users(id),
|
||||||
reviewed_at TIMESTAMPTZ,
|
reviewed_at TIMESTAMPTZ,
|
||||||
created_at TIMESTAMPTZ DEFAULT now()
|
created_at TIMESTAMPTZ DEFAULT now()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS verification_medias (
|
||||||
CREATE INDEX idx_user_verifications_user_id
|
verification_id UUID REFERENCES user_verifications(id) ON DELETE CASCADE,
|
||||||
ON user_verifications(user_id)
|
media_id UUID REFERENCES medias(id) ON DELETE CASCADE,
|
||||||
WHERE is_deleted = false;
|
PRIMARY KEY (verification_id, media_id)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_user_verifications_user_type
|
CREATE INDEX idx_user_verifications_user_type
|
||||||
ON user_verifications(user_id, verify_type)
|
ON user_verifications(user_id, verify_type)
|
||||||
WHERE is_deleted = false;
|
WHERE is_deleted = false;
|
||||||
|
|
||||||
CREATE INDEX idx_user_verifications_status
|
|
||||||
ON user_verifications(status)
|
|
||||||
WHERE is_deleted = false;
|
|
||||||
|
|
||||||
CREATE INDEX idx_user_verifications_status_created
|
CREATE INDEX idx_user_verifications_status_created
|
||||||
ON user_verifications(status, created_at DESC)
|
ON user_verifications(status, created_at DESC)
|
||||||
WHERE is_deleted = false;
|
WHERE is_deleted = false;
|
||||||
|
|
||||||
|
CREATE INDEX idx_verification_medias_media_id
|
||||||
|
ON verification_medias(media_id);
|
||||||
@@ -1,16 +1,11 @@
|
|||||||
-- name: CreateMedia :one
|
-- name: CreateMedia :one
|
||||||
INSERT INTO medias (
|
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 (
|
) VALUES (
|
||||||
$1, $2, $3, $4, $5, $6, $7, $8
|
$1, $2, $3, $4, $5, $6
|
||||||
)
|
)
|
||||||
RETURNING *;
|
RETURNING *;
|
||||||
|
|
||||||
-- name: GetMediasByTarget :many
|
|
||||||
SELECT * FROM medias
|
|
||||||
WHERE target_type = $1 AND target_id = $2
|
|
||||||
ORDER BY created_at DESC;
|
|
||||||
|
|
||||||
-- name: DeleteMedia :exec
|
-- name: DeleteMedia :exec
|
||||||
DELETE FROM medias
|
DELETE FROM medias
|
||||||
WHERE id = $1;
|
WHERE id = $1;
|
||||||
@@ -20,7 +15,6 @@ SELECT *
|
|||||||
FROM medias
|
FROM medias
|
||||||
WHERE
|
WHERE
|
||||||
(sqlc.narg('cursor')::uuid IS NULL OR id > sqlc.narg('cursor')::uuid)
|
(sqlc.narg('cursor')::uuid IS NULL OR id > sqlc.narg('cursor')::uuid)
|
||||||
AND (sqlc.narg('target_types')::varchar[] IS NULL OR target_type = ANY(sqlc.narg('target_types')::varchar[]))
|
|
||||||
AND (
|
AND (
|
||||||
sqlc.narg('search_text')::text IS NULL OR
|
sqlc.narg('search_text')::text IS NULL OR
|
||||||
original_name ILIKE '%' || sqlc.narg('search_text')::text || '%' OR
|
original_name ILIKE '%' || sqlc.narg('search_text')::text || '%' OR
|
||||||
|
|||||||
96
db/query/verification.sql
Normal file
96
db/query/verification.sql
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
-- name: CreateUserVerification :one
|
||||||
|
INSERT INTO user_verifications (
|
||||||
|
user_id, verify_type
|
||||||
|
) VALUES (
|
||||||
|
$1, $2
|
||||||
|
)
|
||||||
|
RETURNING *;
|
||||||
|
|
||||||
|
-- name: CreateVerificationMedia :exec
|
||||||
|
INSERT INTO verification_medias (
|
||||||
|
verification_id, media_id
|
||||||
|
) VALUES (
|
||||||
|
$1, $2
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 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;
|
||||||
|
|
||||||
|
-- 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;
|
||||||
|
|
||||||
|
-- name: UpdateUserVerificationStatus :exec
|
||||||
|
UPDATE user_verifications
|
||||||
|
SET
|
||||||
|
status = $2,
|
||||||
|
reviewed_by = $3,
|
||||||
|
reviewed_at = now()
|
||||||
|
WHERE id = $1 AND is_deleted = false;
|
||||||
|
|
||||||
|
-- name: DeleteUserVerification :exec
|
||||||
|
UPDATE user_verifications
|
||||||
|
SET is_deleted = true
|
||||||
|
WHERE id = $1;
|
||||||
|
|
||||||
|
-- name: DeleteVerificationMedia :exec
|
||||||
|
DELETE FROM verification_medias
|
||||||
|
WHERE verification_id = $1 AND media_id = $2;
|
||||||
@@ -39,18 +39,6 @@ CREATE TABLE IF NOT EXISTS user_roles (
|
|||||||
PRIMARY KEY (user_id, role_id)
|
PRIMARY KEY (user_id, role_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS user_verifications (
|
|
||||||
id UUID PRIMARY KEY DEFAULT uuidv7(),
|
|
||||||
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
verify_type SMALLINT NOT NULL, -- 1 = ID_CARD, 2 = EDUCATION, 3 = EXPERT
|
|
||||||
document_url TEXT NOT NULL,
|
|
||||||
status SMALLINT NOT NULL DEFAULT 1, -- 1 pending, 2 approved, 3 rejected
|
|
||||||
reviewed_by UUID REFERENCES users(id),
|
|
||||||
reviewed_at TIMESTAMPTZ,
|
|
||||||
created_at TIMESTAMPTZ DEFAULT now()
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE medias (
|
CREATE TABLE medias (
|
||||||
id UUID PRIMARY KEY DEFAULT uuidv7(),
|
id UUID PRIMARY KEY DEFAULT uuidv7(),
|
||||||
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
@@ -58,9 +46,24 @@ CREATE TABLE medias (
|
|||||||
original_name VARCHAR(255) NOT NULL,
|
original_name VARCHAR(255) NOT NULL,
|
||||||
mime_type VARCHAR(100) NOT NULL,
|
mime_type VARCHAR(100) NOT NULL,
|
||||||
size BIGINT NOT NULL,
|
size BIGINT NOT NULL,
|
||||||
target_type VARCHAR(50) NOT NULL,
|
|
||||||
target_id UUID NOT NULL,
|
|
||||||
file_metadata JSONB DEFAULT '{}'::jsonb,
|
file_metadata JSONB DEFAULT '{}'::jsonb,
|
||||||
created_at TIMESTAMPTZ DEFAULT now(),
|
created_at TIMESTAMPTZ DEFAULT now(),
|
||||||
updated_at TIMESTAMPTZ DEFAULT now()
|
updated_at TIMESTAMPTZ DEFAULT now()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS user_verifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuidv7(),
|
||||||
|
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
verify_type SMALLINT NOT NULL,
|
||||||
|
is_deleted BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
status SMALLINT NOT NULL DEFAULT 1,
|
||||||
|
reviewed_by UUID REFERENCES users(id),
|
||||||
|
reviewed_at TIMESTAMPTZ,
|
||||||
|
created_at TIMESTAMPTZ DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS verification_medias (
|
||||||
|
verification_id UUID REFERENCES user_verifications(id) ON DELETE CASCADE,
|
||||||
|
media_id UUID REFERENCES medias(id) ON DELETE CASCADE,
|
||||||
|
PRIMARY KEY (verification_id, media_id)
|
||||||
|
);
|
||||||
@@ -60,7 +60,7 @@ func (h *AuthController) Signin(c fiber.Ctx) error {
|
|||||||
Value: res.AccessToken,
|
Value: res.AccessToken,
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: c.Protocol() == "https",
|
Secure: c.Protocol() == "https",
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Cookie(&fiber.Cookie{
|
c.Cookie(&fiber.Cookie{
|
||||||
@@ -68,7 +68,7 @@ func (h *AuthController) Signin(c fiber.Ctx) error {
|
|||||||
Value: res.RefreshToken,
|
Value: res.RefreshToken,
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: c.Protocol() == "https",
|
Secure: c.Protocol() == "https",
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
||||||
@@ -113,7 +113,7 @@ func (h *AuthController) Signup(c fiber.Ctx) error {
|
|||||||
Value: res.AccessToken,
|
Value: res.AccessToken,
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: c.Protocol() == "https",
|
Secure: c.Protocol() == "https",
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Cookie(&fiber.Cookie{
|
c.Cookie(&fiber.Cookie{
|
||||||
@@ -121,7 +121,7 @@ func (h *AuthController) Signup(c fiber.Ctx) error {
|
|||||||
Value: res.RefreshToken,
|
Value: res.RefreshToken,
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: c.Protocol() == "https",
|
Secure: c.Protocol() == "https",
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
||||||
@@ -158,7 +158,7 @@ func (h *AuthController) RefreshToken(c fiber.Ctx) error {
|
|||||||
Value: res.AccessToken,
|
Value: res.AccessToken,
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: c.Protocol() == "https",
|
Secure: c.Protocol() == "https",
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Cookie(&fiber.Cookie{
|
c.Cookie(&fiber.Cookie{
|
||||||
@@ -166,7 +166,7 @@ func (h *AuthController) RefreshToken(c fiber.Ctx) error {
|
|||||||
Value: res.RefreshToken,
|
Value: res.RefreshToken,
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: c.Protocol() == "https",
|
Secure: c.Protocol() == "https",
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
|
||||||
@@ -306,7 +306,7 @@ func (h *AuthController) GoogleLogin(c fiber.Ctx) error {
|
|||||||
Expires: time.Now().Add(15 * time.Minute),
|
Expires: time.Now().Add(15 * time.Minute),
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: secure,
|
Secure: secure,
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
url := h.oauth.AuthCodeURL(state)
|
url := h.oauth.AuthCodeURL(state)
|
||||||
@@ -375,7 +375,7 @@ func (h *AuthController) GoogleCallback(c fiber.Ctx) error {
|
|||||||
Value: res.AccessToken,
|
Value: res.AccessToken,
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: c.Protocol() == "https",
|
Secure: c.Protocol() == "https",
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Cookie(&fiber.Cookie{
|
c.Cookie(&fiber.Cookie{
|
||||||
@@ -383,7 +383,7 @@ func (h *AuthController) GoogleCallback(c fiber.Ctx) error {
|
|||||||
Value: res.RefreshToken,
|
Value: res.RefreshToken,
|
||||||
HTTPOnly: true,
|
HTTPOnly: true,
|
||||||
Secure: c.Protocol() == "https",
|
Secure: c.Protocol() == "https",
|
||||||
SameSite: "Lax",
|
SameSite: "None",
|
||||||
})
|
})
|
||||||
|
|
||||||
return c.Redirect().To("http://localhost:5500")
|
return c.Redirect().To("http://localhost:5500")
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ type MediaResponse struct {
|
|||||||
OriginalName string `json:"original_name"`
|
OriginalName string `json:"original_name"`
|
||||||
MimeType string `json:"mime_type"`
|
MimeType string `json:"mime_type"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
TargetType string `json:"target_type"`
|
|
||||||
TargetID string `json:"target_id"`
|
|
||||||
FileMetadata []byte `json:"file_metadata"`
|
FileMetadata []byte `json:"file_metadata"`
|
||||||
CreatedAt *time.Time `json:"created_at"`
|
CreatedAt *time.Time `json:"created_at"`
|
||||||
UpdatedAt *time.Time `json:"updated_at"`
|
UpdatedAt *time.Time `json:"updated_at"`
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ import (
|
|||||||
|
|
||||||
const createMedia = `-- name: CreateMedia :one
|
const createMedia = `-- name: CreateMedia :one
|
||||||
INSERT INTO medias (
|
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 (
|
) 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 {
|
type CreateMediaParams struct {
|
||||||
@@ -26,8 +26,6 @@ type CreateMediaParams struct {
|
|||||||
OriginalName string `json:"original_name"`
|
OriginalName string `json:"original_name"`
|
||||||
MimeType string `json:"mime_type"`
|
MimeType string `json:"mime_type"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
TargetType string `json:"target_type"`
|
|
||||||
TargetID pgtype.UUID `json:"target_id"`
|
|
||||||
FileMetadata []byte `json:"file_metadata"`
|
FileMetadata []byte `json:"file_metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,8 +36,6 @@ func (q *Queries) CreateMedia(ctx context.Context, arg CreateMediaParams) (Media
|
|||||||
arg.OriginalName,
|
arg.OriginalName,
|
||||||
arg.MimeType,
|
arg.MimeType,
|
||||||
arg.Size,
|
arg.Size,
|
||||||
arg.TargetType,
|
|
||||||
arg.TargetID,
|
|
||||||
arg.FileMetadata,
|
arg.FileMetadata,
|
||||||
)
|
)
|
||||||
var i Media
|
var i Media
|
||||||
@@ -50,8 +46,6 @@ func (q *Queries) CreateMedia(ctx context.Context, arg CreateMediaParams) (Media
|
|||||||
&i.OriginalName,
|
&i.OriginalName,
|
||||||
&i.MimeType,
|
&i.MimeType,
|
||||||
&i.Size,
|
&i.Size,
|
||||||
&i.TargetType,
|
|
||||||
&i.TargetID,
|
|
||||||
&i.FileMetadata,
|
&i.FileMetadata,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
@@ -70,7 +64,7 @@ func (q *Queries) DeleteMedia(ctx context.Context, id pgtype.UUID) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getMediaByID = `-- name: GetMediaByID :one
|
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
|
WHERE id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -84,8 +78,6 @@ func (q *Queries) GetMediaByID(ctx context.Context, id pgtype.UUID) (Media, erro
|
|||||||
&i.OriginalName,
|
&i.OriginalName,
|
||||||
&i.MimeType,
|
&i.MimeType,
|
||||||
&i.Size,
|
&i.Size,
|
||||||
&i.TargetType,
|
|
||||||
&i.TargetID,
|
|
||||||
&i.FileMetadata,
|
&i.FileMetadata,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
@@ -93,51 +85,8 @@ func (q *Queries) GetMediaByID(ctx context.Context, id pgtype.UUID) (Media, erro
|
|||||||
return i, err
|
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
|
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
|
WHERE user_id = $1
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
`
|
`
|
||||||
@@ -158,8 +107,6 @@ func (q *Queries) GetMediasByUserID(ctx context.Context, userID pgtype.UUID) ([]
|
|||||||
&i.OriginalName,
|
&i.OriginalName,
|
||||||
&i.MimeType,
|
&i.MimeType,
|
||||||
&i.Size,
|
&i.Size,
|
||||||
&i.TargetType,
|
|
||||||
&i.TargetID,
|
|
||||||
&i.FileMetadata,
|
&i.FileMetadata,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
@@ -175,34 +122,27 @@ func (q *Queries) GetMediasByUserID(ctx context.Context, userID pgtype.UUID) ([]
|
|||||||
}
|
}
|
||||||
|
|
||||||
const searchMedias = `-- name: SearchMedias :many
|
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
|
FROM medias
|
||||||
WHERE
|
WHERE
|
||||||
($1::uuid IS NULL OR id > $1::uuid)
|
($1::uuid IS NULL OR id > $1::uuid)
|
||||||
AND ($2::varchar[] IS NULL OR target_type = ANY($2::varchar[]))
|
|
||||||
AND (
|
AND (
|
||||||
$3::text IS NULL OR
|
$2::text IS NULL OR
|
||||||
original_name ILIKE '%' || $3::text || '%' OR
|
original_name ILIKE '%' || $2::text || '%' OR
|
||||||
storage_key ILIKE '%' || $3::text || '%'
|
storage_key ILIKE '%' || $2::text || '%'
|
||||||
)
|
)
|
||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
LIMIT $4
|
LIMIT $3
|
||||||
`
|
`
|
||||||
|
|
||||||
type SearchMediasParams struct {
|
type SearchMediasParams struct {
|
||||||
Cursor pgtype.UUID `json:"cursor"`
|
Cursor pgtype.UUID `json:"cursor"`
|
||||||
TargetTypes []string `json:"target_types"`
|
SearchText pgtype.Text `json:"search_text"`
|
||||||
SearchText pgtype.Text `json:"search_text"`
|
Limit int32 `json:"limit"`
|
||||||
Limit int32 `json:"limit"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) SearchMedias(ctx context.Context, arg SearchMediasParams) ([]Media, error) {
|
func (q *Queries) SearchMedias(ctx context.Context, arg SearchMediasParams) ([]Media, error) {
|
||||||
rows, err := q.db.Query(ctx, searchMedias,
|
rows, err := q.db.Query(ctx, searchMedias, arg.Cursor, arg.SearchText, arg.Limit)
|
||||||
arg.Cursor,
|
|
||||||
arg.TargetTypes,
|
|
||||||
arg.SearchText,
|
|
||||||
arg.Limit,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -217,8 +157,6 @@ func (q *Queries) SearchMedias(ctx context.Context, arg SearchMediasParams) ([]M
|
|||||||
&i.OriginalName,
|
&i.OriginalName,
|
||||||
&i.MimeType,
|
&i.MimeType,
|
||||||
&i.Size,
|
&i.Size,
|
||||||
&i.TargetType,
|
|
||||||
&i.TargetID,
|
|
||||||
&i.FileMetadata,
|
&i.FileMetadata,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ type Media struct {
|
|||||||
OriginalName string `json:"original_name"`
|
OriginalName string `json:"original_name"`
|
||||||
MimeType string `json:"mime_type"`
|
MimeType string `json:"mime_type"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
TargetType string `json:"target_type"`
|
|
||||||
TargetID pgtype.UUID `json:"target_id"`
|
|
||||||
FileMetadata []byte `json:"file_metadata"`
|
FileMetadata []byte `json:"file_metadata"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
@@ -63,12 +61,17 @@ type UserRole struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserVerification struct {
|
type UserVerification struct {
|
||||||
ID pgtype.UUID `json:"id"`
|
ID pgtype.UUID `json:"id"`
|
||||||
UserID pgtype.UUID `json:"user_id"`
|
UserID pgtype.UUID `json:"user_id"`
|
||||||
VerifyType int16 `json:"verify_type"`
|
VerifyType int16 `json:"verify_type"`
|
||||||
DocumentUrl string `json:"document_url"`
|
IsDeleted bool `json:"is_deleted"`
|
||||||
Status int16 `json:"status"`
|
Status int16 `json:"status"`
|
||||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_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
|
||||||
|
}
|
||||||
@@ -12,8 +12,6 @@ type MediaEntity struct {
|
|||||||
OriginalName string `json:"original_name"`
|
OriginalName string `json:"original_name"`
|
||||||
MimeType string `json:"mime_type"`
|
MimeType string `json:"mime_type"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
TargetType string `json:"target_type"`
|
|
||||||
TargetID string `json:"target_id"`
|
|
||||||
FileMetadata []byte `json:"file_metadata"`
|
FileMetadata []byte `json:"file_metadata"`
|
||||||
CreatedAt *time.Time `json:"created_at"`
|
CreatedAt *time.Time `json:"created_at"`
|
||||||
UpdatedAt *time.Time `json:"updated_at"`
|
UpdatedAt *time.Time `json:"updated_at"`
|
||||||
@@ -27,8 +25,6 @@ func (e *MediaEntity) ToResponse() *response.MediaResponse {
|
|||||||
OriginalName: e.OriginalName,
|
OriginalName: e.OriginalName,
|
||||||
MimeType: e.MimeType,
|
MimeType: e.MimeType,
|
||||||
Size: e.Size,
|
Size: e.Size,
|
||||||
TargetType: e.TargetType,
|
|
||||||
TargetID: e.TargetID,
|
|
||||||
FileMetadata: e.FileMetadata,
|
FileMetadata: e.FileMetadata,
|
||||||
CreatedAt: e.CreatedAt,
|
CreatedAt: e.CreatedAt,
|
||||||
UpdatedAt: e.UpdatedAt,
|
UpdatedAt: e.UpdatedAt,
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ type MediaRepository interface {
|
|||||||
GetByUserID(ctx context.Context, userId pgtype.UUID) ([]*models.MediaEntity, error)
|
GetByUserID(ctx context.Context, userId pgtype.UUID) ([]*models.MediaEntity, error)
|
||||||
Search(ctx context.Context, params sqlc.SearchMediasParams) ([]*models.MediaEntity, error)
|
Search(ctx context.Context, params sqlc.SearchMediasParams) ([]*models.MediaEntity, error)
|
||||||
Delete(ctx context.Context, id pgtype.UUID) error
|
Delete(ctx context.Context, id pgtype.UUID) error
|
||||||
GetByTarget(ctx context.Context, params sqlc.GetMediasByTargetParams) ([]*models.MediaEntity, error)
|
|
||||||
Create(ctx context.Context, params sqlc.CreateMediaParams) (*models.MediaEntity, error)
|
Create(ctx context.Context, params sqlc.CreateMediaParams) (*models.MediaEntity, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +100,6 @@ func (r *mediaRepository) GetByID(ctx context.Context, id pgtype.UUID) (*models.
|
|||||||
OriginalName: row.OriginalName,
|
OriginalName: row.OriginalName,
|
||||||
MimeType: row.MimeType,
|
MimeType: row.MimeType,
|
||||||
Size: row.Size,
|
Size: row.Size,
|
||||||
TargetType: row.TargetType,
|
|
||||||
TargetID: convert.UUIDToString(row.TargetID),
|
|
||||||
FileMetadata: row.FileMetadata,
|
FileMetadata: row.FileMetadata,
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
@@ -133,8 +130,6 @@ func (r *mediaRepository) Create(ctx context.Context, params sqlc.CreateMediaPar
|
|||||||
OriginalName: row.OriginalName,
|
OriginalName: row.OriginalName,
|
||||||
MimeType: row.MimeType,
|
MimeType: row.MimeType,
|
||||||
Size: row.Size,
|
Size: row.Size,
|
||||||
TargetType: row.TargetType,
|
|
||||||
TargetID: convert.UUIDToString(row.TargetID),
|
|
||||||
FileMetadata: row.FileMetadata,
|
FileMetadata: row.FileMetadata,
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
@@ -156,52 +151,6 @@ func (r *mediaRepository) Delete(ctx context.Context, id pgtype.UUID) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mediaRepository) GetByTarget(ctx context.Context, params sqlc.GetMediasByTargetParams) ([]*models.MediaEntity, error) {
|
|
||||||
queryKey := r.generateQueryKey("media:target", params)
|
|
||||||
var cachedIDs []string
|
|
||||||
if err := r.c.Get(ctx, queryKey, &cachedIDs); err == nil && len(cachedIDs) > 0 {
|
|
||||||
return r.getByIDsWithFallback(ctx, cachedIDs)
|
|
||||||
}
|
|
||||||
|
|
||||||
rows, err := r.q.GetMediasByTarget(ctx, params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var medias []*models.MediaEntity
|
|
||||||
var ids []string
|
|
||||||
mediasToCache := make(map[string]any)
|
|
||||||
|
|
||||||
for _, row := range rows {
|
|
||||||
media := &models.MediaEntity{
|
|
||||||
ID: convert.UUIDToString(row.ID),
|
|
||||||
UserID: convert.UUIDToString(row.UserID),
|
|
||||||
StorageKey: row.StorageKey,
|
|
||||||
OriginalName: row.OriginalName,
|
|
||||||
MimeType: row.MimeType,
|
|
||||||
Size: row.Size,
|
|
||||||
TargetType: row.TargetType,
|
|
||||||
TargetID: convert.UUIDToString(row.TargetID),
|
|
||||||
FileMetadata: row.FileMetadata,
|
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
|
||||||
}
|
|
||||||
ids = append(ids, media.ID)
|
|
||||||
medias = append(medias, media)
|
|
||||||
|
|
||||||
mediasToCache[fmt.Sprintf("media:id:%s", media.ID)] = media
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(mediasToCache) > 0 {
|
|
||||||
_ = r.c.MSet(ctx, mediasToCache, constants.NormalCacheDuration)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ids) > 0 {
|
|
||||||
_ = r.c.Set(ctx, queryKey, ids, constants.ListCacheDuration)
|
|
||||||
}
|
|
||||||
|
|
||||||
return medias, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *mediaRepository) Search(ctx context.Context, params sqlc.SearchMediasParams) ([]*models.MediaEntity, error) {
|
func (r *mediaRepository) Search(ctx context.Context, params sqlc.SearchMediasParams) ([]*models.MediaEntity, error) {
|
||||||
queryKey := r.generateQueryKey("media:search", params)
|
queryKey := r.generateQueryKey("media:search", params)
|
||||||
var cachedIDs []string
|
var cachedIDs []string
|
||||||
@@ -225,8 +174,6 @@ func (r *mediaRepository) Search(ctx context.Context, params sqlc.SearchMediasPa
|
|||||||
OriginalName: row.OriginalName,
|
OriginalName: row.OriginalName,
|
||||||
MimeType: row.MimeType,
|
MimeType: row.MimeType,
|
||||||
Size: row.Size,
|
Size: row.Size,
|
||||||
TargetType: row.TargetType,
|
|
||||||
TargetID: convert.UUIDToString(row.TargetID),
|
|
||||||
FileMetadata: row.FileMetadata,
|
FileMetadata: row.FileMetadata,
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
@@ -271,8 +218,6 @@ func (r *mediaRepository) GetByUserID(ctx context.Context, userId pgtype.UUID) (
|
|||||||
OriginalName: row.OriginalName,
|
OriginalName: row.OriginalName,
|
||||||
MimeType: row.MimeType,
|
MimeType: row.MimeType,
|
||||||
Size: row.Size,
|
Size: row.Size,
|
||||||
TargetType: row.TargetType,
|
|
||||||
TargetID: convert.UUIDToString(row.TargetID),
|
|
||||||
FileMetadata: row.FileMetadata,
|
FileMetadata: row.FileMetadata,
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
|
|||||||
Reference in New Issue
Block a user