Skip to content

GeoDiary is an automated travel log application that allows the user to log various travel locations of their trip by storing images on database. Users can save or delete those images as well as see how much distance they've travelled so far.

Notifications You must be signed in to change notification settings

AT0117/geodiary

Repository files navigation

GeoDiary

This project is an extension to a little mini-project I created a few days ago called "GeoLens".
GeoDiary is an automated travel log application that allows the user to log various travel locations of their trip by storing images on database.
Users can save or delete those images as well as see how much distance they've travelled so far.

Preview

geodiary.mp4

Supabase Setup

  1. Go to Storage > Buckets.
  2. Create a bucket named photos.
  3. IMPORTANT: Toggle "Public Bucket" to ON.
  4. Policies: Add a policy to photos -> "Give users access to their own folder" (SELECT, INSERT, UPDATE, DELETE) -> bucket_id = 'photos' AND (storage.foldername(name))[1] = auth.uid()::text.

Execute this query -
-- 1. Reset Schema
drop table if exists public.logs;
drop table if exists public.trips;

-- 2. Create Tables
create table public.trips (
  id uuid default gen_random_uuid() primary key,
  user_id uuid references auth.users not null,
  name text not null,
  is_active boolean default true,
  created_at timestamp with time zone default now()
);

create table public.logs (
  id uuid default gen_random_uuid() primary key,
  user_id uuid references auth.users not null,
  trip_id uuid references public.trips(id) on delete cascade,
  image_url text not null,
  lat double precision not null,
  lng double precision not null,
  address text,
  distance_km double precision default 0,
  created_at timestamp with time zone default now()
);

-- 3. Enable Security (RLS)
alter table public.trips enable row level security;
alter table public.logs enable row level security;

-- 4. Create Strict Policies
create policy "Users can only see their own trips"
on public.trips for all
using (auth.uid() = user_id);

create policy "Users can only see their own logs"
on public.logs for all
using (auth.uid() = user_id);

-- 5. Create Journey Function
create or replace function start_new_journey(journey_name text)
returns void as $$
begin
  -- Mark previous trips as inactive for THIS user
  update public.trips 
  set is_active = false 
  where user_id = auth.uid();
  
  -- Start new trip
  insert into public.trips (user_id, name, is_active)
  values (auth.uid(), journey_name, true);
end;
$$ language plpgsql security definer;

About

GeoDiary is an automated travel log application that allows the user to log various travel locations of their trip by storing images on database. Users can save or delete those images as well as see how much distance they've travelled so far.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published