Compare commits
No commits in common. "ad08e6ab314f6c983ee207e7cb973488d13af424" and "9f3a2cdf1fba83a8d1edc84d376cc48639649019" have entirely different histories.
ad08e6ab31
...
9f3a2cdf1f
@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
db "git.nochill.in/nochill/hiling_go/db/sqlc"
|
||||
"git.nochill.in/nochill/hiling_go/util"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/meilisearch/meilisearch-go"
|
||||
ysqlc "github.com/yiplee/sqlc"
|
||||
@ -63,7 +63,7 @@ func (server *Server) createLocation(ctx *gin.Context) {
|
||||
SubmittedBy: req.SubmittedBy,
|
||||
RegencyID: req.RegencyID,
|
||||
IsDeleted: false,
|
||||
ApprovedBy: pgtype.Int4{Int32: 0, Valid: false},
|
||||
ApprovedBy: sql.NullInt32{Int32: 0, Valid: false},
|
||||
GoogleMapsLink: pgtype.Text{Valid: len(req.GoogleMapsLink) > 0, String: req.GoogleMapsLink},
|
||||
Thumbnail: tempImg,
|
||||
}
|
||||
@ -111,7 +111,7 @@ type getTopListLocationsReq struct {
|
||||
Page int32 `form:"page" binding:"required,min=1"`
|
||||
PageSize int32 `form:"page_size" binding:"required,min=5"`
|
||||
OrderBy int16 `form:"order_by" binding:"numeric,min=1,max=3"`
|
||||
RegionType int32 `form:"region_type" binding:"numeric,min=0,max=7"`
|
||||
RegionType int16 `form:"region_type" binding:"numeric,min=0,max=7"`
|
||||
}
|
||||
|
||||
func (server *Server) getTopListLocations(ctx *gin.Context) {
|
||||
@ -136,7 +136,7 @@ func (server *Server) getTopListLocations(ctx *gin.Context) {
|
||||
Limit: req.PageSize,
|
||||
Offset: (req.Page - 1) * req.PageSize,
|
||||
OrderBy: orderby,
|
||||
RegionType: pgtype.Int4{Valid: req.RegionType > 0, Int32: req.RegionType},
|
||||
RegionType: sql.NullInt16{Valid: req.RegionType > 0, Int16: req.RegionType},
|
||||
}
|
||||
|
||||
locations, err := server.Store.GetTopListLocations(ctx, arg)
|
||||
@ -192,7 +192,7 @@ func (server *Server) getLocation(ctx *gin.Context) {
|
||||
|
||||
location, err := server.Store.GetLocation(ctx, req.ID)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
if err == sql.ErrNoRows {
|
||||
ctx.JSON(http.StatusNotFound, ErrorResponse(err, ""))
|
||||
return
|
||||
}
|
||||
@ -272,7 +272,7 @@ func (server *Server) getListLocationReviews(ctx *gin.Context) {
|
||||
reviews, err := server.Store.GetListLocationReviews(ctx, arg)
|
||||
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
if err == sql.ErrNoRows {
|
||||
ctx.JSON(http.StatusNotFound, ErrorResponse(err, "There's no critics reviews for this location yet"))
|
||||
return
|
||||
}
|
||||
@ -294,7 +294,7 @@ func (server *Server) getListLocationReviews(ctx *gin.Context) {
|
||||
reviews, err := server.Store.GetListLocationReviews(ctx, arg)
|
||||
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
if err == sql.ErrNoRows {
|
||||
ctx.JSON(http.StatusNotFound, ErrorResponse(err, "There's no critics reviews for this location yet"))
|
||||
return
|
||||
}
|
||||
@ -332,5 +332,5 @@ func (server *Server) searchLocations(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, searchRes.Hits)
|
||||
ctx.JSON(http.StatusOK, searchRes)
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"log"
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
db "git.nochill.in/nochill/hiling_go/db/sqlc"
|
||||
"git.nochill.in/nochill/hiling_go/util/token"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type createReviewReq struct {
|
||||
@ -77,8 +76,6 @@ func (server *Server) getUserReviewByLocation(ctx *gin.Context) {
|
||||
|
||||
authPayload := ctx.MustGet(authorizationPayloadKey).(*token.Payload)
|
||||
|
||||
log.Println(authPayload)
|
||||
|
||||
arg := db.GetUserReviewByLocationParams{
|
||||
SubmittedBy: int32(authPayload.UserID),
|
||||
LocationID: req.LocationID,
|
||||
@ -87,7 +84,7 @@ func (server *Server) getUserReviewByLocation(ctx *gin.Context) {
|
||||
review, err := server.Store.GetUserReviewByLocation(ctx, arg)
|
||||
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
if err == sql.ErrNoRows {
|
||||
ctx.JSON(http.StatusNotFound, ErrorResponse(err, "Review not found"))
|
||||
return
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type renewAccessRequest struct {
|
||||
@ -33,7 +33,7 @@ func (server *Server) renewAccessToken(ctx *gin.Context) {
|
||||
|
||||
session, err := server.Store.GetSession(ctx, int32(refreshPayload.UserID))
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
if err == sql.ErrNoRows {
|
||||
ctx.JSON(http.StatusNotFound, ErrorResponse(err, ""))
|
||||
return
|
||||
}
|
||||
@ -67,7 +67,7 @@ func (server *Server) renewAccessToken(ctx *gin.Context) {
|
||||
|
||||
user, err := server.Store.GetUser(ctx, refreshPayload.Username)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
if err == sql.ErrNoRows {
|
||||
ctx.JSON(http.StatusNotFound, ErrorResponse(err, ""))
|
||||
return
|
||||
}
|
||||
|
16
api/user.go
16
api/user.go
@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@ -12,7 +13,6 @@ import (
|
||||
"git.nochill.in/nochill/hiling_go/util"
|
||||
"git.nochill.in/nochill/hiling_go/util/token"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
@ -25,8 +25,8 @@ type createUserResponse struct {
|
||||
ID int32 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
AvatarPicture string `json:"avatar_picture"` // avatar_url
|
||||
BannedAt pgtype.Timestamp `json:"banned_at"`
|
||||
BannedUntil pgtype.Timestamp `json:"banned_until"`
|
||||
BannedAt sql.NullTime `json:"banned_at"`
|
||||
BannedUntil sql.NullTime `json:"banned_until"`
|
||||
BanReason string `json:"ban_reason"`
|
||||
IsPermaban bool `json:"is_permaban"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
@ -101,8 +101,8 @@ func (server *Server) createUser(ctx *gin.Context) {
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
AvatarPicture: user.AvatarPicture.String,
|
||||
BannedAt: pgtype.Timestamp{Valid: user.BannedAt.Valid, Time: user.BannedAt.Time},
|
||||
BannedUntil: pgtype.Timestamp{Valid: user.BannedUntil.Valid, Time: user.BannedUntil.Time},
|
||||
BannedAt: sql.NullTime{Valid: user.BannedAt.Valid, Time: user.BannedAt.Time},
|
||||
BannedUntil: sql.NullTime{Valid: user.BannedUntil.Valid, Time: user.BannedUntil.Time},
|
||||
BanReason: user.BanReason.String,
|
||||
IsPermaban: user.IsPermaban.Bool,
|
||||
IsAdmin: user.IsAdmin.Bool,
|
||||
@ -177,9 +177,9 @@ func (server *Server) updateUser(ctx *gin.Context) {
|
||||
authPayload := ctx.MustGet(authorizationPayloadKey).(*token.Payload)
|
||||
|
||||
user, err := server.Store.UpdateUser(ctx, db.UpdateUserParams{
|
||||
About: pgtype.Text{String: req.About, Valid: true},
|
||||
About: sql.NullString{String: req.About, Valid: true},
|
||||
SocialMedia: req.SocialMedia,
|
||||
Website: pgtype.Text{String: req.Website, Valid: len(req.Website) > 0},
|
||||
Website: sql.NullString{String: req.Website, Valid: len(req.Website) > 0},
|
||||
ID: int32(authPayload.UserID),
|
||||
})
|
||||
|
||||
@ -258,7 +258,7 @@ func (server *Server) login(ctx *gin.Context) {
|
||||
|
||||
user, err := server.Store.GetUser(ctx, req.Username)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
if err == sql.ErrNoRows {
|
||||
ctx.JSON(http.StatusNotFound, ErrorResponse(err, "User not found"))
|
||||
return
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
@ -11,7 +12,7 @@ type GetTopListLocationsParams struct {
|
||||
Limit int32
|
||||
Offset int32
|
||||
OrderBy string
|
||||
RegionType pgtype.Int4
|
||||
RegionType sql.NullInt16
|
||||
}
|
||||
|
||||
type GetTopListLocationsRow struct {
|
||||
@ -19,7 +20,7 @@ type GetTopListLocationsRow struct {
|
||||
ID int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RegionName string `json:"region_name"`
|
||||
Thumbnail pgtype.Text `json:"thumbnail"`
|
||||
Thumbnail sql.NullString `json:"thumbnail"`
|
||||
Address string `json:"address"`
|
||||
GoogleMapsLink string `json:"google_maps_link"`
|
||||
RegencyName string `json:"regency_name"`
|
||||
@ -37,7 +38,7 @@ func (q *Queries) GetTopListLocations(ctx context.Context, arg GetTopListLocatio
|
||||
regionType := ""
|
||||
|
||||
if arg.RegionType.Valid {
|
||||
regionType = fmt.Sprintf("AND reg.id = %d", arg.RegionType.Int32)
|
||||
regionType = fmt.Sprintf("AND reg.id = %d", arg.RegionType.Int16)
|
||||
}
|
||||
|
||||
// https://fulmicoton.com/posts/bayesian_rating/
|
||||
@ -117,7 +118,7 @@ type GetLocationRow struct {
|
||||
ProvinceName string `json:"province_name"`
|
||||
RegionName string `json:"region_name"`
|
||||
GoogleMapsLink string `json:"google_maps_link"`
|
||||
Thumbnail pgtype.Text `json:"thumbnail"`
|
||||
Thumbnail sql.NullString `json:"thumbnail"`
|
||||
SubmittedBy string `json:"submitted_by"`
|
||||
CriticScore int32 `json:"critic_score"`
|
||||
CriticCount int32 `json:"critic_count"`
|
||||
@ -195,7 +196,7 @@ type CreateLocationParams struct {
|
||||
RegencyID int16 `json:"regency_id"`
|
||||
GoogleMapsLink pgtype.Text `json:"google_maps_link"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
ApprovedBy pgtype.Int4 `json:"approved_by"`
|
||||
ApprovedBy sql.NullInt32 `json:"approved_by"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateLocation(ctx context.Context, arg CreateLocationParams) (int32, error) {
|
||||
|
@ -2,9 +2,8 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createReview = `-- name: CreateReview :one
|
||||
@ -65,7 +64,7 @@ type GetListLocationReviewsRow struct {
|
||||
Comment string `json:"comments"`
|
||||
UserID int32 `json:"user_id"`
|
||||
Username string `json:"username"`
|
||||
UserAvatar pgtype.Text `json:"user_avatar"`
|
||||
UserAvatar sql.NullString `json:"user_avatar"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
@ -14,7 +15,7 @@ type CreateLocationTxParams struct {
|
||||
RegencyID int16 `json:"regency_id"`
|
||||
GoogleMapsLink pgtype.Text `json:"google_maps_link"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
ApprovedBy pgtype.Int4 `json:"approved_by"`
|
||||
ApprovedBy sql.NullInt32 `json:"approved_by"`
|
||||
Thumbnail []CreateImageParams `json:"thumbnails"`
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,9 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getUserQ = `-- name: GetUser :one
|
||||
@ -41,8 +40,8 @@ type GetUserRow struct {
|
||||
Username string `json:"username"`
|
||||
GoogleSignInPayload string `json:"google_sign_in_payload"`
|
||||
AvatarPicture string `json:"avatar_picture"`
|
||||
BannedAt pgtype.Timestamp `json:"banned_at"`
|
||||
BannedUntil pgtype.Timestamp `json:"banned_until"`
|
||||
BannedAt sql.NullTime `json:"banned_at"`
|
||||
BannedUntil sql.NullTime `json:"banned_until"`
|
||||
BanReason string `json:"ban_reason"`
|
||||
IsPermaban bool `json:"is_permaban"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
@ -174,9 +173,9 @@ RETURNING
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
About pgtype.Text `json:"about"`
|
||||
About sql.NullString `json:"about"`
|
||||
SocialMedia interface{} `json:"social_media"`
|
||||
Website pgtype.Text `json:"website"`
|
||||
Website sql.NullString `json:"website"`
|
||||
ID int32 `json:"id"`
|
||||
}
|
||||
|
||||
@ -188,8 +187,8 @@ type UpdateUserRow struct {
|
||||
About string `json:"about"`
|
||||
Website string `json:"website"`
|
||||
GoogleSignInPayload string `json:"google_sign_in_payload"`
|
||||
BannedAt pgtype.Timestamp `json:"banned_at"`
|
||||
BannedUntil pgtype.Timestamp `json:"banned_until"`
|
||||
BannedAt sql.NullTime `json:"banned_at"`
|
||||
BannedUntil sql.NullTime `json:"banned_until"`
|
||||
BanReason string `json:"ban_reason"`
|
||||
IsPermaban bool `json:"is_permaban"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
|
Loading…
Reference in New Issue
Block a user