2023-09-13 21:42:04 +07:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
2024-02-06 11:55:25 +07:00
|
|
|
// sqlc v1.25.0
|
2023-09-13 21:42:04 +07:00
|
|
|
// source: locations.sql
|
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-02-06 11:55:25 +07:00
|
|
|
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
2023-09-13 21:42:04 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
const getListLocations = `-- name: GetListLocations :many
|
2023-10-02 08:49:41 +07:00
|
|
|
SELECT id, address, name, google_maps_link, location_type, submitted_by, total_visited, thumbnail, regency_id, is_deleted, created_at, updated_at, approved_by, approved_at FROM locations
|
2023-09-13 21:42:04 +07:00
|
|
|
`
|
|
|
|
|
2023-09-14 13:49:03 +07:00
|
|
|
func (q *Queries) GetListLocations(ctx context.Context) ([]Location, error) {
|
2024-02-06 11:55:25 +07:00
|
|
|
rows, err := q.db.Query(ctx, getListLocations)
|
2023-09-13 21:42:04 +07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
items := []Location{}
|
|
|
|
for rows.Next() {
|
|
|
|
var i Location
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Address,
|
|
|
|
&i.Name,
|
|
|
|
&i.GoogleMapsLink,
|
2023-10-02 08:49:41 +07:00
|
|
|
&i.LocationType,
|
2023-09-13 21:42:04 +07:00
|
|
|
&i.SubmittedBy,
|
|
|
|
&i.TotalVisited,
|
|
|
|
&i.Thumbnail,
|
|
|
|
&i.RegencyID,
|
|
|
|
&i.IsDeleted,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.UpdatedAt,
|
|
|
|
&i.ApprovedBy,
|
|
|
|
&i.ApprovedAt,
|
|
|
|
); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
2023-09-20 13:37:14 +07:00
|
|
|
const getLocationTag = `-- name: GetLocationTag :many
|
|
|
|
SELECT
|
|
|
|
name
|
|
|
|
FROM tags
|
|
|
|
WHERE tags_type = 'location'
|
|
|
|
AND
|
|
|
|
target_id = $1
|
|
|
|
AND
|
|
|
|
approved_by IS NOT NULL
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetLocationTag(ctx context.Context, targetID int32) ([]string, error) {
|
2024-02-06 11:55:25 +07:00
|
|
|
rows, err := q.db.Query(ctx, getLocationTag, targetID)
|
2023-09-20 13:37:14 +07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
items := []string{}
|
|
|
|
for rows.Next() {
|
|
|
|
var name string
|
|
|
|
if err := rows.Scan(&name); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, name)
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
2023-10-03 19:44:31 +07:00
|
|
|
|
|
|
|
const updateLocationThumbnail = `-- name: UpdateLocationThumbnail :exec
|
|
|
|
UPDATE locations
|
|
|
|
SET thumbnail = $1
|
|
|
|
WHERE id = $2
|
|
|
|
`
|
|
|
|
|
|
|
|
type UpdateLocationThumbnailParams struct {
|
2024-02-06 11:55:25 +07:00
|
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
|
|
ID int32 `json:"id"`
|
2023-10-03 19:44:31 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdateLocationThumbnail(ctx context.Context, arg UpdateLocationThumbnailParams) error {
|
2024-02-06 11:55:25 +07:00
|
|
|
_, err := q.db.Exec(ctx, updateLocationThumbnail, arg.Thumbnail, arg.ID)
|
2023-10-03 19:44:31 +07:00
|
|
|
return err
|
|
|
|
}
|