Skip to content

Commit c9d7a37

Browse files
author
Anthony Li
committed
Change map placement and description and address comments
1 parent cf2f97a commit c9d7a37

7 files changed

Lines changed: 39 additions & 28 deletions

File tree

backend/market/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import hashlib
22
import math
3+
import hmac
34

45
from django.contrib.auth.models import AbstractUser
56
from django.core.exceptions import ValidationError
67
from django.core.validators import MinValueValidator
78
from django.db import models
9+
from django.conf import settings
810
from phonenumber_field.modelfields import PhoneNumberField
911

1012

@@ -146,7 +148,11 @@ def _calculate_approximate_location(self, latitude, longitude):
146148

147149
lat_str = f"{float(latitude):.9f}"
148150
lon_str = f"{float(longitude):.9f}"
149-
seed = hashlib.md5(f"{lat_str}{lon_str}".encode()).hexdigest()
151+
seed = hmac.new(
152+
settings.SECRET_KEY.encode(),
153+
f"{lat_str}{lon_str}".encode(),
154+
hashlib.sha256,
155+
).hexdigest()
150156

151157
offset_factor = int(seed[:8], 16) / 0xFFFFFFFF
152158

backend/market/serializers.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,26 @@ class SubletDataSerializer(ModelSerializer):
104104

105105
class Meta:
106106
model = Sublet
107-
fields = ["street_address", "beds", "baths", "start_date", "end_date",
108-
"latitude", "longitude"]
107+
fields = [
108+
"street_address",
109+
"beds",
110+
"baths",
111+
"start_date",
112+
"end_date",
113+
"latitude",
114+
"longitude",
115+
]
109116

110117
def get_latitude(self, obj):
111-
if obj.approximate_location is not None:
112-
return float(obj.approximate_location[0])
118+
approx_lat, _ = obj.approximate_location
119+
if approx_lat is not None:
120+
return float(approx_lat)
113121
return None
114122

115123
def get_longitude(self, obj):
116-
if obj.approximate_location is not None:
117-
return float(obj.approximate_location[1])
124+
_, approx_lon = obj.approximate_location
125+
if approx_lon is not None:
126+
return float(approx_lon)
118127
return None
119128

120129
# Unified serializer for all listing types (Items and Sublets); used for CRUD operations

docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ services:
6868
- penn-marketplace-frontend-pnpm-store:/app/.pnpm-store
6969
environment:
7070
- NODE_ENV=development
71-
# Browser on your machine → API on published port
7271
- NEXT_PUBLIC_API_URL=http://localhost:8000
73-
# Next server inside this container → Django service name
74-
- API_BASE_URL=http://backend:8000
7572

7673
volumes:
7774
penn-marketplace-postgres-data:

frontend/components/listings/detail/ListingDetail.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,26 @@ export const ListingDetail = ({ listing, initialIsFavorited }: Props) => {
8989
{...listing.additional_data}
9090
/>
9191
<UserCard user={listing.seller} label={listingOwnerLabel} />
92-
<ListingActions
93-
listingId={listing.id}
94-
listingPrice={listing.price}
95-
priceLabel={priceLabel}
96-
listingOwnerLabel={listingOwnerLabel}
97-
/>
9892
{hasLocation && (
9993
<div className="space-y-3">
100-
<h2 className="text-lg font-semibold">{"Where you'll be living"}</h2>
94+
<div>
95+
<h2 className="text-lg font-semibold">{"Where you'll be living"}</h2>
96+
<p className="text-sm text-gray-500">
97+
Approximate location shown. The exact location will be shared once you connect with the owner.
98+
</p>
99+
</div>
101100
<SubletMap
102101
latitude={subletCoords.latitude!}
103102
longitude={subletCoords.longitude!}
104103
/>
105104
</div>
106105
)}
106+
<ListingActions
107+
listingId={listing.id}
108+
listingPrice={listing.price}
109+
priceLabel={priceLabel}
110+
listingOwnerLabel={listingOwnerLabel}
111+
/>
107112
</div>
108113
</div>
109114
</div>

frontend/components/listings/detail/SubletMap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface Props {
99

1010
const LazyMap = dynamic(
1111
() =>
12-
import("./SubletMapContent").then((m) => m.SubletMapContent),
12+
import("@/components/listings/detail/SubletMapContent").then((m) => m.SubletMapContent),
1313
{ ssr: false },
1414
);
1515

frontend/lib/constants.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ import {
99
export const BASE_URL =
1010
process.env.NODE_ENV === "production" ? "REPLACE WITH PROD BASE URL" : "http://localhost:3000";
1111

12-
/**
13-
* Server-side fetches (RSC, Route Handlers, middleware).
14-
* - Local `pnpm dev`: default http://localhost:8000 (backend on host port).
15-
* - Docker frontend service: set API_BASE_URL=http://backend:8000 in compose.
16-
*/
1712
export const API_BASE_URL =
18-
process.env.NODE_ENV === "production"
19-
? process.env.NEXT_PUBLIC_API_URL ?? "REPLACE WITH PROD API URL"
20-
: (process.env.API_BASE_URL ?? "http://localhost:8000");
13+
process.env.NODE_ENV === "production" ? "REPLACE WITH PROD API URL" : "http://backend:8000"; // can't be localhost because server fetch happens in container
14+
2115

2216
export const PLATFORM_URL = process.env.PLATFORM_URL;
2317
export const CLIENT_ID = process.env.CLIENT_ID;

frontend/lib/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export type SubletAdditionalData = {
4444
baths: number;
4545
start_date: string;
4646
end_date: string;
47-
latitude?: number;
48-
longitude?: number;
47+
latitude: number;
48+
longitude: number;
4949
};
5050

5151
// ------------------------------------------------------------

0 commit comments

Comments
 (0)