initial commit
This commit is contained in:
713
internal/database/responses.sql.go
Normal file
713
internal/database/responses.sql.go
Normal file
@@ -0,0 +1,713 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: responses.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const AcceptVolunteerResponse = `-- name: AcceptVolunteerResponse :exec
|
||||
UPDATE volunteer_responses SET
|
||||
status = 'accepted',
|
||||
accepted_at = CURRENT_TIMESTAMP,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) AcceptVolunteerResponse(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, AcceptVolunteerResponse, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const CalculateVolunteerAverageRating = `-- name: CalculateVolunteerAverageRating :one
|
||||
SELECT
|
||||
COALESCE(AVG(rating), 0) as average_rating,
|
||||
COUNT(*) as total_ratings
|
||||
FROM ratings
|
||||
WHERE volunteer_id = $1
|
||||
`
|
||||
|
||||
type CalculateVolunteerAverageRatingRow struct {
|
||||
AverageRating interface{} `json:"average_rating"`
|
||||
TotalRatings int64 `json:"total_ratings"`
|
||||
}
|
||||
|
||||
func (q *Queries) CalculateVolunteerAverageRating(ctx context.Context, volunteerID int64) (CalculateVolunteerAverageRatingRow, error) {
|
||||
row := q.db.QueryRow(ctx, CalculateVolunteerAverageRating, volunteerID)
|
||||
var i CalculateVolunteerAverageRatingRow
|
||||
err := row.Scan(&i.AverageRating, &i.TotalRatings)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const CallAcceptVolunteerResponse = `-- name: CallAcceptVolunteerResponse :one
|
||||
|
||||
SELECT
|
||||
r.success::BOOLEAN,
|
||||
r.message::TEXT,
|
||||
r.out_request_id::BIGINT,
|
||||
r.out_volunteer_id::BIGINT
|
||||
FROM accept_volunteer_response($1, $2) AS r(success, message, out_request_id, out_volunteer_id)
|
||||
`
|
||||
|
||||
type CallAcceptVolunteerResponseParams struct {
|
||||
PResponseID int64 `json:"p_response_id"`
|
||||
PRequesterID int64 `json:"p_requester_id"`
|
||||
}
|
||||
|
||||
type CallAcceptVolunteerResponseRow struct {
|
||||
Success bool `json:"r_success"`
|
||||
Message string `json:"r_message"`
|
||||
RequestID int64 `json:"r_out_request_id"`
|
||||
VolunteerID int64 `json:"r_out_volunteer_id"`
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Хранимые процедуры
|
||||
// ============================================================================
|
||||
func (q *Queries) CallAcceptVolunteerResponse(ctx context.Context, arg CallAcceptVolunteerResponseParams) (CallAcceptVolunteerResponseRow, error) {
|
||||
row := q.db.QueryRow(ctx, CallAcceptVolunteerResponse, arg.PResponseID, arg.PRequesterID)
|
||||
var i CallAcceptVolunteerResponseRow
|
||||
err := row.Scan(
|
||||
&i.Success,
|
||||
&i.Message,
|
||||
&i.RequestID,
|
||||
&i.VolunteerID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const CallCompleteRequestWithRating = `-- name: CallCompleteRequestWithRating :one
|
||||
SELECT
|
||||
r.success::BOOLEAN,
|
||||
r.message::TEXT,
|
||||
r.out_rating_id::BIGINT
|
||||
FROM complete_request_with_rating($1, $2, $3, $4) AS r(success, message, out_rating_id)
|
||||
`
|
||||
|
||||
type CallCompleteRequestWithRatingParams struct {
|
||||
PRequestID int64 `json:"p_request_id"`
|
||||
PRequesterID int64 `json:"p_requester_id"`
|
||||
PRating int32 `json:"p_rating"`
|
||||
Comment pgtype.Text `json:"comment"`
|
||||
}
|
||||
|
||||
type CallCompleteRequestWithRatingRow struct {
|
||||
Success bool `json:"r_success"`
|
||||
Message string `json:"r_message"`
|
||||
RatingID int64 `json:"r_out_rating_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CallCompleteRequestWithRating(ctx context.Context, arg CallCompleteRequestWithRatingParams) (CallCompleteRequestWithRatingRow, error) {
|
||||
row := q.db.QueryRow(ctx, CallCompleteRequestWithRating,
|
||||
arg.PRequestID,
|
||||
arg.PRequesterID,
|
||||
arg.PRating,
|
||||
arg.Comment,
|
||||
)
|
||||
var i CallCompleteRequestWithRatingRow
|
||||
err := row.Scan(&i.Success, &i.Message, &i.RatingID)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const CallModerateRequest = `-- name: CallModerateRequest :one
|
||||
SELECT
|
||||
r.success::BOOLEAN,
|
||||
r.message::TEXT
|
||||
FROM moderate_request($1, $2, $3, $4) AS r(success, message)
|
||||
`
|
||||
|
||||
type CallModerateRequestParams struct {
|
||||
PRequestID int64 `json:"p_request_id"`
|
||||
PModeratorID int64 `json:"p_moderator_id"`
|
||||
PAction string `json:"p_action"`
|
||||
Comment pgtype.Text `json:"comment"`
|
||||
}
|
||||
|
||||
type CallModerateRequestRow struct {
|
||||
Success bool `json:"r_success"`
|
||||
Message string `json:"r_message"`
|
||||
}
|
||||
|
||||
func (q *Queries) CallModerateRequest(ctx context.Context, arg CallModerateRequestParams) (CallModerateRequestRow, error) {
|
||||
row := q.db.QueryRow(ctx, CallModerateRequest,
|
||||
arg.PRequestID,
|
||||
arg.PModeratorID,
|
||||
arg.PAction,
|
||||
arg.Comment,
|
||||
)
|
||||
var i CallModerateRequestRow
|
||||
err := row.Scan(&i.Success, &i.Message)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const CountPendingResponsesByVolunteer = `-- name: CountPendingResponsesByVolunteer :one
|
||||
SELECT COUNT(*) FROM volunteer_responses
|
||||
WHERE volunteer_id = $1 AND status = 'pending'
|
||||
`
|
||||
|
||||
func (q *Queries) CountPendingResponsesByVolunteer(ctx context.Context, volunteerID int64) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, CountPendingResponsesByVolunteer, volunteerID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const CountResponsesByRequest = `-- name: CountResponsesByRequest :one
|
||||
SELECT COUNT(*) FROM volunteer_responses
|
||||
WHERE request_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) CountResponsesByRequest(ctx context.Context, requestID int64) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, CountResponsesByRequest, requestID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const CreateRating = `-- name: CreateRating :one
|
||||
|
||||
INSERT INTO ratings (
|
||||
volunteer_response_id,
|
||||
volunteer_id,
|
||||
requester_id,
|
||||
request_id,
|
||||
rating,
|
||||
comment
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6
|
||||
) RETURNING id, volunteer_response_id, volunteer_id, requester_id, request_id, rating, comment, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateRatingParams struct {
|
||||
VolunteerResponseID int64 `json:"volunteer_response_id"`
|
||||
VolunteerID int64 `json:"volunteer_id"`
|
||||
RequesterID int64 `json:"requester_id"`
|
||||
RequestID int64 `json:"request_id"`
|
||||
Rating int32 `json:"rating"`
|
||||
Comment pgtype.Text `json:"comment"`
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Рейтинги
|
||||
// ============================================================================
|
||||
func (q *Queries) CreateRating(ctx context.Context, arg CreateRatingParams) (Rating, error) {
|
||||
row := q.db.QueryRow(ctx, CreateRating,
|
||||
arg.VolunteerResponseID,
|
||||
arg.VolunteerID,
|
||||
arg.RequesterID,
|
||||
arg.RequestID,
|
||||
arg.Rating,
|
||||
arg.Comment,
|
||||
)
|
||||
var i Rating
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.VolunteerResponseID,
|
||||
&i.VolunteerID,
|
||||
&i.RequesterID,
|
||||
&i.RequestID,
|
||||
&i.Rating,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const CreateStatusHistoryEntry = `-- name: CreateStatusHistoryEntry :one
|
||||
|
||||
INSERT INTO request_status_history (
|
||||
request_id,
|
||||
from_status,
|
||||
to_status,
|
||||
changed_by,
|
||||
comment
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5
|
||||
) RETURNING id, request_id, from_status, to_status, changed_by, comment, created_at
|
||||
`
|
||||
|
||||
type CreateStatusHistoryEntryParams struct {
|
||||
RequestID int64 `json:"request_id"`
|
||||
FromStatus NullRequestStatus `json:"from_status"`
|
||||
ToStatus RequestStatus `json:"to_status"`
|
||||
ChangedBy int64 `json:"changed_by"`
|
||||
Comment pgtype.Text `json:"comment"`
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// История изменения статусов заявок
|
||||
// ============================================================================
|
||||
func (q *Queries) CreateStatusHistoryEntry(ctx context.Context, arg CreateStatusHistoryEntryParams) (RequestStatusHistory, error) {
|
||||
row := q.db.QueryRow(ctx, CreateStatusHistoryEntry,
|
||||
arg.RequestID,
|
||||
arg.FromStatus,
|
||||
arg.ToStatus,
|
||||
arg.ChangedBy,
|
||||
arg.Comment,
|
||||
)
|
||||
var i RequestStatusHistory
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.RequestID,
|
||||
&i.FromStatus,
|
||||
&i.ToStatus,
|
||||
&i.ChangedBy,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const CreateVolunteerResponse = `-- name: CreateVolunteerResponse :one
|
||||
|
||||
|
||||
INSERT INTO volunteer_responses (
|
||||
request_id,
|
||||
volunteer_id,
|
||||
message
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3
|
||||
)
|
||||
ON CONFLICT (request_id, volunteer_id) DO NOTHING
|
||||
RETURNING id, request_id, volunteer_id, status, message, responded_at, accepted_at, rejected_at, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateVolunteerResponseParams struct {
|
||||
RequestID int64 `json:"request_id"`
|
||||
VolunteerID int64 `json:"volunteer_id"`
|
||||
Message pgtype.Text `json:"message"`
|
||||
}
|
||||
|
||||
// Фаза 3: Отклики волонтеров и история статусов (СРЕДНИЙ ПРИОРИТЕТ)
|
||||
// Запросы для управления откликами волонтеров и историей изменения статусов заявок
|
||||
// ============================================================================
|
||||
// Отклики волонтеров
|
||||
// ============================================================================
|
||||
func (q *Queries) CreateVolunteerResponse(ctx context.Context, arg CreateVolunteerResponseParams) (VolunteerResponse, error) {
|
||||
row := q.db.QueryRow(ctx, CreateVolunteerResponse, arg.RequestID, arg.VolunteerID, arg.Message)
|
||||
var i VolunteerResponse
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.RequestID,
|
||||
&i.VolunteerID,
|
||||
&i.Status,
|
||||
&i.Message,
|
||||
&i.RespondedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.RejectedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const GetLatestStatusChange = `-- name: GetLatestStatusChange :one
|
||||
SELECT
|
||||
rsh.id, rsh.request_id, rsh.from_status, rsh.to_status, rsh.changed_by, rsh.comment, rsh.created_at,
|
||||
(u.first_name || ' ' || u.last_name) as changed_by_name
|
||||
FROM request_status_history rsh
|
||||
JOIN users u ON u.id = rsh.changed_by
|
||||
WHERE rsh.request_id = $1
|
||||
ORDER BY rsh.created_at DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type GetLatestStatusChangeRow struct {
|
||||
ID int64 `json:"id"`
|
||||
RequestID int64 `json:"request_id"`
|
||||
FromStatus NullRequestStatus `json:"from_status"`
|
||||
ToStatus RequestStatus `json:"to_status"`
|
||||
ChangedBy int64 `json:"changed_by"`
|
||||
Comment pgtype.Text `json:"comment"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
ChangedByName interface{} `json:"changed_by_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetLatestStatusChange(ctx context.Context, requestID int64) (GetLatestStatusChangeRow, error) {
|
||||
row := q.db.QueryRow(ctx, GetLatestStatusChange, requestID)
|
||||
var i GetLatestStatusChangeRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.RequestID,
|
||||
&i.FromStatus,
|
||||
&i.ToStatus,
|
||||
&i.ChangedBy,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
&i.ChangedByName,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const GetRatingByResponseID = `-- name: GetRatingByResponseID :one
|
||||
SELECT id, volunteer_response_id, volunteer_id, requester_id, request_id, rating, comment, created_at, updated_at FROM ratings
|
||||
WHERE volunteer_response_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetRatingByResponseID(ctx context.Context, volunteerResponseID int64) (Rating, error) {
|
||||
row := q.db.QueryRow(ctx, GetRatingByResponseID, volunteerResponseID)
|
||||
var i Rating
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.VolunteerResponseID,
|
||||
&i.VolunteerID,
|
||||
&i.RequesterID,
|
||||
&i.RequestID,
|
||||
&i.Rating,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const GetRatingsByVolunteer = `-- name: GetRatingsByVolunteer :many
|
||||
SELECT
|
||||
r.id, r.volunteer_response_id, r.volunteer_id, r.requester_id, r.request_id, r.rating, r.comment, r.created_at, r.updated_at,
|
||||
req.title as request_title,
|
||||
(u.first_name || ' ' || u.last_name) as requester_name
|
||||
FROM ratings r
|
||||
JOIN requests req ON req.id = r.request_id
|
||||
JOIN users u ON u.id = r.requester_id
|
||||
WHERE r.volunteer_id = $1
|
||||
ORDER BY r.created_at DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
type GetRatingsByVolunteerParams struct {
|
||||
VolunteerID int64 `json:"volunteer_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
type GetRatingsByVolunteerRow struct {
|
||||
ID int64 `json:"id"`
|
||||
VolunteerResponseID int64 `json:"volunteer_response_id"`
|
||||
VolunteerID int64 `json:"volunteer_id"`
|
||||
RequesterID int64 `json:"requester_id"`
|
||||
RequestID int64 `json:"request_id"`
|
||||
Rating int32 `json:"rating"`
|
||||
Comment pgtype.Text `json:"comment"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
RequestTitle string `json:"request_title"`
|
||||
RequesterName interface{} `json:"requester_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetRatingsByVolunteer(ctx context.Context, arg GetRatingsByVolunteerParams) ([]GetRatingsByVolunteerRow, error) {
|
||||
rows, err := q.db.Query(ctx, GetRatingsByVolunteer, arg.VolunteerID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GetRatingsByVolunteerRow{}
|
||||
for rows.Next() {
|
||||
var i GetRatingsByVolunteerRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.VolunteerResponseID,
|
||||
&i.VolunteerID,
|
||||
&i.RequesterID,
|
||||
&i.RequestID,
|
||||
&i.Rating,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.RequestTitle,
|
||||
&i.RequesterName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const GetRequestStatusHistory = `-- name: GetRequestStatusHistory :many
|
||||
SELECT
|
||||
rsh.id, rsh.request_id, rsh.from_status, rsh.to_status, rsh.changed_by, rsh.comment, rsh.created_at,
|
||||
(u.first_name || ' ' || u.last_name) as changed_by_name
|
||||
FROM request_status_history rsh
|
||||
JOIN users u ON u.id = rsh.changed_by
|
||||
WHERE rsh.request_id = $1
|
||||
ORDER BY rsh.created_at DESC
|
||||
`
|
||||
|
||||
type GetRequestStatusHistoryRow struct {
|
||||
ID int64 `json:"id"`
|
||||
RequestID int64 `json:"request_id"`
|
||||
FromStatus NullRequestStatus `json:"from_status"`
|
||||
ToStatus RequestStatus `json:"to_status"`
|
||||
ChangedBy int64 `json:"changed_by"`
|
||||
Comment pgtype.Text `json:"comment"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
ChangedByName interface{} `json:"changed_by_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetRequestStatusHistory(ctx context.Context, requestID int64) ([]GetRequestStatusHistoryRow, error) {
|
||||
rows, err := q.db.Query(ctx, GetRequestStatusHistory, requestID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GetRequestStatusHistoryRow{}
|
||||
for rows.Next() {
|
||||
var i GetRequestStatusHistoryRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.RequestID,
|
||||
&i.FromStatus,
|
||||
&i.ToStatus,
|
||||
&i.ChangedBy,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
&i.ChangedByName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const GetResponseByID = `-- name: GetResponseByID :one
|
||||
SELECT
|
||||
vr.id, vr.request_id, vr.volunteer_id, vr.status, vr.message, vr.responded_at, vr.accepted_at, vr.rejected_at, vr.created_at, vr.updated_at,
|
||||
(u.first_name || ' ' || u.last_name) as volunteer_name,
|
||||
r.title as request_title
|
||||
FROM volunteer_responses vr
|
||||
JOIN users u ON u.id = vr.volunteer_id
|
||||
JOIN requests r ON r.id = vr.request_id
|
||||
WHERE vr.id = $1
|
||||
`
|
||||
|
||||
type GetResponseByIDRow struct {
|
||||
ID int64 `json:"id"`
|
||||
RequestID int64 `json:"request_id"`
|
||||
VolunteerID int64 `json:"volunteer_id"`
|
||||
Status NullResponseStatus `json:"status"`
|
||||
Message pgtype.Text `json:"message"`
|
||||
RespondedAt pgtype.Timestamptz `json:"responded_at"`
|
||||
AcceptedAt pgtype.Timestamptz `json:"accepted_at"`
|
||||
RejectedAt pgtype.Timestamptz `json:"rejected_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
VolunteerName interface{} `json:"volunteer_name"`
|
||||
RequestTitle string `json:"request_title"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetResponseByID(ctx context.Context, id int64) (GetResponseByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, GetResponseByID, id)
|
||||
var i GetResponseByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.RequestID,
|
||||
&i.VolunteerID,
|
||||
&i.Status,
|
||||
&i.Message,
|
||||
&i.RespondedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.RejectedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.VolunteerName,
|
||||
&i.RequestTitle,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const GetResponsesByRequest = `-- name: GetResponsesByRequest :many
|
||||
SELECT
|
||||
vr.id, vr.request_id, vr.volunteer_id, vr.status, vr.message, vr.responded_at, vr.accepted_at, vr.rejected_at, vr.created_at, vr.updated_at,
|
||||
(u.first_name || ' ' || u.last_name) as volunteer_name,
|
||||
u.avatar_url as volunteer_avatar,
|
||||
u.volunteer_rating,
|
||||
u.completed_requests_count,
|
||||
u.email as volunteer_email,
|
||||
u.phone as volunteer_phone
|
||||
FROM volunteer_responses vr
|
||||
JOIN users u ON u.id = vr.volunteer_id
|
||||
WHERE vr.request_id = $1
|
||||
ORDER BY vr.created_at DESC
|
||||
`
|
||||
|
||||
type GetResponsesByRequestRow struct {
|
||||
ID int64 `json:"id"`
|
||||
RequestID int64 `json:"request_id"`
|
||||
VolunteerID int64 `json:"volunteer_id"`
|
||||
Status NullResponseStatus `json:"status"`
|
||||
Message pgtype.Text `json:"message"`
|
||||
RespondedAt pgtype.Timestamptz `json:"responded_at"`
|
||||
AcceptedAt pgtype.Timestamptz `json:"accepted_at"`
|
||||
RejectedAt pgtype.Timestamptz `json:"rejected_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
VolunteerName interface{} `json:"volunteer_name"`
|
||||
VolunteerAvatar pgtype.Text `json:"volunteer_avatar"`
|
||||
VolunteerRating pgtype.Numeric `json:"volunteer_rating"`
|
||||
CompletedRequestsCount pgtype.Int4 `json:"completed_requests_count"`
|
||||
VolunteerEmail string `json:"volunteer_email"`
|
||||
VolunteerPhone pgtype.Text `json:"volunteer_phone"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetResponsesByRequest(ctx context.Context, requestID int64) ([]GetResponsesByRequestRow, error) {
|
||||
rows, err := q.db.Query(ctx, GetResponsesByRequest, requestID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GetResponsesByRequestRow{}
|
||||
for rows.Next() {
|
||||
var i GetResponsesByRequestRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.RequestID,
|
||||
&i.VolunteerID,
|
||||
&i.Status,
|
||||
&i.Message,
|
||||
&i.RespondedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.RejectedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.VolunteerName,
|
||||
&i.VolunteerAvatar,
|
||||
&i.VolunteerRating,
|
||||
&i.CompletedRequestsCount,
|
||||
&i.VolunteerEmail,
|
||||
&i.VolunteerPhone,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const GetResponsesByVolunteer = `-- name: GetResponsesByVolunteer :many
|
||||
SELECT
|
||||
vr.id, vr.request_id, vr.volunteer_id, vr.status, vr.message, vr.responded_at, vr.accepted_at, vr.rejected_at, vr.created_at, vr.updated_at,
|
||||
r.title as request_title,
|
||||
r.status as request_status,
|
||||
(u.first_name || ' ' || u.last_name) as requester_name
|
||||
FROM volunteer_responses vr
|
||||
JOIN requests r ON r.id = vr.request_id
|
||||
JOIN users u ON u.id = r.requester_id
|
||||
WHERE vr.volunteer_id = $1
|
||||
ORDER BY vr.created_at DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
type GetResponsesByVolunteerParams struct {
|
||||
VolunteerID int64 `json:"volunteer_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
type GetResponsesByVolunteerRow struct {
|
||||
ID int64 `json:"id"`
|
||||
RequestID int64 `json:"request_id"`
|
||||
VolunteerID int64 `json:"volunteer_id"`
|
||||
Status NullResponseStatus `json:"status"`
|
||||
Message pgtype.Text `json:"message"`
|
||||
RespondedAt pgtype.Timestamptz `json:"responded_at"`
|
||||
AcceptedAt pgtype.Timestamptz `json:"accepted_at"`
|
||||
RejectedAt pgtype.Timestamptz `json:"rejected_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
RequestTitle string `json:"request_title"`
|
||||
RequestStatus NullRequestStatus `json:"request_status"`
|
||||
RequesterName interface{} `json:"requester_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetResponsesByVolunteer(ctx context.Context, arg GetResponsesByVolunteerParams) ([]GetResponsesByVolunteerRow, error) {
|
||||
rows, err := q.db.Query(ctx, GetResponsesByVolunteer, arg.VolunteerID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GetResponsesByVolunteerRow{}
|
||||
for rows.Next() {
|
||||
var i GetResponsesByVolunteerRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.RequestID,
|
||||
&i.VolunteerID,
|
||||
&i.Status,
|
||||
&i.Message,
|
||||
&i.RespondedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.RejectedAt,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.RequestTitle,
|
||||
&i.RequestStatus,
|
||||
&i.RequesterName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const RejectVolunteerResponse = `-- name: RejectVolunteerResponse :exec
|
||||
UPDATE volunteer_responses SET
|
||||
status = 'rejected',
|
||||
rejected_at = CURRENT_TIMESTAMP,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) RejectVolunteerResponse(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, RejectVolunteerResponse, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const UpdateRating = `-- name: UpdateRating :exec
|
||||
UPDATE ratings SET
|
||||
rating = $2,
|
||||
comment = $3,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type UpdateRatingParams struct {
|
||||
ID int64 `json:"id"`
|
||||
Rating int32 `json:"rating"`
|
||||
Comment pgtype.Text `json:"comment"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateRating(ctx context.Context, arg UpdateRatingParams) error {
|
||||
_, err := q.db.Exec(ctx, UpdateRating, arg.ID, arg.Rating, arg.Comment)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user