Skip to content

Commit

Permalink
Add sublet negotiable, swap max/min to reg price fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-Jess committed Feb 9, 2024
1 parent 78fc33e commit f4efde6
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
18 changes: 18 additions & 0 deletions backend/sublet/migrations/0002_auto_20240209_1649.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.24 on 2024-02-09 21:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("sublet", "0001_initial"),
]

operations = [
migrations.RenameField(model_name="sublet", old_name="max_price", new_name="price",),
migrations.RemoveField(model_name="sublet", name="min_price",),
migrations.AddField(
model_name="sublet", name="negotiable", field=models.BooleanField(default=True),
),
]
5 changes: 2 additions & 3 deletions backend/sublet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ class Sublet(models.Model):
baths = models.IntegerField(null=True, blank=True)
description = models.TextField(null=True, blank=True)
external_link = models.URLField(max_length=255)
# TODO: change to just one price field and migrateeeee
min_price = models.IntegerField()
max_price = models.IntegerField()
price = models.IntegerField()
negotiable = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
expires_at = models.DateTimeField()
start_date = models.DateField()
Expand Down
12 changes: 6 additions & 6 deletions backend/sublet/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class Meta:
"baths",
"description",
"external_link",
"min_price",
"max_price",
"price",
"negotiable",
"start_date",
"end_date",
"expires_at",
Expand Down Expand Up @@ -138,8 +138,8 @@ class Meta:
"baths",
"description",
"external_link",
"min_price",
"max_price",
"price",
"negotiable",
"start_date",
"end_date",
"expires_at",
Expand All @@ -162,8 +162,8 @@ class Meta:
"address",
"beds",
"baths",
"min_price",
"max_price",
"price",
"negotiable",
"start_date",
"end_date",
"images",
Expand Down
9 changes: 5 additions & 4 deletions backend/sublet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def list(self, request, *args, **kwargs):
ends_after = params.get("ends_after", None)
min_price = params.get("min_price", None)
max_price = params.get("max_price", None)
negotiable = params.get("negotiable", None)
beds = params.get("beds", None)
baths = params.get("baths", None)

Expand All @@ -158,10 +159,10 @@ def list(self, request, *args, **kwargs):
queryset = queryset.filter(end_date__lt=ends_before)
if ends_after:
queryset = queryset.filter(end_date__gt=ends_after)
if min_price:
queryset = queryset.filter(min_price__gte=min_price)
if max_price:
queryset = queryset.filter(max_price__lte=max_price)
if min_price and max_price:
queryset = queryset.filter(price__gte=min_price).filter(price__lte=max_price)
if negotiable:
queryset = queryset.filter(negotiable=negotiable)

Check warning on line 165 in backend/sublet/views.py

View check run for this annotation

Codecov / codecov/patch

backend/sublet/views.py#L165

Added line #L165 was not covered by tests
if beds:
queryset = queryset.filter(beds=beds)
if baths:
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/sublet/mock_sublets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"baths": 2,
"description": "Test sublet 1",
"external_link": "https://pennlabs.org/",
"min_price": 10,
"max_price": 500,
"price": 1000,
"negotiable": true,
"expires_at": "3000-02-01T10:48:02-05:00",
"start_date": "3000-04-09",
"end_date": "3000-08-07"
Expand All @@ -19,8 +19,8 @@
"baths": 1,
"description": "This is test sublet2!!!",
"external_link": "https://www.google.com/maps",
"min_price": 0,
"max_price": 1000000,
"price": 1000,
"negotiable": false,
"expires_at": "2999-11-28T10:49:10-05:00",
"start_date": "3000-12-19",
"end_date": "3001-03-07"
Expand Down
31 changes: 16 additions & 15 deletions backend/tests/sublet/test_sublets.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def test_create_sublet(self):
"baths": 1,
"description": "This is a test sublet.",
"external_link": "https://example.com",
"min_price": 100,
"max_price": 500,
"price": 1000,
"negotiable": True,
"expires_at": "3000-02-01T10:48:02-05:00",
"start_date": "3000-04-09",
"end_date": "3000-08-07",
Expand All @@ -59,8 +59,8 @@ def test_create_sublet(self):
"baths",
"description",
"external_link",
"min_price",
"max_price",
"price",
"negotiable",
"expires_at",
"start_date",
"end_date",
Expand All @@ -80,8 +80,8 @@ def test_update_sublet(self):
"baths": 1,
"description": "This is an old sublet.",
"external_link": "https://example.com",
"min_price": 100,
"max_price": 500,
"price": 1000,
"negotiable": True,
"expires_at": "3000-02-01T10:48:02-05:00",
"start_date": "3000-04-09",
"end_date": "3000-08-07",
Expand Down Expand Up @@ -110,8 +110,8 @@ def test_browse_sublets(self):
"baths": 1,
"description": "This is a test sublet.",
"external_link": "https://example.com",
"min_price": 100,
"max_price": 500,
"price": 1000,
"negotiable": True,
"expires_at": "3000-02-01T10:48:02-05:00",
"start_date": "3000-04-09",
"end_date": "3000-08-07",
Expand All @@ -136,8 +136,8 @@ def test_browse_filtered(self):
"baths": 1,
"description": "This is a test sublet.",
"external_link": "https://example.com",
"min_price": 100,
"max_price": 400,
"price": 500,
"negotiable": True,
"expires_at": "3000-02-01T10:48:02-05:00",
"start_date": "3000-04-09",
"end_date": "3000-08-07",
Expand All @@ -147,7 +147,8 @@ def test_browse_filtered(self):
old_id = json.loads(response.content)["id"]
payload = {
"title": "Sublet2",
"max_price": 450,
"max_price": 999,
"min_price": 499,
}
response = self.client.get("/sublet/properties/", payload)
res_json = json.loads(response.content)
Expand All @@ -165,8 +166,8 @@ def test_browse_filtered(self):
"baths": 1,
"description": "This is a test sublet.",
"external_link": "https://example.com",
"min_price": 100,
"max_price": 500,
"price": 1000,
"negotiable": True,
"expires_at": "3000-02-01T10:48:02-05:00",
"start_date": "3000-04-09",
"end_date": "5000-08-07",
Expand All @@ -186,8 +187,8 @@ def test_browse_sublet(self):
"baths": 1,
"description": "This is a test sublet.",
"external_link": "https://example.com",
"min_price": 100,
"max_price": 500,
"price": 1000,
"negotiable": True,
"expires_at": "3000-02-01T10:48:02-05:00",
"start_date": "3000-04-09",
"end_date": "3000-08-07",
Expand Down

0 comments on commit f4efde6

Please sign in to comment.