This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: answers.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getAnswer = `-- name: GetAnswer :one
|
||||
SELECT a.question_id, a.author_id, u.name AS author_name, a.body, a.created_at, a.updated_at
|
||||
FROM answers a
|
||||
JOIN users u ON u.id = a.author_id
|
||||
WHERE a.question_id = $1
|
||||
`
|
||||
|
||||
type GetAnswerRow struct {
|
||||
QuestionID string
|
||||
AuthorID string
|
||||
AuthorName string
|
||||
Body string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
func (q *Queries) GetAnswer(ctx context.Context, questionID string) (GetAnswerRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAnswer, questionID)
|
||||
var i GetAnswerRow
|
||||
err := row.Scan(
|
||||
&i.QuestionID,
|
||||
&i.AuthorID,
|
||||
&i.AuthorName,
|
||||
&i.Body,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const upsertAnswer = `-- name: UpsertAnswer :exec
|
||||
INSERT INTO answers (question_id, author_id, body, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (question_id) DO UPDATE
|
||||
SET body = excluded.body, author_id = excluded.author_id, updated_at = excluded.updated_at
|
||||
`
|
||||
|
||||
type UpsertAnswerParams struct {
|
||||
QuestionID string
|
||||
AuthorID string
|
||||
Body string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertAnswer(ctx context.Context, arg UpsertAnswerParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertAnswer,
|
||||
arg.QuestionID,
|
||||
arg.AuthorID,
|
||||
arg.Body,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -9,14 +9,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Answer struct {
|
||||
QuestionID string
|
||||
AuthorID string
|
||||
Body string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
type Post struct {
|
||||
ID string
|
||||
ParentID sql.NullString
|
||||
@@ -36,17 +28,6 @@ type PostVote struct {
|
||||
Value int32
|
||||
}
|
||||
|
||||
type Question struct {
|
||||
ID string
|
||||
AuthorID string
|
||||
Title string
|
||||
Body string
|
||||
City string
|
||||
HuntDate string
|
||||
Hidden int32
|
||||
CreatedAt string
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
Token string
|
||||
Data []byte
|
||||
@@ -64,9 +45,3 @@ type User struct {
|
||||
State string
|
||||
CreatedAt string
|
||||
}
|
||||
|
||||
type Vote struct {
|
||||
UserID string
|
||||
QuestionID string
|
||||
Value int32
|
||||
}
|
||||
|
||||
@@ -1,316 +0,0 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: questions.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const createQuestion = `-- name: CreateQuestion :exec
|
||||
INSERT INTO questions (id, author_id, title, body, city, hunt_date, hidden, created_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, 0, $7)
|
||||
`
|
||||
|
||||
type CreateQuestionParams struct {
|
||||
ID string
|
||||
AuthorID string
|
||||
Title string
|
||||
Body string
|
||||
City string
|
||||
HuntDate string
|
||||
CreatedAt string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateQuestion(ctx context.Context, arg CreateQuestionParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createQuestion,
|
||||
arg.ID,
|
||||
arg.AuthorID,
|
||||
arg.Title,
|
||||
arg.Body,
|
||||
arg.City,
|
||||
arg.HuntDate,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const getQuestion = `-- name: GetQuestion :one
|
||||
SELECT q.id, q.author_id, u.name AS author_name, q.title, q.body, q.city, q.hunt_date, q.hidden, q.created_at,
|
||||
COALESCE((SELECT SUM(votes.value) FROM votes WHERE votes.question_id = q.id), 0)::bigint AS score,
|
||||
CASE WHEN a.question_id IS NULL THEN 0 ELSE 1 END::bigint AS answered,
|
||||
COALESCE((
|
||||
SELECT votes.value FROM votes
|
||||
WHERE votes.user_id = $1 AND votes.question_id = q.id
|
||||
), 0)::bigint AS user_vote
|
||||
FROM questions q
|
||||
JOIN users u ON u.id = q.author_id
|
||||
LEFT JOIN answers a ON a.question_id = q.id
|
||||
WHERE q.id = $2
|
||||
`
|
||||
|
||||
type GetQuestionParams struct {
|
||||
ViewerID string
|
||||
ID string
|
||||
}
|
||||
|
||||
type GetQuestionRow struct {
|
||||
ID string
|
||||
AuthorID string
|
||||
AuthorName string
|
||||
Title string
|
||||
Body string
|
||||
City string
|
||||
HuntDate string
|
||||
Hidden int32
|
||||
CreatedAt string
|
||||
Score int64
|
||||
Answered int64
|
||||
UserVote int64
|
||||
}
|
||||
|
||||
func (q *Queries) GetQuestion(ctx context.Context, arg GetQuestionParams) (GetQuestionRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, getQuestion, arg.ViewerID, arg.ID)
|
||||
var i GetQuestionRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AuthorID,
|
||||
&i.AuthorName,
|
||||
&i.Title,
|
||||
&i.Body,
|
||||
&i.City,
|
||||
&i.HuntDate,
|
||||
&i.Hidden,
|
||||
&i.CreatedAt,
|
||||
&i.Score,
|
||||
&i.Answered,
|
||||
&i.UserVote,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const hideQuestion = `-- name: HideQuestion :exec
|
||||
UPDATE questions
|
||||
SET hidden = 1
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) HideQuestion(ctx context.Context, id string) error {
|
||||
_, err := q.db.ExecContext(ctx, hideQuestion, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const listHunt = `-- name: ListHunt :many
|
||||
SELECT q.id, q.author_id, u.name AS author_name, q.title, q.body, q.city, q.hunt_date, q.hidden, q.created_at,
|
||||
COALESCE(SUM(v.value), 0)::bigint AS score,
|
||||
CASE WHEN a.question_id IS NULL THEN 0 ELSE 1 END::bigint AS answered,
|
||||
COALESCE((
|
||||
SELECT votes.value FROM votes
|
||||
WHERE votes.user_id = $1 AND votes.question_id = q.id
|
||||
), 0)::bigint AS user_vote
|
||||
FROM questions q
|
||||
JOIN users u ON u.id = q.author_id
|
||||
LEFT JOIN votes v ON v.question_id = q.id
|
||||
LEFT JOIN answers a ON a.question_id = q.id
|
||||
WHERE q.hunt_date = $2 AND q.hidden = 0
|
||||
GROUP BY q.id, q.author_id, u.name, q.title, q.body, q.city, q.hunt_date, q.hidden, q.created_at, a.question_id
|
||||
ORDER BY score DESC, q.created_at ASC
|
||||
LIMIT $3
|
||||
`
|
||||
|
||||
type ListHuntParams struct {
|
||||
ViewerID string
|
||||
HuntDate string
|
||||
RowLimit int32
|
||||
}
|
||||
|
||||
type ListHuntRow struct {
|
||||
ID string
|
||||
AuthorID string
|
||||
AuthorName string
|
||||
Title string
|
||||
Body string
|
||||
City string
|
||||
HuntDate string
|
||||
Hidden int32
|
||||
CreatedAt string
|
||||
Score int64
|
||||
Answered int64
|
||||
UserVote int64
|
||||
}
|
||||
|
||||
func (q *Queries) ListHunt(ctx context.Context, arg ListHuntParams) ([]ListHuntRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listHunt, arg.ViewerID, arg.HuntDate, arg.RowLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListHuntRow{}
|
||||
for rows.Next() {
|
||||
var i ListHuntRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AuthorID,
|
||||
&i.AuthorName,
|
||||
&i.Title,
|
||||
&i.Body,
|
||||
&i.City,
|
||||
&i.HuntDate,
|
||||
&i.Hidden,
|
||||
&i.CreatedAt,
|
||||
&i.Score,
|
||||
&i.Answered,
|
||||
&i.UserVote,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listQuestionsAnsweredBy = `-- name: ListQuestionsAnsweredBy :many
|
||||
SELECT q.id, q.author_id, u.name AS author_name, q.title, q.body, q.city, q.hunt_date, q.hidden, q.created_at,
|
||||
COALESCE((SELECT SUM(votes.value) FROM votes WHERE votes.question_id = q.id), 0)::bigint AS score,
|
||||
1::bigint AS answered,
|
||||
0::bigint AS user_vote
|
||||
FROM answers ans
|
||||
JOIN questions q ON q.id = ans.question_id
|
||||
JOIN users u ON u.id = q.author_id
|
||||
WHERE ans.author_id = $1 AND q.hidden = 0
|
||||
ORDER BY ans.updated_at DESC
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
type ListQuestionsAnsweredByParams struct {
|
||||
AdminID string
|
||||
RowLimit int32
|
||||
}
|
||||
|
||||
type ListQuestionsAnsweredByRow struct {
|
||||
ID string
|
||||
AuthorID string
|
||||
AuthorName string
|
||||
Title string
|
||||
Body string
|
||||
City string
|
||||
HuntDate string
|
||||
Hidden int32
|
||||
CreatedAt string
|
||||
Score int64
|
||||
Answered int64
|
||||
UserVote int64
|
||||
}
|
||||
|
||||
func (q *Queries) ListQuestionsAnsweredBy(ctx context.Context, arg ListQuestionsAnsweredByParams) ([]ListQuestionsAnsweredByRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listQuestionsAnsweredBy, arg.AdminID, arg.RowLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListQuestionsAnsweredByRow{}
|
||||
for rows.Next() {
|
||||
var i ListQuestionsAnsweredByRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AuthorID,
|
||||
&i.AuthorName,
|
||||
&i.Title,
|
||||
&i.Body,
|
||||
&i.City,
|
||||
&i.HuntDate,
|
||||
&i.Hidden,
|
||||
&i.CreatedAt,
|
||||
&i.Score,
|
||||
&i.Answered,
|
||||
&i.UserVote,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listQuestionsByAuthor = `-- name: ListQuestionsByAuthor :many
|
||||
SELECT q.id, q.author_id, u.name AS author_name, q.title, q.body, q.city, q.hunt_date, q.hidden, q.created_at,
|
||||
COALESCE((SELECT SUM(votes.value) FROM votes WHERE votes.question_id = q.id), 0)::bigint AS score,
|
||||
CASE WHEN a.question_id IS NULL THEN 0 ELSE 1 END::bigint AS answered,
|
||||
0::bigint AS user_vote
|
||||
FROM questions q
|
||||
JOIN users u ON u.id = q.author_id
|
||||
LEFT JOIN answers a ON a.question_id = q.id
|
||||
WHERE q.author_id = $1 AND q.hidden = 0
|
||||
ORDER BY q.created_at DESC
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
type ListQuestionsByAuthorParams struct {
|
||||
AuthorID string
|
||||
RowLimit int32
|
||||
}
|
||||
|
||||
type ListQuestionsByAuthorRow struct {
|
||||
ID string
|
||||
AuthorID string
|
||||
AuthorName string
|
||||
Title string
|
||||
Body string
|
||||
City string
|
||||
HuntDate string
|
||||
Hidden int32
|
||||
CreatedAt string
|
||||
Score int64
|
||||
Answered int64
|
||||
UserVote int64
|
||||
}
|
||||
|
||||
func (q *Queries) ListQuestionsByAuthor(ctx context.Context, arg ListQuestionsByAuthorParams) ([]ListQuestionsByAuthorRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listQuestionsByAuthor, arg.AuthorID, arg.RowLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListQuestionsByAuthorRow{}
|
||||
for rows.Next() {
|
||||
var i ListQuestionsByAuthorRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AuthorID,
|
||||
&i.AuthorName,
|
||||
&i.Title,
|
||||
&i.Body,
|
||||
&i.City,
|
||||
&i.HuntDate,
|
||||
&i.Hidden,
|
||||
&i.CreatedAt,
|
||||
&i.Score,
|
||||
&i.Answered,
|
||||
&i.UserVote,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: votes.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const deleteVote = `-- name: DeleteVote :exec
|
||||
DELETE FROM votes
|
||||
WHERE user_id = $1 AND question_id = $2
|
||||
`
|
||||
|
||||
type DeleteVoteParams struct {
|
||||
UserID string
|
||||
QuestionID string
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteVote(ctx context.Context, arg DeleteVoteParams) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteVote, arg.UserID, arg.QuestionID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getVote = `-- name: GetVote :one
|
||||
SELECT value
|
||||
FROM votes
|
||||
WHERE user_id = $1 AND question_id = $2
|
||||
`
|
||||
|
||||
type GetVoteParams struct {
|
||||
UserID string
|
||||
QuestionID string
|
||||
}
|
||||
|
||||
func (q *Queries) GetVote(ctx context.Context, arg GetVoteParams) (int32, error) {
|
||||
row := q.db.QueryRowContext(ctx, getVote, arg.UserID, arg.QuestionID)
|
||||
var value int32
|
||||
err := row.Scan(&value)
|
||||
return value, err
|
||||
}
|
||||
|
||||
const questionIsVisible = `-- name: QuestionIsVisible :one
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM questions WHERE id = $1 AND hidden = 0
|
||||
)::bool
|
||||
`
|
||||
|
||||
func (q *Queries) QuestionIsVisible(ctx context.Context, id string) (bool, error) {
|
||||
row := q.db.QueryRowContext(ctx, questionIsVisible, id)
|
||||
var column_1 bool
|
||||
err := row.Scan(&column_1)
|
||||
return column_1, err
|
||||
}
|
||||
|
||||
const upsertVoteOnVisible = `-- name: UpsertVoteOnVisible :execrows
|
||||
INSERT INTO votes (user_id, question_id, value)
|
||||
SELECT $1, $2, $3
|
||||
FROM questions q
|
||||
WHERE q.id = $2 AND q.hidden = 0
|
||||
ON CONFLICT (user_id, question_id) DO UPDATE
|
||||
SET value = excluded.value
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM questions q2 WHERE q2.id = excluded.question_id AND q2.hidden = 0
|
||||
)
|
||||
`
|
||||
|
||||
type UpsertVoteOnVisibleParams struct {
|
||||
UserID string
|
||||
QuestionID string
|
||||
Value int32
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertVoteOnVisible(ctx context.Context, arg UpsertVoteOnVisibleParams) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, upsertVoteOnVisible, arg.UserID, arg.QuestionID, arg.Value)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
Reference in New Issue
Block a user