Skip to content
Draft
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
225 changes: 225 additions & 0 deletions app/helpers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@
date: booking.booking_date
} AS booking
"""
GET_OWNED_HOTELS_QUERY = """
MATCH (hotelowner:HotelOwner {uid:$hotelierId})-[:OWNS_HOTEL]-(hotel:Hotel),
(hotel)-[:LOCATED_IN]-(city:City)
OPTIONAL MATCH
(hotel)-[review:REVIEWED_HOTEL]-()
RETURN
hotel.uid AS id,
hotel.photos[0] AS coverUri,
hotel.name AS name,
city.name AS city,
AVG(review.rating) as rating,
hotel.locality AS locality,
hotel.price AS price
ORDER BY rating DESC
"""

GET_PACKAGE_DETAILS_QUERY = """
MATCH
Expand Down Expand Up @@ -392,3 +407,213 @@
} AS booking,
agency
"""


GET_OFFERED_PACKAGES_QUERY = """
MATCH
(agency:Agency {uid:$agencyId})-[:OFFERS_PACKAGE]-(package)
OPTIONAL MATCH
(package)-[review:REVIEWED_PACKAGE]-()
CALL {
WITH package
MATCH
(package)-[dayRel:HAS_DAY]-(packageDay:PackageDay)
WITH dayRel.day AS day, packageDay
ORDER BY day
RETURN
COUNT(day) AS days
}
RETURN
package.uid as id,
package.name as name,
package.price as price,
package.photos[0] as coverUri,
AVG(review.rating) as rating,
days
"""

GET_OWNED_SHOPS_QUERY = """
MATCH (shopier:ShopOwner {uid:$shopierId})-[:OWNS_SHOP]-(shop:Shop)
OPTIONAL MATCH (shop)-[review:REVIEWED_SHOP]-()
RETURN
shop.uid as id,
shop.name as name,
avg(review.rating) as rating,
shop.locality as locality,
shop.latitude as latitude,
shop.longitude as longitude,
shop.phone as phone,
shop.photos[0] as coverUri
ORDER BY rating DESC
"""

GET_ALL_FAV_QUERY = """
MATCH (t:Traveller {uid:$userId})
CALL {
WITH t
match (t)-[lc:LIKES_CITY]-(c:City)
with c,lc order by lc.datetime desc limit 3
return
collect ({
id:c.uid,
name:c.name,
coverUri:c.photos[0]})
as favcities
}
CALL{
with t
match (t)-[la:LIKES_ATTRACTION]-(a:Attraction)
with a,la order by la.datetime desc limit 3
return
collect ({
id:a.uid,
name:a.name,
coverUri:a.photos[0]
})
as favattractions
}
CALL {
WITH t
OPTIONAL MATCH (t)-[lb:LIKES_BLOG]-(b:Blog)
optional match (b)-[like:LIKES_BLOG]-()
WITH b,count(like) as likes,lb ORDER BY lb.datetime DESC LIMIT 3
RETURN
COLLECT({
id:b.uid,
title:b.title,
content:left(b.content,100),
likes:likes
})
AS favblogs
}
CALL {
WITH t
OPTIONAL MATCH (t)-[lh:LIKES_HOTEL]-(h:Hotel),(h)-[:LOCATED_IN]-(c:City)
WITH h,c ORDER BY lh.datetime DESC LIMIT 3
RETURN
COLLECT({
id:h.uid,
name:h.name,
coverUri:h.photos[0],
city:c.name,
locality:h.locality,
price:h.price
})
AS favhotels
}
CALL {
WITH t
OPTIONAL MATCH (t)-[ls:LIKES_SHOP]-(s:Shop)
WITH s ORDER BY ls.datetime DESC LIMIT 3
RETURN
COLLECT({
id:s.uid,
name:s.name,
description:s.description,
photos:s.photos,
address:s.address,
phone:s.phone,
locality:s.locality,
postal_code:s.postal_code,
latitude:s.latitude,
longitude:s.longitude
})
AS favshops
}
RETURN
favblogs,
favhotels,
favshops,
favcities,
favattractions
"""
GET_FAV_HOTELS_QUERY = """
match (t:Traveller {uid:$userId})-[lh:LIKES_HOTEL]-(h:Hotel)
return
h.uid as id,
h.name as name,
h.description as description,
h.phone as phone,
h.address as address,
h.locality as locality,
h.postal_code as postal_code,
h.latitude as latitude,
h.longitude as longitude,
h.photos as photos,
h.price as price
order by lh.datetime desc
"""

GET_FAV_BLOG_QUERY = """
match (t:Traveller {uid:$userId})-[lb:LIKES_BLOG]-(b:Blog)
return
b.uid as id,
b.title as title,
b.content as content,
b.photos as photos,
b.published_on as published_on
order by lb.datetime desc
"""
GET_FAV_PACKAGE_QUERY = """
match (t:Traveller {uid:$userId})-[lp:LIKES_PACKAGE]-(p:Package)
optional match (p)-[review:REVIEWED_PACKAGE]-()
with avg(review.rating) as rating,p,lp.datetime as datetime
call {
with p
match (p)-[dayrel:HAS_DAY]-(pday:PackageDay)
with dayrel.day AS day, pday
order by day
return
count(day) AS days
}
return
p.uid as id,
p.name as name,
p.price as price,
p.photos as photos,
rating,
days,
p.description as description
order by datetime desc
"""

GET_FAV_SHOPS_QUERY = """
match (t:Traveller {uid:$userId})-[ls:LIKES_SHOP]-(s:Shop)
optional match (s)-[review:REVIEWED_SHOP]-()
with avg(review.rating) as rating,s,ls.datetime as datetime
return
s.uid as id,
s.name as name,
s.photos as photos,
s.description as description,
s.phone as phone,
s.address as address,
s.locality as locality,
rating,
s.postal_code as postal_code,
s.latitude as latitude,
s.longitude as longitude
order by datetime desc
"""

GET_FAV_CITIES_QUERY = """
match (t:Traveller {uid:$userId})-[lc:LIKES_CITY]-(c:City)
with c,lc order by lc.datetime desc limit 3
return
c.uid as id,
c.name as name,
c.description as description,
c.photos[0] as coverUri
"""

GET_FAV_ATT_QUERY = """
match (t:Traveller {uid:$userId})-[la:LIKES_ATTRACTION]-(a:Attraction)-[:LOCATED_IN]-(c:City)
return
a.uid as id,
a.name as name,
a.description as description,
a.photos as photos,
c.name as city,
a.latitude as latitude,
a.longitude as longitude
"""
14 changes: 13 additions & 1 deletion app/models/database/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,26 @@ class Attraction(Location):

visited_by = RelationshipFrom("Traveller", "VISITED_ATTRACTION", model=VisitedRel)

located_in = RelationshipTo(
"City", "LOCATED_IN", model=OwnsRel, cardinality=cardinality.One
)


class Shop(Location):
address = StringProperty(max_length=512, required=True)
locality = StringProperty(required=True)
postal_code = IntegerProperty(required=True)
phone = RegexProperty(expression=r"^\+(\d){12}$", required=True)

liked_by = RelationshipFrom("Traveller", "LIKES_SHOP", model=LikesRel)
reviewed_by = RelationshipFrom("Traveller", "REVIEWED_SHOP", model=ReviewedRel)
owned_by = RelationshipFrom("ShopOwner", "OWNS_SHOP", model=OwnsRel)

visited_by = RelationshipFrom("Traveller", "VISITED_SHOP", model=VisitedRel)

located_in = RelationshipTo(
"City", "LOCATED_IN", model=OwnsRel, cardinality=cardinality.One
)


class Blog(StructuredNode):
uid = UniqueIdProperty()
Expand Down
5 changes: 4 additions & 1 deletion app/routers/business/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from fastapi import APIRouter

from . import auth
from . import agency, auth, hotel, shop

router = APIRouter()

router.include_router(auth.router, prefix="/auth")
router.include_router(hotel.router, prefix="/hotel")
router.include_router(shop.router, prefix="/shop")
router.include_router(agency.router, prefix="/agency")
13 changes: 13 additions & 0 deletions app/routers/business/agency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from fastapi import APIRouter, Depends

from ...helpers.db_query import get_query_response
from ...helpers.queries import GET_OFFERED_PACKAGES_QUERY
from .auth import get_business

router = APIRouter()


# user=Depends(get_business)
@router.get("/owned")
async def get_offered_packages(agency=Depends(get_business)):
return get_query_response(GET_OFFERED_PACKAGES_QUERY, {"agencyId": agency.uid})
Loading