feat:migrate location name from finds to location table and update the frontend components to reflect the change.

This commit is contained in:
2025-12-16 12:53:59 +01:00
parent d67b9b7911
commit 577a3cab56
8 changed files with 875 additions and 21 deletions

View File

@@ -14,7 +14,6 @@
let title = $state('');
let description = $state('');
let locationName = $state('');
let category = $state('cafe');
let isPublic = $state(true);
let selectedFiles = $state<FileList | null>(null);
@@ -93,7 +92,6 @@
locationId,
title: title.trim(),
description: description.trim() || null,
locationName: locationName.trim() || null,
category,
isPublic,
media: uploadedMedia
@@ -118,7 +116,6 @@
function resetForm() {
title = '';
description = '';
locationName = '';
category = 'cafe';
isPublic = true;
selectedFiles = null;
@@ -177,15 +174,6 @@
></textarea>
</div>
<div class="field">
<Label for="location-name">Location name (optional)</Label>
<Input
name="location-name"
placeholder="Café Central, Brussels"
bind:value={locationName}
/>
</div>
<div class="field-group">
<div class="field">
<Label for="category">Category</Label>

View File

@@ -16,6 +16,7 @@
let latitude = $state('');
let longitude = $state('');
let locationName = $state('');
let isSubmitting = $state(false);
let useManualLocation = $state(false);
@@ -59,7 +60,8 @@
},
body: JSON.stringify({
latitude: lat,
longitude: lng
longitude: lng,
locationName: locationName.trim() || null
})
});
@@ -85,6 +87,7 @@
}
function handlePlaceSelected(place: PlaceResult) {
locationName = place.name;
latitude = place.latitude.toString();
longitude = place.longitude.toString();
}
@@ -100,6 +103,7 @@
function resetForm() {
latitude = '';
longitude = '';
locationName = '';
useManualLocation = false;
}
@@ -158,6 +162,16 @@
{/if}
</div>
<div class="field">
<Label for="location-name">Location Name (Optional)</Label>
<Input
name="location-name"
type="text"
placeholder="Café Central, Brussels"
bind:value={locationName}
/>
</div>
{#if useManualLocation || (!latitude && !longitude)}
<div class="field-group">
<div class="field">

View File

@@ -29,6 +29,7 @@ export const location = pgTable('location', {
.references(() => user.id, { onDelete: 'cascade' }),
latitude: text('latitude').notNull(), // Using text for precision
longitude: text('longitude').notNull(), // Using text for precision
locationName: text('location_name'), // e.g., "Café Belga, Brussels"
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).defaultNow().notNull()
});
@@ -43,7 +44,6 @@ export const find = pgTable('find', {
.references(() => user.id, { onDelete: 'cascade' }),
title: text('title').notNull(),
description: text('description'),
locationName: text('location_name'), // e.g., "Café Belga, Brussels"
category: text('category'), // e.g., "cafe", "restaurant", "park", "landmark"
isPublic: integer('is_public').default(1), // Using integer for boolean (1 = true, 0 = false)
createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).defaultNow().notNull(),

View File

@@ -70,7 +70,7 @@ export const GET: RequestHandler = async ({ url, locals }) => {
locationId: find.locationId,
title: find.title,
description: find.description,
locationName: find.locationName,
locationName: location.locationName,
category: find.category,
isPublic: find.isPublic,
createdAt: find.createdAt,
@@ -98,9 +98,10 @@ export const GET: RequestHandler = async ({ url, locals }) => {
})
.from(find)
.innerJoin(user, eq(find.userId, user.id))
.innerJoin(location, eq(find.locationId, location.id))
.leftJoin(findLike, eq(find.id, findLike.findId))
.where(whereConditions)
.groupBy(find.id, user.username, user.profilePictureUrl)
.groupBy(find.id, user.username, user.profilePictureUrl, location.locationName)
.orderBy(order === 'desc' ? desc(find.createdAt) : find.createdAt);
// Get media for all finds
@@ -198,7 +199,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
}
const data = await request.json();
const { locationId, title, description, locationName, category, isPublic, media } = data;
const { locationId, title, description, category, isPublic, media } = data;
if (!title || !locationId) {
throw error(400, 'Title and locationId are required');
@@ -234,7 +235,6 @@ export const POST: RequestHandler = async ({ request, locals }) => {
userId: locals.user.id,
title,
description,
locationName,
category,
isPublic: isPublic ? 1 : 0
})

View File

@@ -66,6 +66,7 @@ export const GET: RequestHandler = async ({ url, locals }) => {
id: location.id,
latitude: location.latitude,
longitude: location.longitude,
locationName: location.locationName,
createdAt: location.createdAt,
userId: location.userId,
username: user.username,
@@ -109,7 +110,6 @@ export const GET: RequestHandler = async ({ url, locals }) => {
id: find.id,
title: find.title,
description: find.description,
locationName: find.locationName,
category: find.category,
isPublic: find.isPublic,
createdAt: find.createdAt,
@@ -239,7 +239,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
}
const data = await request.json();
const { latitude, longitude } = data;
const { latitude, longitude, locationName } = data;
if (!latitude || !longitude) {
throw error(400, 'Latitude and longitude are required');
@@ -254,7 +254,8 @@ export const POST: RequestHandler = async ({ request, locals }) => {
id: locationId,
userId: locals.user.id,
latitude: latitude.toString(),
longitude: longitude.toString()
longitude: longitude.toString(),
locationName: locationName || null
})
.returning();