Skip to content

Commit

Permalink
Merge branch 'main' of github.com:calblueprint/our-city-forest into a…
Browse files Browse the repository at this point in the history
…pawar/ocf-16-lo-fi-tree-information-screen
  • Loading branch information
adityapawar1 committed Oct 31, 2024
2 parents a2bab88 + 9bd4471 commit 38dc2e8
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@



CC: @insert pl github username here
CC: @christophertorres1 <!-- Include Carys if this PR involves frontend changes -->
14 changes: 10 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"expo": {
"name": "mobile-app-template",
"slug": "mobile-app-template",
"owner": "mobileapptemplate",
"name": "Our City Forest",
"slug": "our-city-forest",
"owner": "calblueprint",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/bp-icon.png",
Expand All @@ -13,9 +13,15 @@
"backgroundColor": "#ffffff"
},
"ios": {
"supportsTablet": true
"bundleIdentifier": "org.calblueprint.ourcityforest",
"supportsTablet": true,
"infoPlist": {
"NSCameraUsageDescription": "This app requires access to the camera to scan QR codes for tree information."
}
},
"android": {
"package": "org.calblueprint.ourcityforest",
"permissions": ["CAMERA"],
"adaptiveIcon": {
"foregroundImage": "./assets/bp-adaptive-icon.png",
"backgroundColor": "#ffffff"
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "mobile-app-template",
"name": "our-city-forest",
"version": "1.0.0",
"main": "expo/AppEntry.js",
"scripts": {
Expand All @@ -21,7 +21,6 @@
"@supabase/supabase-js": "^2.45.4",
"expo": "~51.0.21",
"expo-auth-session": "~5.5.2",
"expo-barcode-scanner": "~13.0.1",
"expo-camera": "~15.0.16",
"expo-constants": "~16.0.2",
"expo-device": "~6.0.2",
Expand Down
242 changes: 242 additions & 0 deletions src/supabase/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
import { supabase } from './client';

// Function to add a single tree
export async function addTree(species: string) {
const { error } = await supabase.rpc('add_tree', { species });

if (error) {
throw new Error(`Error adding tree: ${error.message}`);
}
}

// Function to add multiple trees
export async function addMultipleTrees(species: string, quantity: number) {
const { error } = await supabase.rpc('add_multiple_trees', {
species: species,
quantity: quantity,
});

if (error) {
throw new Error(`Error adding multiple trees: ${error.message}`);
}
}

// Function to remove a single tree by UUID
export async function removeTree(treeId: string) {
const { error } = await supabase.rpc('remove_tree', {
tree_uuid: treeId,
});

if (error) {
throw new Error(`Error removing tree: ${error.message}`);
}
}

// Function to remove multiple trees by a list of UUIDs
export async function removeMultipleTrees(treeIds: string[]) {
const { error } = await supabase.rpc('remove_multiple_trees', {
tree_uuids: treeIds,
});

if (error) {
throw new Error(`Error removing multiple trees: ${error.message}`);
}
}

// Retrieves tree info by UUID, returns properties as JSON: { "bank": null, "date": null, "health_status": null, ... }
export async function getTreeInfo(treeId: string) {
const { data, error } = await supabase.rpc('get_tree_by_uuid', {
tree_uuid: treeId,
});

if (error) {
throw new Error(`Error retrieving tree info: ${error.message}`);
}

return data;
}

// Functions to update each property

// Update species
export async function updateTreeSpecies(treeId: string, newSpecies: string) {
const { error } = await supabase
.from('trees')
.update({ species: newSpecies })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating species: ${error.message}`);
}
}

// Update street address
export async function updateTreeStreetAddress(
treeId: string,
newAddress: string,
) {
const { error } = await supabase
.from('trees')
.update({ street_address: newAddress })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating street address: ${error.message}`);
}
}

// Update bank
export async function updateTreeBank(treeId: string, newBank: number) {
const { error } = await supabase
.from('trees')
.update({ bank: newBank })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating bank: ${error.message}`);
}
}

// Update row
export async function updateTreeRow(treeId: string, newRow: number) {
const { error } = await supabase
.from('trees')
.update({ row: newRow })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating row: ${error.message}`);
}
}

// Update health status
export async function updateTreeHealthStatus(
treeId: string,
newHealthStatus: string,
) {
const { error } = await supabase
.from('trees')
.update({ health_status: newHealthStatus })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating health status: ${error.message}`);
}
}

// Update planted status
export async function updateTreePlanted(treeId: string, isPlanted: boolean) {
const { error } = await supabase
.from('trees')
.update({ planted: isPlanted })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating planted status: ${error.message}`);
}
}

// Update sold status
export async function updateTreeSold(treeId: string, isSold: boolean) {
const { error } = await supabase
.from('trees')
.update({ sold: isSold })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating sold status: ${error.message}`);
}
}

// Update reserved status
export async function updateTreeReserved(treeId: string, isReserved: boolean) {
const { error } = await supabase
.from('trees')
.update({ reserved: isReserved })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating reserved status: ${error.message}`);
}
}

// Update reserved for
export async function updateTreeReservedFor(
treeId: string,
reservedFor?: string,
) {
const { error } = await supabase
.from('trees')
.update({ reserved_for: reservedFor })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating reserved for: ${error.message}`);
}
}

// Update street ready status
export async function updateTreeStreetReady(
treeId: string,
isStreetReady?: boolean,
) {
const { error } = await supabase
.from('trees')
.update({ street_ready: isStreetReady })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating street ready status: ${error.message}`);
}
}

// Update required action
export async function updateTreeRequiredAction(
treeId: string,
requiredAction?: string,
) {
const { error } = await supabase
.from('trees')
.update({ required_action: requiredAction })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating required action: ${error.message}`);
}
}

// Update source
export async function updateTreeSource(treeId: string, source?: string) {
const { error } = await supabase
.from('trees')
.update({ source })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating source: ${error.message}`);
}
}

// Update date
export async function updateTreeDate(treeId: string, date?: Date) {
const { error } = await supabase
.from('trees')
.update({ date })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating date: ${error.message}`);
}
}

// Update QR code URL
export async function updateTreeQrCodeUrl(treeId: string, qrCodeUrl?: string) {
const { error } = await supabase
.from('trees')
.update({ qr_code_url: qrCodeUrl })
.eq('tree_id', treeId);

if (error) {
throw new Error(`Error updating QR code URL: ${error.message}`);
}
}

0 comments on commit 38dc2e8

Please sign in to comment.