Align schema, API routes, and auth with updated admin domain model.

Rename users table fields and loan documents table, expand branch billing credentials, switch to /api/admin prefix, refactor auth endpoints, replace PATCH with PUT for status updates, remove file upload APIs, and regenerate Swagger with ordered tags.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-06 14:09:45 +05:00
parent 0c717101da
commit 82e1aad016
22 changed files with 4248 additions and 418 deletions

View File

@@ -22,7 +22,7 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) province.Re
}
func (r *repository) List(ctx context.Context) ([]province.ProvinceDTO, error) {
rows, err := r.client.Query(ctx, `SELECT id, title FROM province ORDER BY id`)
rows, err := r.client.Query(ctx, `SELECT id, title, status FROM provinces ORDER BY id`)
if err != nil {
return nil, err
}
@@ -41,7 +41,7 @@ func (r *repository) List(ctx context.Context) ([]province.ProvinceDTO, error) {
}
func (r *repository) GetByID(ctx context.Context, id int64) (province.ProvinceDTO, error) {
row := r.client.QueryRow(ctx, `SELECT id, title FROM province WHERE id = $1`, id)
row := r.client.QueryRow(ctx, `SELECT id, title, status FROM provinces WHERE id = $1`, id)
item, err := scanProvince(row)
if errors.Is(err, pgx.ErrNoRows) {
return province.ProvinceDTO{}, err
@@ -55,7 +55,15 @@ func (r *repository) Create(ctx context.Context, dto province.CreateProvinceDTO)
return province.ProvinceDTO{}, err
}
row := r.client.QueryRow(ctx, `INSERT INTO province (title) VALUES ($1) RETURNING id, title`, title)
status := true
if dto.Status != nil {
status = *dto.Status
}
row := r.client.QueryRow(ctx,
`INSERT INTO provinces (title, status) VALUES ($1, $2) RETURNING id, title, status`,
title, status,
)
return scanProvince(row)
}
@@ -66,8 +74,8 @@ func (r *repository) Update(ctx context.Context, id int64, dto province.UpdatePr
}
row := r.client.QueryRow(ctx,
`UPDATE province SET title = $1 WHERE id = $2 RETURNING id, title`,
title, id,
`UPDATE provinces SET title = $1, status = $2 WHERE id = $3 RETURNING id, title, status`,
title, dto.Status, id,
)
item, err := scanProvince(row)
if errors.Is(err, pgx.ErrNoRows) {
@@ -77,7 +85,7 @@ func (r *repository) Update(ctx context.Context, id int64, dto province.UpdatePr
}
func (r *repository) Delete(ctx context.Context, id int64) error {
tag, err := r.client.Exec(ctx, `DELETE FROM province WHERE id = $1`, id)
tag, err := r.client.Exec(ctx, `DELETE FROM provinces WHERE id = $1`, id)
if err != nil {
return err
}
@@ -94,7 +102,7 @@ type scannable interface {
func scanProvince(row scannable) (province.ProvinceDTO, error) {
var item province.ProvinceDTO
var titleJSON []byte
if err := row.Scan(&item.Id, &titleJSON); err != nil {
if err := row.Scan(&item.Id, &titleJSON, &item.Status); err != nil {
return province.ProvinceDTO{}, err
}
if err := json.Unmarshal(titleJSON, &item.Title); err != nil {