2023-09-13 21:42:04 +07:00
|
|
|
-- name: GetListLocations :many
|
2023-09-14 13:49:03 +07:00
|
|
|
SELECT * FROM locations;
|
2023-09-13 21:42:04 +07:00
|
|
|
|
2023-09-14 22:51:01 +07:00
|
|
|
-- name: GetListRecentLocationsWithRatings :many
|
|
|
|
SELECT
|
|
|
|
l.id,
|
|
|
|
name,
|
|
|
|
thumbnail,
|
|
|
|
re.regency_name,
|
|
|
|
(SELECT COALESCE(SUM(score), -1) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_score,
|
|
|
|
(SELECT COUNT(id) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_count,
|
|
|
|
(SELECT COALESCE(SUM(score), -1) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_score,
|
|
|
|
(SELECT COUNT(id) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_count
|
|
|
|
FROM locations l
|
|
|
|
JOIN regencies re on re.id = l.regency_id
|
|
|
|
WHERE approved_by IS NOT NULL
|
|
|
|
ORDER BY l.created_at ASC
|
|
|
|
LIMIT $1;
|
|
|
|
|
|
|
|
|
2023-09-13 21:42:04 +07:00
|
|
|
-- name: GetLocation :one
|
|
|
|
SELECT * FROM locations
|
|
|
|
WHERE id = $1;
|
|
|
|
|
|
|
|
-- name: CreateLocation :exec
|
|
|
|
INSERT INTO locations(
|
|
|
|
address,
|
|
|
|
name,
|
|
|
|
submitted_by,
|
|
|
|
regency_id,
|
|
|
|
google_maps_link
|
|
|
|
) values (
|
|
|
|
$1, $2, $3, $4, $5
|
|
|
|
);
|