Skip to content

Commit

Permalink
finished both states
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattchris committed Dec 4, 2024
1 parent 0b55bbc commit 9467b49
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 117 deletions.
2 changes: 1 addition & 1 deletion backend/internal/handlers/venues/venues.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ func (s *Service) GetVenuesByIDs(c *fiber.Ctx) error {
"error": "Missing venue IDs",
})
}


// Split the IDs into a slice
idStrings := strings.Split(ids, ",")
Expand Down Expand Up @@ -256,6 +255,7 @@ func (s *Service) GetVenuesByIDs(c *fiber.Ctx) error {
func (s *Service) GetVenuesByLocation(c *fiber.Ctx) error {
// Parse latitude
latitude := c.QueryFloat("latitude")
fmt.Print(latitude)
if latitude == 0 {
log.Printf("Invalid or missing latitude parameter: %v", latitude)
return fiber.NewError(fiber.StatusBadRequest, "Invalid or missing latitude parameter")
Expand Down
53 changes: 5 additions & 48 deletions backend/internal/storage/postgres/venues.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,60 +206,17 @@ func (db *DB) GetVenuesByLocation(ctx context.Context, latitude float64, longitu
FROM venue
WHERE ST_DWithin(
location::geography,
ST_MakePoint($1, $2)::geography,
$3
);
ST_MakePoint($1, $2)::geography, $3) limit 20
`

rows, err := db.conn.Query(ctx, query, longitude, latitude, radiusInMeters)
rows, err := db.conn.Query(ctx, query, latitude, longitude, radiusInMeters)
if err != nil {
log.Printf("Database query failed: %v | Query: %s | Params: longitude=%f, latitude=%f, radius=%d", err, query, longitude, latitude, radiusInMeters)
return nil, fmt.Errorf("database query error: %w", err)
}
defer rows.Close() // No need to handle rows.Close()'s return, just defer the call

venues := []models.Venue{}
for rows.Next() {
var venue models.Venue
if err := rows.Scan(
&venue.VenueID,
&venue.Name,
&venue.Address,
&venue.City,
&venue.State,
&venue.ZipCode,
&venue.Latitude,
&venue.Longitude,
&venue.VenueType,
&venue.TotalRating,
&venue.Price,
&venue.AvgMainstream,
&venue.AvgPrice,
&venue.AvgExclusive,
&venue.AvgEnergy,
&venue.MondayHours,
&venue.TuesdayHours,
&venue.WednesdayHours,
&venue.ThursdayHours,
&venue.FridayHours,
&venue.SaturdayHours,
&venue.SundayHours,
&venue.CreatedAt,
&venue.UpdatedAt,
); err != nil {
log.Printf("Error scanning row: %v", err)
return nil, fmt.Errorf("row scan error: %w", err)
}
venues = append(venues, venue)
}

// Check for errors in row iteration
if err := rows.Err(); err != nil {
log.Printf("Row iteration error: %v", err)
return nil, fmt.Errorf("row iteration error: %w", err)
}

return venues, nil
defer rows.Close()
arr, err := pgx.CollectRows(rows, pgx.RowToStructByName[models.Venue])
return arr, err
}

func (db *DB) GetAllVenuesWithFilter(ctx context.Context, where string, sort string) ([]models.Venue, error) {
Expand Down
3 changes: 3 additions & 0 deletions frontend/assets/location.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 24 additions & 16 deletions frontend/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ import { ScrollView, View, StyleSheet } from "react-native";
import SearchBar from "@/components/Map/SearchBar";
import EventsScrollable from "./explore/EventsScrollable";

const HomeScreen: React.FC = () => {
return (
<View style={styles.container}>
<SearchBar placeholderText="Search venues..." />
<ScrollView contentContainerStyle={styles.scrollableContent}>
<EventsScrollable title={"On Your Radar"} accent="#382873"/>
<EventsScrollable title={"Recommended for You"} accent="#382873" />
<EventsScrollable title={"Hidden Grooves"} persona="BIRD" accent={"#F1B149"} />
<EventsScrollable title={"Opus Evenings"} persona="CAT" accent={"#E1675A"} />
<EventsScrollable title={"Fun, Flirty, Fierce!"} persona="GIRL" accent={"#D976AF"} />
<EventsScrollable title={"Taste Adventure"} persona="GREEN" accent={"#90ad50"} />
<EventsScrollable title={"Kick Back & Unwind"} persona="MAN" accent={"#C39C3D"} />
<EventsScrollable title={"Anything Can Happen"} persona="MERMAID" accent={"#7b82ad"} />
<EventsScrollable title={"Electric Vibes"} persona="ZAP" accent={"#268ECE"} />
</ScrollView>
interface HomeScreenProps {
showSearchBar?: boolean;
}

const HomeScreen: React.FC<HomeScreenProps> = ({ showSearchBar = true }) => {
return (
<View style={styles.container}>
{showSearchBar && (
<View style={styles.searchBarContainer}>
<SearchBar placeholderText="Search venues..." />
</View>
);
)}
<ScrollView contentContainerStyle={styles.scrollableContent}>
<EventsScrollable title={"On Your Radar"} accent="#382873" />
<EventsScrollable title={"Recommended for You"} accent="#382873" />
<EventsScrollable title={"Hidden Grooves"} persona="BIRD" accent={"#F1B149"} />
<EventsScrollable title={"Opus Evenings"} persona="CAT" accent={"#E1675A"} />
<EventsScrollable title={"Fun, Flirty, Fierce!"} persona="GIRL" accent={"#D976AF"} />
<EventsScrollable title={"Taste Adventure"} persona="GREEN" accent={"#90ad50"} />
<EventsScrollable title={"Kick Back & Unwind"} persona="MAN" accent={"#C39C3D"} />
<EventsScrollable title={"Anything Can Happen"} persona="MERMAID" accent={"#7b82ad"} />
<EventsScrollable title={"Electric Vibes"} persona="ZAP" accent={"#268ECE"} />
</ScrollView>
</View>
);
};

const styles = StyleSheet.create({
Expand Down
126 changes: 74 additions & 52 deletions frontend/screens/MapScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,70 @@ import { Venue } from "@/types/Venue";
import { useAuth } from "@/context/AuthContext";
import React from "react";
import HomeScreen from "./HomeScreen";
import EventCard from "./explore/EventCard";

const MapScreen: React.FC = () => {
const [allVenues, setAllVenues] = useState<Venue[]>([]);
const [selectedVenue, setSelectedVenue] = useState<Venue | null>(null);
const [mapKey, setMapKey] = useState(0);
const { user, accessToken } = useAuth();
const modalRef = React.useRef<Modalize>(null);



const fetchVenues = async (): Promise<void> => {
if (!accessToken || !user?.location) {
console.log("No access token available or user location available");
return;
}


try {

const locationRes = await fetch(
`${API_DOMAIN}/profiles/${user.user_id}/location`,
{
method: "GET",
headers: {
"Authorization": `Bearer ${accessToken}`,
Authorization: `Bearer ${accessToken}`,
},
}
);

if (!locationRes.ok)
throw new Error(`Error fetching user location: ${locationRes.statusText}`);
throw new Error(
`Error fetching user location: ${locationRes.statusText}`
);
const { latitude, longitude } = await locationRes.json();



// Fetch venues by location
// Fetch venues by location
const radius = 80000; // 80,000 meters (80 km)
const venuesRes = await fetch(
`${API_DOMAIN}/venues/location?latitude=${latitude}&longitude=${longitude}&radius=${radius}`,
// `${API_DOMAIN}/venues`,
{
method: "GET",
headers: {
"Authorization": `Bearer ${accessToken}`,
Authorization: `Bearer ${accessToken}`,
},
}
);

if (!venuesRes.ok)
if (!venuesRes.ok) {
throw new Error(`Error fetching venues: ${venuesRes.statusText}`);
}
const venues: Venue[] = await venuesRes.json();
console.log(venues[1]);

setAllVenues(venues);
setMapKey((prevKey) => prevKey + 1);
} catch (err) {
console.error("Failed to fetch venues by location:", err);
}
};

const getPriceRepresentation = (price: number | undefined): string => {
// Fallback to 1 star if price is undefined or 0
if (!price || price === 0) {
return "$";
}
// Return the correct number of dollar signs
return "$".repeat(price);
};

useEffect(() => {
Expand All @@ -81,29 +90,36 @@ const MapScreen: React.FC = () => {
modalRef.current?.open();
};

// // Get the current day of the week for displaying venue hours
// const getCurrentDayHours = (venue: Venue): string => {
// const days = [
// "monday_hours",
// "tuesday_hours",
// "wednesday_hours",
// "thursday_hours",
// "friday_hours",
// "saturday_hours",
// "sunday_hours",
// ];
// const today = new Date().getDay();
// return venue[days[today - 1]] || "Hours not available";
// };
// Get the current day of the week for displaying venue hours
const getCurrentDayHours = (venue: Venue): string | number => {
const days = [
"monday_hours",
"tuesday_hours",
"wednesday_hours",
"thursday_hours",
"friday_hours",
"saturday_hours",
"sunday_hours",
];
const today = new Date().getDay();
const dayKey = days[today - 1] as keyof Venue;

if (venue[dayKey] == "NULL") {
return "Hours not available";
}

return venue[dayKey] || "Hours not available";
};

return (
<GestureHandlerRootView style={{ flex: 1 }}>
<View style={styles.container}>
{/* Floating Search Bar */}
<SearchBar placeholderText="Search for venues"/>
<SearchBar placeholderText="Search for venues" />

{/* Map */}
<MapView
key={mapKey}
style={styles.map}
initialRegion={{
latitude: 42.3601,
Expand All @@ -130,6 +146,7 @@ const MapScreen: React.FC = () => {
style={styles.markerImage}
resizeMode="contain"
/>
{/* <LocationIcon/> */}
</View>
</Marker>
))}
Expand Down Expand Up @@ -173,9 +190,7 @@ const MapScreen: React.FC = () => {
<View style={styles.ratingContainer}>
{/* Stand-in Rating */}
<Text style={styles.standInRating}>
{selectedVenue.total_rating
? selectedVenue.total_rating.toFixed(1)
: "4.2"}
{selectedVenue.total_rating}
</Text>

{/* Star Icon */}
Expand All @@ -189,35 +204,35 @@ const MapScreen: React.FC = () => {
<Text style={styles.divider}>|</Text>

{/* Money Sign */}
<Text style={styles.moneySign}>$$$</Text>
<Text style={styles.moneySign}>
{getPriceRepresentation(selectedVenue?.price)}
</Text>

{/* Divider */}
<Text style={styles.divider}>|</Text>

{/* Open Status */}
{/* <Text style={styles.statusText}>
{/* Hours for the Day */}
<Text style={styles.statusText}>
{getCurrentDayHours(selectedVenue)}
</Text> */}
<Text style={styles.statusText}>🟢 Open</Text>
</Text>
</View>

{/* Centered EventCard */}
<View style={styles.eventCardContainer}>
<EventCard
key={selectedVenue.venue_id}
image={
"https://academy.la/wp-content/uploads/2024/06/best-club-near-me-hollywood-1024x576.webp"
}
title={selectedVenue.name}
subtitle={`${selectedVenue.city}, ${selectedVenue.state}`}
accent={"#2d2d44"}
venue_id={selectedVenue.venue_id}
/>
</View>
</View>
) : (
// TODO: Replace with Ben's explore page
// Venue List View
// <View style={styles.modalContent}>
// <Text style={styles.listTitle}>All Venues</Text>
// {allVenues.map((venue) => (
// <TouchableOpacity
// key={venue.venue_id}
// onPress={() => handleMarkerPress(venue)}
// style={styles.venueItem}
// >
// <Text style={styles.venueName}>{venue.name}</Text>
// <Text style={styles.venueAddress}>{venue.address}</Text>
// </TouchableOpacity>
// ))}
// </View>
<HomeScreen/>
<HomeScreen showSearchBar={false} />
)}
</Modalize>
</View>
Expand Down Expand Up @@ -352,9 +367,16 @@ const styles = StyleSheet.create({
},
statusText: {
fontSize: 18,
color: "#00FF00",
color: "#FFFFFF",
marginLeft: 5,
},
eventCardContainer: {
width: "100%",
justifyContent: "center",
alignItems: "center",
marginTop: 20,
paddingHorizontal: 10, // Add some padding for aesthetic spacing
},
});

export default MapScreen;
8 changes: 8 additions & 0 deletions frontend/types/Venue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ export interface Venue {
created_at: string;
total_rating: number;
price: number;
monday_hours: string;
tuesday_hours: string;
wednesday_hours: string;
thursday_horus: string;
friday_hours: string;
saturday_hours: string;
sunday_hours: string;

}

0 comments on commit 9467b49

Please sign in to comment.