- Removed detailed event routes from the API. - Added new report request routes for creating and fetching report requests. - Introduced new domain models for report requests, including metadata and status handling. - Implemented report request processing logic, including CSV generation for event interval reports. - Enhanced company statistics handling with new domain models and service methods. - Updated repository interfaces and implementations to support new report functionalities. - Added error handling and logging for report file operations and notifications.
287 lines
6.5 KiB
Go
287 lines
6.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: report.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateReportRequest = `-- name: CreateReportRequest :one
|
|
INSERT INTO report_requests (
|
|
company_id,
|
|
requested_by,
|
|
type,
|
|
metadata
|
|
)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING id, company_id, requested_by, file_path, type, status, metadata, reject_reason, created_at, completed_at
|
|
`
|
|
|
|
type CreateReportRequestParams struct {
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
RequestedBy pgtype.Int8 `json:"requested_by"`
|
|
Type string `json:"type"`
|
|
Metadata []byte `json:"metadata"`
|
|
}
|
|
|
|
func (q *Queries) CreateReportRequest(ctx context.Context, arg CreateReportRequestParams) (ReportRequest, error) {
|
|
row := q.db.QueryRow(ctx, CreateReportRequest,
|
|
arg.CompanyID,
|
|
arg.RequestedBy,
|
|
arg.Type,
|
|
arg.Metadata,
|
|
)
|
|
var i ReportRequest
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.RequestedBy,
|
|
&i.FilePath,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.Metadata,
|
|
&i.RejectReason,
|
|
&i.CreatedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetAllReportRequests = `-- name: GetAllReportRequests :many
|
|
SELECT id, company_id, requested_by, file_path, type, status, metadata, reject_reason, created_at, completed_at, company_name, company_slug, requester_first_name, requester_last_name
|
|
FROM report_request_detail
|
|
WHERE (
|
|
company_id = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
type = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
status = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
requested_by = $4
|
|
OR $4 IS NULL
|
|
)
|
|
ORDER BY id DESC
|
|
LIMIT $6 OFFSET $5
|
|
`
|
|
|
|
type GetAllReportRequestsParams struct {
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Type pgtype.Text `json:"type"`
|
|
Status pgtype.Text `json:"status"`
|
|
RequestedBy pgtype.Int8 `json:"requested_by"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) GetAllReportRequests(ctx context.Context, arg GetAllReportRequestsParams) ([]ReportRequestDetail, error) {
|
|
rows, err := q.db.Query(ctx, GetAllReportRequests,
|
|
arg.CompanyID,
|
|
arg.Type,
|
|
arg.Status,
|
|
arg.RequestedBy,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ReportRequestDetail
|
|
for rows.Next() {
|
|
var i ReportRequestDetail
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.RequestedBy,
|
|
&i.FilePath,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.Metadata,
|
|
&i.RejectReason,
|
|
&i.CreatedAt,
|
|
&i.CompletedAt,
|
|
&i.CompanyName,
|
|
&i.CompanySlug,
|
|
&i.RequesterFirstName,
|
|
&i.RequesterLastName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetReportRequestByID = `-- name: GetReportRequestByID :one
|
|
SELECT id, company_id, requested_by, file_path, type, status, metadata, reject_reason, created_at, completed_at, company_name, company_slug, requester_first_name, requester_last_name
|
|
FROM report_request_detail
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetReportRequestByID(ctx context.Context, id int64) (ReportRequestDetail, error) {
|
|
row := q.db.QueryRow(ctx, GetReportRequestByID, id)
|
|
var i ReportRequestDetail
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.RequestedBy,
|
|
&i.FilePath,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.Metadata,
|
|
&i.RejectReason,
|
|
&i.CreatedAt,
|
|
&i.CompletedAt,
|
|
&i.CompanyName,
|
|
&i.CompanySlug,
|
|
&i.RequesterFirstName,
|
|
&i.RequesterLastName,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetReportRequestByRequestedByID = `-- name: GetReportRequestByRequestedByID :many
|
|
SELECT id, company_id, requested_by, file_path, type, status, metadata, reject_reason, created_at, completed_at, company_name, company_slug, requester_first_name, requester_last_name
|
|
FROM report_request_detail
|
|
WHERE requested_by = $1
|
|
AND (
|
|
type = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
status = $3
|
|
OR $3 IS NULL
|
|
)
|
|
ORDER BY id DESC
|
|
LIMIT $5 OFFSET $4
|
|
`
|
|
|
|
type GetReportRequestByRequestedByIDParams struct {
|
|
RequestedBy pgtype.Int8 `json:"requested_by"`
|
|
Type pgtype.Text `json:"type"`
|
|
Status pgtype.Text `json:"status"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) GetReportRequestByRequestedByID(ctx context.Context, arg GetReportRequestByRequestedByIDParams) ([]ReportRequestDetail, error) {
|
|
rows, err := q.db.Query(ctx, GetReportRequestByRequestedByID,
|
|
arg.RequestedBy,
|
|
arg.Type,
|
|
arg.Status,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ReportRequestDetail
|
|
for rows.Next() {
|
|
var i ReportRequestDetail
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.RequestedBy,
|
|
&i.FilePath,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.Metadata,
|
|
&i.RejectReason,
|
|
&i.CreatedAt,
|
|
&i.CompletedAt,
|
|
&i.CompanyName,
|
|
&i.CompanySlug,
|
|
&i.RequesterFirstName,
|
|
&i.RequesterLastName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetTotalReportRequests = `-- name: GetTotalReportRequests :one
|
|
SELECT COUNT(id)
|
|
FROM report_request_detail
|
|
WHERE (
|
|
company_id = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
type = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
status = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
requested_by = $4
|
|
OR $4 IS NULL
|
|
)
|
|
`
|
|
|
|
type GetTotalReportRequestsParams struct {
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Type pgtype.Text `json:"type"`
|
|
Status pgtype.Text `json:"status"`
|
|
RequestedBy pgtype.Int8 `json:"requested_by"`
|
|
}
|
|
|
|
func (q *Queries) GetTotalReportRequests(ctx context.Context, arg GetTotalReportRequestsParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetTotalReportRequests,
|
|
arg.CompanyID,
|
|
arg.Type,
|
|
arg.Status,
|
|
arg.RequestedBy,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const UpdateReportRequest = `-- name: UpdateReportRequest :exec
|
|
UPDATE report_requests
|
|
SET file_path = COALESCE($2, file_path),
|
|
reject_reason = COALESCE($3, reject_reason),
|
|
status = COALESCE($4, status),
|
|
completed_at = now()
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateReportRequestParams struct {
|
|
ID int64 `json:"id"`
|
|
FilePath pgtype.Text `json:"file_path"`
|
|
RejectReason pgtype.Text `json:"reject_reason"`
|
|
Status pgtype.Text `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateReportRequest(ctx context.Context, arg UpdateReportRequestParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateReportRequest,
|
|
arg.ID,
|
|
arg.FilePath,
|
|
arg.RejectReason,
|
|
arg.Status,
|
|
)
|
|
return err
|
|
}
|