Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type RoomsResult {
}

type Query {
getReservation(roomId: String!): ReservationResult!
getReservation(id: ID!): ReservationResult!
getAllReservations: ReservationsResult!
getAllRooms: RoomsResult!
getAvailableRooms(input: AvailableRoomInput!): RoomsResult!
Expand Down
9 changes: 1 addition & 8 deletions backend/specs/resolvers/when_cancelling_reservations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@


class DescribeDeleteReservationResolver:
def find_by_id(self, reservation_id):
return [
reservation
for reservation in self.reservations
if reservation.id != reservation_id
]

@pytest.mark.asyncio
async def should_delete_existing_reservation(self, mocker):
original_reservations = [
Expand Down Expand Up @@ -60,7 +53,7 @@ async def should_delete_existing_reservation(self, mocker):
assert result["reservations"] == expected_reservations

@pytest.mark.asyncio
async def test_should_give_reservation_not_found(self, mocker):
async def should_give_reservation_not_found(self, mocker):
result = await delete_reservation_resolver(
None, MOCK_EXECUTION_CONTEXT, reservationId=999
)
Expand Down
13 changes: 2 additions & 11 deletions backend/specs/when_authorizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest
from jose import jwt

from auth import create_access_token, create_refresh_token
from settings import ALGORITHM, REFRESH_SECRET_KEY, SECRET_KEY
from auth import create_access_token
from settings import ALGORITHM, SECRET_KEY


class DescribeAuthorization:
Expand All @@ -22,12 +22,3 @@ def should_create_access_token(self, subject, expires_delta):

decoded_token = jwt.decode(generated_token, SECRET_KEY, algorithms=[ALGORITHM])
assert decoded_token["sub"] == subject

def should_create_refresh_token(self, subject, expires_delta):
generated_token = create_refresh_token(subject, expires_delta)
assert generated_token is not None

decoded_token = jwt.decode(
generated_token, REFRESH_SECRET_KEY, algorithms=[ALGORITHM]
)
assert decoded_token["sub"] == subject
12 changes: 4 additions & 8 deletions backend/src/api/resolvers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@ async def create_reservation(


async def delete_reservation(db, reservation_id: int) -> Dict[str, Any]:
reservation = await fetch_reservation(db, reservation_id)
if reservation:
await db.execute("DELETE FROM reservations WHERE id = $1", reservation_id)
return await fetch_all_rows(db, Reservation)
else:
errors = ["Reservation not found"]
return {"success": False, "errors": errors, "reservations": None}
await fetch_reservation(db, reservation_id)
await db.execute("DELETE FROM reservations WHERE id = $1", reservation_id)
return await fetch_all_rows(db, Reservation)


async def is_room_available(
Expand Down Expand Up @@ -116,7 +112,7 @@ async def fetch_room(db, room_id: str) -> Room:
raise ValueError(f"Room with id {room_id} not found")


async def fetch_reservation(db, reservation_id: id):
async def fetch_reservation(db, reservation_id: int):
result = await fetch_by_id(db, Reservation, id=reservation_id)
if result["success"]:
return result
Expand Down
3 changes: 1 addition & 2 deletions backend/src/api/resolvers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@


async def get_reservation_resolver(obj, info, id) -> Dict[str, Any]:
db = await DbSession()
try:
db = await DbSession()

result = await fetch_reservation(db, id)
return result
except ValueError as error:
Expand Down
3 changes: 1 addition & 2 deletions backend/src/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def convert_to_local_date(dt_utc: datetime) -> datetime:


def convert_to_local_date_from_str(date_str: str) -> datetime:
dt_utc = datetime.strptime(date_str, "%Y-%m-%d")
return dt_utc.astimezone(timezone.utc).replace(tzinfo=None)
return datetime.strptime(date_str, "%Y-%m-%d")


def get_calling_function_name() -> str:
Expand Down
11 changes: 1 addition & 10 deletions backend/src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

from jose import jwt

from settings import (
ACCESS_TOKEN_EXPIRE_MINUTES,
ALGORITHM,
REFRESH_SECRET_KEY,
SECRET_KEY,
)
from settings import ACCESS_TOKEN_EXPIRE_MINUTES, ALGORITHM, SECRET_KEY


def create_token(subject: str, secret_key: str, expires_delta: timedelta) -> str:
Expand All @@ -27,10 +22,6 @@ def create_access_token(subject: str, expires_delta: timedelta) -> str:
return create_token(subject, str(SECRET_KEY), expires_delta)


def create_refresh_token(subject: str, expires_delta: timedelta) -> str:
return create_token(subject, str(REFRESH_SECRET_KEY), expires_delta)


def verify_user(username: str, password: str):
# for this example application, we are just going to hard-code this
return username == "example-user" and password == "example-user"
13 changes: 12 additions & 1 deletion backend/src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

API_NAME = "Acme Hotel Reservation - Graphql API"
API_PORT = getenv("RESERVATION_PORT") or 80
ENV = getenv("ENV")
ENV = getenv("ENV", "development")
DB_URL = getenv("PG_URL")
ALLOWED_ORIGINS = getenv("ALLOWED_ORIGINS", "http://localhost:3000").split(",")

Expand All @@ -14,3 +14,14 @@

SECRET_KEY = getenv("SECRET_KEY")
REFRESH_SECRET_KEY = getenv("REFRESH_SECRET_KEY")

_missing = [
name
for name, val in [
("SECRET_KEY", SECRET_KEY),
("REFRESH_SECRET_KEY", REFRESH_SECRET_KEY),
]
if not val
]
if _missing and ENV != "test":
raise RuntimeError(f"Missing required environment variables: {', '.join(_missing)}")
Loading