Done (probably) with sql requests
This commit is contained in:
parent
ae9bd6f9d6
commit
0aa9f78d07
@ -1,6 +1,6 @@
|
||||
import { Button, Card, ChevronDownIcon, Text } from "@radix-ui/themes";
|
||||
import * as NavigationMenu from "@radix-ui/react-navigation-menu";
|
||||
import { Link, useLocation, useNavigate } from "react-router-dom";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
|
||||
export default function NavBar() {
|
||||
return (
|
||||
@ -18,7 +18,7 @@ export default function NavBar() {
|
||||
<NavigationMenu.Trigger className="flex items-center">
|
||||
<Button
|
||||
asChild
|
||||
className="w-fit h-fit rounded-full m-0 p-0 pr-2 pl-2 mt-2 mb-2 duration-[50ms]"
|
||||
className="w-fit pr-2 h-fit rounded-full m-0 p-0 pl-2 mt-2 mb-2 duration-[50ms]"
|
||||
variant="ghost"
|
||||
highContrast
|
||||
>
|
||||
|
||||
103
enshi_back/db/go_queries/bookmarks_queries.sql.go
Normal file
103
enshi_back/db/go_queries/bookmarks_queries.sql.go
Normal file
@ -0,0 +1,103 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
// source: bookmarks_queries.sql
|
||||
|
||||
package db_repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createBookmark = `-- name: CreateBookmark :one
|
||||
INSERT INTO public.bookmarks
|
||||
(user_id, post_id, bookmarked_at)
|
||||
VALUES($1, $2, CURRENT_TIMESTAMP)
|
||||
RETURNING user_id, post_id, bookmarked_at
|
||||
`
|
||||
|
||||
type CreateBookmarkParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
PostID int64 `json:"post_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBookmark(ctx context.Context, arg CreateBookmarkParams) (Bookmark, error) {
|
||||
row := q.db.QueryRow(ctx, createBookmark, arg.UserID, arg.PostID)
|
||||
var i Bookmark
|
||||
err := row.Scan(&i.UserID, &i.PostID, &i.BookmarkedAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteBookmark = `-- name: DeleteBookmark :exec
|
||||
DELETE FROM public.bookmarks
|
||||
WHERE user_id=$1 AND post_id=$2
|
||||
`
|
||||
|
||||
type DeleteBookmarkParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
PostID int64 `json:"post_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteBookmark(ctx context.Context, arg DeleteBookmarkParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteBookmark, arg.UserID, arg.PostID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getBookmarkTimestamp = `-- name: GetBookmarkTimestamp :one
|
||||
SELECT bookmarked_at
|
||||
FROM public.bookmarks bookmarks
|
||||
where bookmarks.post_id = $1 and bookmarks.user_id = $2
|
||||
`
|
||||
|
||||
type GetBookmarkTimestampParams struct {
|
||||
PostID int64 `json:"post_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetBookmarkTimestamp(ctx context.Context, arg GetBookmarkTimestampParams) (pgtype.Timestamp, error) {
|
||||
row := q.db.QueryRow(ctx, getBookmarkTimestamp, arg.PostID, arg.UserID)
|
||||
var bookmarked_at pgtype.Timestamp
|
||||
err := row.Scan(&bookmarked_at)
|
||||
return bookmarked_at, err
|
||||
}
|
||||
|
||||
const getBookmarksByUserId = `-- name: GetBookmarksByUserId :many
|
||||
SELECT user_id, post_id, bookmarked_at
|
||||
FROM public.bookmarks bookmarks
|
||||
where bookmarks.user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetBookmarksByUserId(ctx context.Context, userID int64) ([]Bookmark, error) {
|
||||
rows, err := q.db.Query(ctx, getBookmarksByUserId, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Bookmark
|
||||
for rows.Next() {
|
||||
var i Bookmark
|
||||
if err := rows.Scan(&i.UserID, &i.PostID, &i.BookmarkedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getCountOfBookmarksByPostId = `-- name: GetCountOfBookmarksByPostId :one
|
||||
SELECT COUNT(*)
|
||||
FROM public.bookmarks bookmarks
|
||||
where bookmarks.post_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetCountOfBookmarksByPostId(ctx context.Context, postID int64) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, getCountOfBookmarksByPostId, postID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
181
enshi_back/db/go_queries/comments_queries.sql.go
Normal file
181
enshi_back/db/go_queries/comments_queries.sql.go
Normal file
@ -0,0 +1,181 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
// source: comments_queries.sql
|
||||
|
||||
package db_repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createComment = `-- name: CreateComment :one
|
||||
INSERT INTO public."comments"
|
||||
(comment_id, post_id, user_id, "content", created_at)
|
||||
VALUES($1, $2, $3, $4, CURRENT_TIMESTAMP)
|
||||
RETURNING comment_id, post_id, user_id, content, created_at
|
||||
`
|
||||
|
||||
type CreateCommentParams struct {
|
||||
CommentID int64 `json:"comment_id"`
|
||||
PostID pgtype.Int8 `json:"post_id"`
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateComment(ctx context.Context, arg CreateCommentParams) (Comment, error) {
|
||||
row := q.db.QueryRow(ctx, createComment,
|
||||
arg.CommentID,
|
||||
arg.PostID,
|
||||
arg.UserID,
|
||||
arg.Content,
|
||||
)
|
||||
var i Comment
|
||||
err := row.Scan(
|
||||
&i.CommentID,
|
||||
&i.PostID,
|
||||
&i.UserID,
|
||||
&i.Content,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteComment = `-- name: DeleteComment :exec
|
||||
DELETE FROM public."comments"
|
||||
WHERE comment_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteComment(ctx context.Context, commentID int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteComment, commentID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getCommentByUserId = `-- name: GetCommentByUserId :one
|
||||
SELECT comment_id, post_id, user_id, "content", created_at
|
||||
FROM public."comments"
|
||||
where public."comments".user_id = $1 and public."comments".post_id = $2
|
||||
`
|
||||
|
||||
type GetCommentByUserIdParams struct {
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
PostID pgtype.Int8 `json:"post_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetCommentByUserId(ctx context.Context, arg GetCommentByUserIdParams) (Comment, error) {
|
||||
row := q.db.QueryRow(ctx, getCommentByUserId, arg.UserID, arg.PostID)
|
||||
var i Comment
|
||||
err := row.Scan(
|
||||
&i.CommentID,
|
||||
&i.PostID,
|
||||
&i.UserID,
|
||||
&i.Content,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCommentsForPostAsc = `-- name: GetCommentsForPostAsc :many
|
||||
SELECT comment_id, post_id, user_id, "content", created_at
|
||||
FROM public."comments"
|
||||
where public."comments".post_id = $1
|
||||
order by created_at ASC
|
||||
LIMIT 10 offset ($2 * 10)
|
||||
`
|
||||
|
||||
type GetCommentsForPostAscParams struct {
|
||||
PostID pgtype.Int8 `json:"post_id"`
|
||||
Column2 interface{} `json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetCommentsForPostAsc(ctx context.Context, arg GetCommentsForPostAscParams) ([]Comment, error) {
|
||||
rows, err := q.db.Query(ctx, getCommentsForPostAsc, arg.PostID, arg.Column2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Comment
|
||||
for rows.Next() {
|
||||
var i Comment
|
||||
if err := rows.Scan(
|
||||
&i.CommentID,
|
||||
&i.PostID,
|
||||
&i.UserID,
|
||||
&i.Content,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getCommentsForPostDesc = `-- name: GetCommentsForPostDesc :many
|
||||
SELECT comment_id, post_id, user_id, "content", created_at
|
||||
FROM public."comments"
|
||||
where public."comments".post_id = $1
|
||||
order by created_at DESC
|
||||
LIMIT 10 offset ($2 * 10)
|
||||
`
|
||||
|
||||
type GetCommentsForPostDescParams struct {
|
||||
PostID pgtype.Int8 `json:"post_id"`
|
||||
Column2 interface{} `json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetCommentsForPostDesc(ctx context.Context, arg GetCommentsForPostDescParams) ([]Comment, error) {
|
||||
rows, err := q.db.Query(ctx, getCommentsForPostDesc, arg.PostID, arg.Column2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Comment
|
||||
for rows.Next() {
|
||||
var i Comment
|
||||
if err := rows.Scan(
|
||||
&i.CommentID,
|
||||
&i.PostID,
|
||||
&i.UserID,
|
||||
&i.Content,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateCommentByCommentId = `-- name: UpdateCommentByCommentId :one
|
||||
UPDATE public."comments"
|
||||
SET "content"=$2
|
||||
WHERE comment_id=$1
|
||||
RETURNING comment_id, post_id, user_id, content, created_at
|
||||
`
|
||||
|
||||
type UpdateCommentByCommentIdParams struct {
|
||||
CommentID int64 `json:"comment_id"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateCommentByCommentId(ctx context.Context, arg UpdateCommentByCommentIdParams) (Comment, error) {
|
||||
row := q.db.QueryRow(ctx, updateCommentByCommentId, arg.CommentID, arg.Content)
|
||||
var i Comment
|
||||
err := row.Scan(
|
||||
&i.CommentID,
|
||||
&i.PostID,
|
||||
&i.UserID,
|
||||
&i.Content,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
83
enshi_back/db/go_queries/likes_queries.sql.go
Normal file
83
enshi_back/db/go_queries/likes_queries.sql.go
Normal file
@ -0,0 +1,83 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
// source: likes_queries.sql
|
||||
|
||||
package db_repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createLike = `-- name: CreateLike :one
|
||||
INSERT INTO public.likes
|
||||
(like_id, user_id, comment_id, created_at)
|
||||
VALUES($1, $2, $3, CURRENT_TIMESTAMP)
|
||||
RETURNING like_id, user_id, comment_id, created_at
|
||||
`
|
||||
|
||||
type CreateLikeParams struct {
|
||||
LikeID int64 `json:"like_id"`
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
CommentID pgtype.Int8 `json:"comment_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateLike(ctx context.Context, arg CreateLikeParams) (Like, error) {
|
||||
row := q.db.QueryRow(ctx, createLike, arg.LikeID, arg.UserID, arg.CommentID)
|
||||
var i Like
|
||||
err := row.Scan(
|
||||
&i.LikeID,
|
||||
&i.UserID,
|
||||
&i.CommentID,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteLikeByUserCommentId = `-- name: DeleteLikeByUserCommentId :exec
|
||||
DELETE FROM public.likes
|
||||
WHERE user_id = $1 and comment_id = $2
|
||||
`
|
||||
|
||||
type DeleteLikeByUserCommentIdParams struct {
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
CommentID pgtype.Int8 `json:"comment_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteLikeByUserCommentId(ctx context.Context, arg DeleteLikeByUserCommentIdParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteLikeByUserCommentId, arg.UserID, arg.CommentID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getLikesForComment = `-- name: GetLikesForComment :one
|
||||
SELECT count(*)
|
||||
FROM public.likes
|
||||
WHERE comment_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetLikesForComment(ctx context.Context, commentID pgtype.Int8) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, getLikesForComment, commentID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const isUserLikedComment = `-- name: IsUserLikedComment :one
|
||||
SELECT count(*)
|
||||
FROM public.likes
|
||||
WHERE user_id = $1 and comment_id = $2
|
||||
`
|
||||
|
||||
type IsUserLikedCommentParams struct {
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
CommentID pgtype.Int8 `json:"comment_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) IsUserLikedComment(ctx context.Context, arg IsUserLikedCommentParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, isUserLikedComment, arg.UserID, arg.CommentID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
@ -72,7 +72,7 @@ type PostVote struct {
|
||||
|
||||
type Profile struct {
|
||||
ProfileID int64 `json:"profile_id"`
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
Bio pgtype.Text `json:"bio"`
|
||||
AvatarUrl pgtype.Text `json:"avatar_url"`
|
||||
WebsiteUrl pgtype.Text `json:"website_url"`
|
||||
|
||||
@ -9,26 +9,26 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getFavoriteBlogsInfosByUserId = `-- name: GetFavoriteBlogsInfosByUserId :many
|
||||
const getFavoriteBlogsByUserId = `-- name: GetFavoriteBlogsByUserId :many
|
||||
SELECT blogs.blog_id, blogs.user_id, blogs.title, blogs.description, blogs.category_id, blogs.created_at
|
||||
FROM favorites
|
||||
JOIN blogs on blogs.blog_id = favorites.blog_id
|
||||
WHERE favorites.user_id = $1
|
||||
`
|
||||
|
||||
type GetFavoriteBlogsInfosByUserIdRow struct {
|
||||
type GetFavoriteBlogsByUserIdRow struct {
|
||||
Blog Blog `json:"blog"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetFavoriteBlogsInfosByUserId(ctx context.Context, userID int64) ([]GetFavoriteBlogsInfosByUserIdRow, error) {
|
||||
rows, err := q.db.Query(ctx, getFavoriteBlogsInfosByUserId, userID)
|
||||
func (q *Queries) GetFavoriteBlogsByUserId(ctx context.Context, userID int64) ([]GetFavoriteBlogsByUserIdRow, error) {
|
||||
rows, err := q.db.Query(ctx, getFavoriteBlogsByUserId, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetFavoriteBlogsInfosByUserIdRow
|
||||
var items []GetFavoriteBlogsByUserIdRow
|
||||
for rows.Next() {
|
||||
var i GetFavoriteBlogsInfosByUserIdRow
|
||||
var i GetFavoriteBlogsByUserIdRow
|
||||
if err := rows.Scan(
|
||||
&i.Blog.BlogID,
|
||||
&i.Blog.UserID,
|
||||
|
||||
75
enshi_back/db/go_queries/post_tags_queries.sql.go
Normal file
75
enshi_back/db/go_queries/post_tags_queries.sql.go
Normal file
@ -0,0 +1,75 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
// source: post_tags_queries.sql
|
||||
|
||||
package db_repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const createPostTagRelation = `-- name: CreatePostTagRelation :one
|
||||
INSERT INTO public.post_tags
|
||||
(post_id, tag_id)
|
||||
VALUES($1, $2)
|
||||
RETURNING post_id, tag_id
|
||||
`
|
||||
|
||||
type CreatePostTagRelationParams struct {
|
||||
PostID int64 `json:"post_id"`
|
||||
TagID int32 `json:"tag_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreatePostTagRelation(ctx context.Context, arg CreatePostTagRelationParams) (PostTag, error) {
|
||||
row := q.db.QueryRow(ctx, createPostTagRelation, arg.PostID, arg.TagID)
|
||||
var i PostTag
|
||||
err := row.Scan(&i.PostID, &i.TagID)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deletePostTagRelation = `-- name: DeletePostTagRelation :exec
|
||||
DELETE FROM public.post_tags
|
||||
WHERE post_id = $1 AND tag_id = $2
|
||||
`
|
||||
|
||||
type DeletePostTagRelationParams struct {
|
||||
PostID int64 `json:"post_id"`
|
||||
TagID int32 `json:"tag_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeletePostTagRelation(ctx context.Context, arg DeletePostTagRelationParams) error {
|
||||
_, err := q.db.Exec(ctx, deletePostTagRelation, arg.PostID, arg.TagID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAllTagsForPost = `-- name: GetAllTagsForPost :many
|
||||
SELECT tags.tag_id, tags.tag_name
|
||||
from public.tags tags
|
||||
JOIN public.post_tags post_tags on post_tags.tag_id = tags.tag_id
|
||||
JOIN public.posts posts on posts.post_id = post_tags.post_id
|
||||
`
|
||||
|
||||
type GetAllTagsForPostRow struct {
|
||||
Tag Tag `json:"tag"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetAllTagsForPost(ctx context.Context) ([]GetAllTagsForPostRow, error) {
|
||||
rows, err := q.db.Query(ctx, getAllTagsForPost)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetAllTagsForPostRow
|
||||
for rows.Next() {
|
||||
var i GetAllTagsForPostRow
|
||||
if err := rows.Scan(&i.Tag.TagID, &i.Tag.TagName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
83
enshi_back/db/go_queries/post_votes_queries.sql.go
Normal file
83
enshi_back/db/go_queries/post_votes_queries.sql.go
Normal file
@ -0,0 +1,83 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
// source: post_votes_queries.sql
|
||||
|
||||
package db_repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const createPostVote = `-- name: CreatePostVote :one
|
||||
INSERT INTO public.post_votes
|
||||
(post_id, user_id, vote)
|
||||
VALUES($1, $2, $3)
|
||||
RETURNING post_id, user_id, vote
|
||||
`
|
||||
|
||||
type CreatePostVoteParams struct {
|
||||
PostID int64 `json:"post_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
Vote bool `json:"vote"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreatePostVote(ctx context.Context, arg CreatePostVoteParams) (PostVote, error) {
|
||||
row := q.db.QueryRow(ctx, createPostVote, arg.PostID, arg.UserID, arg.Vote)
|
||||
var i PostVote
|
||||
err := row.Scan(&i.PostID, &i.UserID, &i.Vote)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deletePostVote = `-- name: DeletePostVote :exec
|
||||
DELETE FROM public.post_votes
|
||||
WHERE post_id=$1 AND user_id=$2
|
||||
`
|
||||
|
||||
type DeletePostVoteParams struct {
|
||||
PostID int64 `json:"post_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeletePostVote(ctx context.Context, arg DeletePostVoteParams) error {
|
||||
_, err := q.db.Exec(ctx, deletePostVote, arg.PostID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getPostVote = `-- name: GetPostVote :one
|
||||
SELECT vote
|
||||
FROM public.post_votes p_v
|
||||
WHERE p_v.user_id = $1 and p_v.post_id = $2
|
||||
`
|
||||
|
||||
type GetPostVoteParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
PostID int64 `json:"post_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetPostVote(ctx context.Context, arg GetPostVoteParams) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, getPostVote, arg.UserID, arg.PostID)
|
||||
var vote bool
|
||||
err := row.Scan(&vote)
|
||||
return vote, err
|
||||
}
|
||||
|
||||
const updateVote = `-- name: UpdateVote :one
|
||||
UPDATE public.post_votes
|
||||
SET vote=$1
|
||||
WHERE post_id=$2 AND user_id=$3
|
||||
RETURNING post_id, user_id, vote
|
||||
`
|
||||
|
||||
type UpdateVoteParams struct {
|
||||
Vote bool `json:"vote"`
|
||||
PostID int64 `json:"post_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateVote(ctx context.Context, arg UpdateVoteParams) (PostVote, error) {
|
||||
row := q.db.QueryRow(ctx, updateVote, arg.Vote, arg.PostID, arg.UserID)
|
||||
var i PostVote
|
||||
err := row.Scan(&i.PostID, &i.UserID, &i.Vote)
|
||||
return i, err
|
||||
}
|
||||
162
enshi_back/db/go_queries/posts_queries.sql.go
Normal file
162
enshi_back/db/go_queries/posts_queries.sql.go
Normal file
@ -0,0 +1,162 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
// source: posts_queries.sql
|
||||
|
||||
package db_repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createPost = `-- name: CreatePost :one
|
||||
INSERT INTO public.posts
|
||||
(post_id, blog_id, user_id, title, "content", created_at, updated_at)
|
||||
VALUES($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
RETURNING post_id, blog_id, user_id, title, content, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreatePostParams struct {
|
||||
PostID int64 `json:"post_id"`
|
||||
BlogID pgtype.Int8 `json:"blog_id"`
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
Title pgtype.Text `json:"title"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreatePost(ctx context.Context, arg CreatePostParams) (Post, error) {
|
||||
row := q.db.QueryRow(ctx, createPost,
|
||||
arg.PostID,
|
||||
arg.BlogID,
|
||||
arg.UserID,
|
||||
arg.Title,
|
||||
arg.Content,
|
||||
)
|
||||
var i Post
|
||||
err := row.Scan(
|
||||
&i.PostID,
|
||||
&i.BlogID,
|
||||
&i.UserID,
|
||||
&i.Title,
|
||||
&i.Content,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deletePostByPostId = `-- name: DeletePostByPostId :exec
|
||||
DELETE FROM public.posts
|
||||
WHERE post_id=$1
|
||||
`
|
||||
|
||||
func (q *Queries) DeletePostByPostId(ctx context.Context, postID int64) error {
|
||||
_, err := q.db.Exec(ctx, deletePostByPostId, postID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getPostsByBlogId = `-- name: GetPostsByBlogId :many
|
||||
SELECT post_id, blog_id, user_id, title, content, created_at, updated_at
|
||||
FROM public.posts posts
|
||||
where posts.blog_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPostsByBlogId(ctx context.Context, blogID pgtype.Int8) ([]Post, error) {
|
||||
rows, err := q.db.Query(ctx, getPostsByBlogId, blogID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Post
|
||||
for rows.Next() {
|
||||
var i Post
|
||||
if err := rows.Scan(
|
||||
&i.PostID,
|
||||
&i.BlogID,
|
||||
&i.UserID,
|
||||
&i.Title,
|
||||
&i.Content,
|
||||
&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 getPostsByUserId = `-- name: GetPostsByUserId :many
|
||||
SELECT post_id, blog_id, user_id, title, content, created_at, updated_at
|
||||
FROM public.posts posts
|
||||
where posts.user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPostsByUserId(ctx context.Context, userID pgtype.Int8) ([]Post, error) {
|
||||
rows, err := q.db.Query(ctx, getPostsByUserId, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Post
|
||||
for rows.Next() {
|
||||
var i Post
|
||||
if err := rows.Scan(
|
||||
&i.PostID,
|
||||
&i.BlogID,
|
||||
&i.UserID,
|
||||
&i.Title,
|
||||
&i.Content,
|
||||
&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 updatePostByPostId = `-- name: UpdatePostByPostId :one
|
||||
UPDATE public.posts
|
||||
SET blog_id=$1, user_id=$2, title=$3, "content"=$4, updated_at=CURRENT_TIMESTAMP
|
||||
WHERE post_id = $5
|
||||
RETURNING post_id, blog_id, user_id, title, content, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdatePostByPostIdParams struct {
|
||||
BlogID pgtype.Int8 `json:"blog_id"`
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
Title pgtype.Text `json:"title"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
PostID int64 `json:"post_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePostByPostId(ctx context.Context, arg UpdatePostByPostIdParams) (Post, error) {
|
||||
row := q.db.QueryRow(ctx, updatePostByPostId,
|
||||
arg.BlogID,
|
||||
arg.UserID,
|
||||
arg.Title,
|
||||
arg.Content,
|
||||
arg.PostID,
|
||||
)
|
||||
var i Post
|
||||
err := row.Scan(
|
||||
&i.PostID,
|
||||
&i.BlogID,
|
||||
&i.UserID,
|
||||
&i.Title,
|
||||
&i.Content,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -18,7 +18,7 @@ WHERE user_id=$1
|
||||
RETURNING profile_id, user_id, bio, avatar_url, website_url
|
||||
`
|
||||
|
||||
func (q *Queries) ClearProfileByUserId(ctx context.Context, userID pgtype.Int8) (Profile, error) {
|
||||
func (q *Queries) ClearProfileByUserId(ctx context.Context, userID int64) (Profile, error) {
|
||||
row := q.db.QueryRow(ctx, clearProfileByUserId, userID)
|
||||
var i Profile
|
||||
err := row.Scan(
|
||||
@ -39,8 +39,8 @@ RETURNING profile_id, user_id, bio, avatar_url, website_url
|
||||
`
|
||||
|
||||
type CreateProfileForUserParams struct {
|
||||
ProfileID int64 `json:"profile_id"`
|
||||
UserID pgtype.Int8 `json:"user_id"`
|
||||
ProfileID int64 `json:"profile_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateProfileForUser(ctx context.Context, arg CreateProfileForUserParams) (Profile, error) {
|
||||
@ -61,7 +61,7 @@ DELETE FROM public.profiles
|
||||
WHERE user_id=$1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteProfileByUserId(ctx context.Context, userID pgtype.Int8) error {
|
||||
func (q *Queries) DeleteProfileByUserId(ctx context.Context, userID int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteProfileByUserId, userID)
|
||||
return err
|
||||
}
|
||||
@ -70,7 +70,7 @@ const getProfileByUserId = `-- name: GetProfileByUserId :one
|
||||
SELECT profile_id, user_id, bio, avatar_url, website_url FROM public.profiles WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetProfileByUserId(ctx context.Context, userID pgtype.Int8) (Profile, error) {
|
||||
func (q *Queries) GetProfileByUserId(ctx context.Context, userID int64) (Profile, error) {
|
||||
row := q.db.QueryRow(ctx, getProfileByUserId, userID)
|
||||
var i Profile
|
||||
err := row.Scan(
|
||||
|
||||
78
enshi_back/db/go_queries/tags_queries.sql.go
Normal file
78
enshi_back/db/go_queries/tags_queries.sql.go
Normal file
@ -0,0 +1,78 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
// source: tags_queries.sql
|
||||
|
||||
package db_repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const createTag = `-- name: CreateTag :one
|
||||
INSERT INTO public.tags
|
||||
(tag_id, tag_name)
|
||||
VALUES($1, $2)
|
||||
RETURNING tag_id, tag_name
|
||||
`
|
||||
|
||||
type CreateTagParams struct {
|
||||
TagID int32 `json:"tag_id"`
|
||||
TagName string `json:"tag_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateTag(ctx context.Context, arg CreateTagParams) (Tag, error) {
|
||||
row := q.db.QueryRow(ctx, createTag, arg.TagID, arg.TagName)
|
||||
var i Tag
|
||||
err := row.Scan(&i.TagID, &i.TagName)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteTag = `-- name: DeleteTag :exec
|
||||
DELETE FROM public.tags
|
||||
WHERE tag_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteTag(ctx context.Context, tagID int32) error {
|
||||
_, err := q.db.Exec(ctx, deleteTag, tagID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAllTags = `-- name: GetAllTags :many
|
||||
SELECT tag_id, tag_name
|
||||
FROM public.tags
|
||||
ORDER BY tag_name ASC
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllTags(ctx context.Context) ([]Tag, error) {
|
||||
rows, err := q.db.Query(ctx, getAllTags)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Tag
|
||||
for rows.Next() {
|
||||
var i Tag
|
||||
if err := rows.Scan(&i.TagID, &i.TagName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getTagByTagId = `-- name: GetTagByTagId :one
|
||||
SELECT tag_id, tag_name
|
||||
FROM public.tags tags
|
||||
where tags.tag_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetTagByTagId(ctx context.Context, tagID int32) (Tag, error) {
|
||||
row := q.db.QueryRow(ctx, getTagByTagId, tagID)
|
||||
var i Tag
|
||||
err := row.Scan(&i.TagID, &i.TagName)
|
||||
return i, err
|
||||
}
|
||||
24
enshi_back/db/queries/bookmarks_queries.sql
Normal file
24
enshi_back/db/queries/bookmarks_queries.sql
Normal file
@ -0,0 +1,24 @@
|
||||
-- name: GetBookmarksByUserId :many
|
||||
SELECT *
|
||||
FROM public.bookmarks bookmarks
|
||||
where bookmarks.user_id = $1;
|
||||
|
||||
-- name: GetCountOfBookmarksByPostId :one
|
||||
SELECT COUNT(*)
|
||||
FROM public.bookmarks bookmarks
|
||||
where bookmarks.post_id = $1;
|
||||
|
||||
-- name: GetBookmarkTimestamp :one
|
||||
SELECT bookmarked_at
|
||||
FROM public.bookmarks bookmarks
|
||||
where bookmarks.post_id = $1 and bookmarks.user_id = $2;
|
||||
|
||||
-- name: CreateBookmark :one
|
||||
INSERT INTO public.bookmarks
|
||||
(user_id, post_id, bookmarked_at)
|
||||
VALUES($1, $2, CURRENT_TIMESTAMP)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteBookmark :exec
|
||||
DELETE FROM public.bookmarks
|
||||
WHERE user_id=$1 AND post_id=$2;
|
||||
34
enshi_back/db/queries/comments_queries.sql
Normal file
34
enshi_back/db/queries/comments_queries.sql
Normal file
@ -0,0 +1,34 @@
|
||||
-- name: CreateComment :one
|
||||
INSERT INTO public."comments"
|
||||
(comment_id, post_id, user_id, "content", created_at)
|
||||
VALUES($1, $2, $3, $4, CURRENT_TIMESTAMP)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteComment :exec
|
||||
DELETE FROM public."comments"
|
||||
WHERE comment_id = $1;
|
||||
|
||||
-- name: GetCommentsForPostDesc :many
|
||||
SELECT comment_id, post_id, user_id, "content", created_at
|
||||
FROM public."comments"
|
||||
where public."comments".post_id = $1
|
||||
order by created_at DESC
|
||||
LIMIT 10 offset ($2 * 10);
|
||||
|
||||
-- name: GetCommentsForPostAsc :many
|
||||
SELECT comment_id, post_id, user_id, "content", created_at
|
||||
FROM public."comments"
|
||||
where public."comments".post_id = $1
|
||||
order by created_at ASC
|
||||
LIMIT 10 offset ($2 * 10);
|
||||
|
||||
-- name: UpdateCommentByCommentId :one
|
||||
UPDATE public."comments"
|
||||
SET "content"=$2
|
||||
WHERE comment_id=$1
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetCommentByUserId :one
|
||||
SELECT comment_id, post_id, user_id, "content", created_at
|
||||
FROM public."comments"
|
||||
where public."comments".user_id = $1 and public."comments".post_id = $2;
|
||||
20
enshi_back/db/queries/likes_queries.sql
Normal file
20
enshi_back/db/queries/likes_queries.sql
Normal file
@ -0,0 +1,20 @@
|
||||
-- name: CreateLike :one
|
||||
INSERT INTO public.likes
|
||||
(like_id, user_id, comment_id, created_at)
|
||||
VALUES($1, $2, $3, CURRENT_TIMESTAMP)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteLikeByUserCommentId :exec
|
||||
DELETE FROM public.likes
|
||||
WHERE user_id = $1 and comment_id = $2;
|
||||
|
||||
-- name: GetLikesForComment :one
|
||||
SELECT count(*)
|
||||
FROM public.likes
|
||||
WHERE comment_id = $1;
|
||||
|
||||
-- name: IsUserLikedComment :one
|
||||
SELECT count(*)
|
||||
FROM public.likes
|
||||
WHERE user_id = $1 and comment_id = $2;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
-- name: GetFavoriteBlogsInfosByUserId :many
|
||||
-- name: GetFavoriteBlogsByUserId :many
|
||||
SELECT sqlc.embed(blogs)
|
||||
FROM favorites
|
||||
JOIN blogs on blogs.blog_id = favorites.blog_id
|
||||
|
||||
15
enshi_back/db/queries/post_tags_queries.sql
Normal file
15
enshi_back/db/queries/post_tags_queries.sql
Normal file
@ -0,0 +1,15 @@
|
||||
-- name: GetAllTagsForPost :many
|
||||
SELECT sqlc.embed(tags)
|
||||
from public.tags tags
|
||||
JOIN public.post_tags post_tags on post_tags.tag_id = tags.tag_id
|
||||
JOIN public.posts posts on posts.post_id = post_tags.post_id;
|
||||
|
||||
-- name: CreatePostTagRelation :one
|
||||
INSERT INTO public.post_tags
|
||||
(post_id, tag_id)
|
||||
VALUES($1, $2)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeletePostTagRelation :exec
|
||||
DELETE FROM public.post_tags
|
||||
WHERE post_id = $1 AND tag_id = $2;
|
||||
20
enshi_back/db/queries/post_votes_queries.sql
Normal file
20
enshi_back/db/queries/post_votes_queries.sql
Normal file
@ -0,0 +1,20 @@
|
||||
-- name: CreatePostVote :one
|
||||
INSERT INTO public.post_votes
|
||||
(post_id, user_id, vote)
|
||||
VALUES($1, $2, $3)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeletePostVote :exec
|
||||
DELETE FROM public.post_votes
|
||||
WHERE post_id=$1 AND user_id=$2;
|
||||
|
||||
-- name: UpdateVote :one
|
||||
UPDATE public.post_votes
|
||||
SET vote=$1
|
||||
WHERE post_id=$2 AND user_id=$3
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetPostVote :one
|
||||
SELECT vote
|
||||
FROM public.post_votes p_v
|
||||
WHERE p_v.user_id = $1 and p_v.post_id = $2;
|
||||
25
enshi_back/db/queries/posts_queries.sql
Normal file
25
enshi_back/db/queries/posts_queries.sql
Normal file
@ -0,0 +1,25 @@
|
||||
-- name: GetPostsByUserId :many
|
||||
SELECT *
|
||||
FROM public.posts posts
|
||||
where posts.user_id = $1;
|
||||
|
||||
-- name: GetPostsByBlogId :many
|
||||
SELECT *
|
||||
FROM public.posts posts
|
||||
where posts.blog_id = $1;
|
||||
|
||||
-- name: CreatePost :one
|
||||
INSERT INTO public.posts
|
||||
(post_id, blog_id, user_id, title, "content", created_at, updated_at)
|
||||
VALUES($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdatePostByPostId :one
|
||||
UPDATE public.posts
|
||||
SET blog_id=$1, user_id=$2, title=$3, "content"=$4, updated_at=CURRENT_TIMESTAMP
|
||||
WHERE post_id = $5
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeletePostByPostId :exec
|
||||
DELETE FROM public.posts
|
||||
WHERE post_id=$1;
|
||||
19
enshi_back/db/queries/tags_queries.sql
Normal file
19
enshi_back/db/queries/tags_queries.sql
Normal file
@ -0,0 +1,19 @@
|
||||
-- name: GetTagByTagId :one
|
||||
SELECT tag_id, tag_name
|
||||
FROM public.tags tags
|
||||
where tags.tag_id = $1;
|
||||
|
||||
-- name: CreateTag :one
|
||||
INSERT INTO public.tags
|
||||
(tag_id, tag_name)
|
||||
VALUES($1, $2)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteTag :exec
|
||||
DELETE FROM public.tags
|
||||
WHERE tag_id = $1;
|
||||
|
||||
-- name: GetAllTags :many
|
||||
SELECT tag_id, tag_name
|
||||
FROM public.tags
|
||||
ORDER BY tag_name ASC;
|
||||
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
db_repo "enshi/db/go_queries"
|
||||
"enshi/utils"
|
||||
utils "enshi/utils"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user