Migration 000065 adds nullable gender text column; persona API and Postman expose it alongside profile_picture. Co-authored-by: Cursor <cursoragent@cursor.com>
194 lines
4.7 KiB
Go
194 lines
4.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: lms_personas.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateLmsPersona = `-- name: CreateLmsPersona :one
|
|
INSERT INTO lms_personas (name, description, profile_picture, gender, is_active)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING id, name, description, profile_picture, is_active, created_at, updated_at, gender
|
|
`
|
|
|
|
type CreateLmsPersonaParams struct {
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
ProfilePicture pgtype.Text `json:"profile_picture"`
|
|
Gender pgtype.Text `json:"gender"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) CreateLmsPersona(ctx context.Context, arg CreateLmsPersonaParams) (LmsPersona, error) {
|
|
row := q.db.QueryRow(ctx, CreateLmsPersona,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.ProfilePicture,
|
|
arg.Gender,
|
|
arg.IsActive,
|
|
)
|
|
var i LmsPersona
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProfilePicture,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Gender,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteLmsPersona = `-- name: DeleteLmsPersona :exec
|
|
DELETE FROM lms_personas
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteLmsPersona(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteLmsPersona, id)
|
|
return err
|
|
}
|
|
|
|
const GetLmsPersonaByID = `-- name: GetLmsPersonaByID :one
|
|
SELECT id, name, description, profile_picture, is_active, created_at, updated_at, gender
|
|
FROM lms_personas
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetLmsPersonaByID(ctx context.Context, id int64) (LmsPersona, error) {
|
|
row := q.db.QueryRow(ctx, GetLmsPersonaByID, id)
|
|
var i LmsPersona
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProfilePicture,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Gender,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListLmsPersonas = `-- name: ListLmsPersonas :many
|
|
SELECT
|
|
COUNT(*) OVER () AS total_count,
|
|
p.id,
|
|
p.name,
|
|
p.description,
|
|
p.profile_picture,
|
|
p.gender,
|
|
p.is_active,
|
|
p.created_at,
|
|
p.updated_at
|
|
FROM lms_personas p
|
|
WHERE (
|
|
$3::boolean = FALSE
|
|
OR p.is_active = TRUE
|
|
)
|
|
ORDER BY p.name ASC, p.created_at DESC
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListLmsPersonasParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
FilterActive bool `json:"filter_active"`
|
|
}
|
|
|
|
type ListLmsPersonasRow struct {
|
|
TotalCount int64 `json:"total_count"`
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
ProfilePicture pgtype.Text `json:"profile_picture"`
|
|
Gender pgtype.Text `json:"gender"`
|
|
IsActive bool `json:"is_active"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) ListLmsPersonas(ctx context.Context, arg ListLmsPersonasParams) ([]ListLmsPersonasRow, error) {
|
|
rows, err := q.db.Query(ctx, ListLmsPersonas, arg.Limit, arg.Offset, arg.FilterActive)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListLmsPersonasRow
|
|
for rows.Next() {
|
|
var i ListLmsPersonasRow
|
|
if err := rows.Scan(
|
|
&i.TotalCount,
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProfilePicture,
|
|
&i.Gender,
|
|
&i.IsActive,
|
|
&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 UpdateLmsPersona = `-- name: UpdateLmsPersona :one
|
|
UPDATE lms_personas
|
|
SET
|
|
name = COALESCE($1::varchar, name),
|
|
description = COALESCE($2::text, description),
|
|
profile_picture = COALESCE($3::text, profile_picture),
|
|
gender = COALESCE($4::text, gender),
|
|
is_active = COALESCE($5::boolean, is_active),
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $6
|
|
RETURNING id, name, description, profile_picture, is_active, created_at, updated_at, gender
|
|
`
|
|
|
|
type UpdateLmsPersonaParams struct {
|
|
Name pgtype.Text `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
ProfilePicture pgtype.Text `json:"profile_picture"`
|
|
Gender pgtype.Text `json:"gender"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateLmsPersona(ctx context.Context, arg UpdateLmsPersonaParams) (LmsPersona, error) {
|
|
row := q.db.QueryRow(ctx, UpdateLmsPersona,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.ProfilePicture,
|
|
arg.Gender,
|
|
arg.IsActive,
|
|
arg.ID,
|
|
)
|
|
var i LmsPersona
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProfilePicture,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Gender,
|
|
)
|
|
return i, err
|
|
}
|