From d0894a9610a600fbfcddc290630a16cc84076a26 Mon Sep 17 00:00:00 2001 From: Dennis Chen Date: Tue, 6 Aug 2024 10:11:59 -0700 Subject: [PATCH] Add backend checks to length of name and description --- store/app/routers/listings.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/store/app/routers/listings.py b/store/app/routers/listings.py index 37b009b8..956075dd 100644 --- a/store/app/routers/listings.py +++ b/store/app/routers/listings.py @@ -202,9 +202,19 @@ async def edit_listing( ) -> bool: listing_info = await crud.get_listing(id) if listing_info is None: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Listing not found") + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Listing not found.") if listing_info.user_id != user.id: - raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not own this listing") + raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not own this listing.") + if listing.name is not None and len(listing.name) < 4: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="Listing name must be at least 4 characters long.", + ) + if listing.description is not None and len(listing.description) < 6: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="Listing description must be at least 6 characters long.", + ) await crud.edit_listing( listing_id=id, name=listing.name,