- Pull the repo and cd to the directory.
- Run
sudo docker build -t tajawal .
- Run
sudo docker run --name tajawal -p 8080:8080 tajawal
HotelAPIController
is responsible for fetch all hotels.Parsing
is responsible for parsing price and date range to valid data.PriceRangeParse
andDateRangeParse
extendParsing
and implementparse
method to parse the price range and date range.Validation
is responsible for validating all the url parameters.PriceRangeValidation
,DateRangeValidation
andSortValidation
extendValidation
and implement thevalidate
method which validate the price and date ranges and the sort parameters.Filter
is responsible for filtering the hotels list according to the passed parameters in the query url. It is an implementation of theChain of Responsiblity
design pattern.Sort
is responsible for sorting the hotels list according to the the sort parameters in the query url. It is an implementation ofstrategy design pattern
whererHotelNameSort
andHotelPriceSort
are the two strategies.HotelProbertySortFactory
is responsible for creating one of the two sort strategies depending on the sort parameters.
- http://localhost:8080/hotels will return all the available hotels.
{"status_code":200, "data":{"hotels":[]}}
{ "err_msg": "", "err_name": "", "status_code": 400 }
- Only
name
,city
,min_price
,max_price
,start_date
,end_date
,sort_by
andsort_type
options are valid to be provided in the URL query if anything else is provided the API will ignore it. - Filter by
name
http://localhost:8080/hotels?name=Golden%20Tulip will returnGolden Tulip
and if you search withTulip Golden
,Gold
,Tulip
orGolden
will also return the same result ofGolden Tulip
.Can search by reversed or partial hotel name. - Filter by
city
http://localhost:8080/hotels?city=london will returnLe Meridien
and you can search with partial or reversed city if contains two words. - Filter by price range using
min_price
andmax_price
http://localhost:8080/hotels?min_price=100&max_price=200 will return hotels in this range. Note that Ifmin_price
ormax_price
is not numeric or negative values ormin_price
value is larger than themax_price
this will return error. - Filter by price range using only
min_price
http://localhost:8080/hotels?min_price=100 will return hotels with price above that value. - Filter by price range using only
max_price
http://localhost:8080/hotels?max_price=200 will return hotels with price below that value. - Filter by date range using
start_date
andend_date
http://localhost:8080/hotels?start_date=10-10-2020&end_date=20-10-2020 will return hotels in this range. Note that If one these two values is provided and the other is missing or theend_date
is later theend_date
this will return error. - Sorting by
name
orprice
by providingsort_by=name
orsort_by=price
and you can provide the type of sort which can be ascending(sort_type=asc
) or descending sort(sort_type=desc
) http://localhost:8080/hotels?sort_by=name&sort_type='asc' and http://localhost:8080/hotels?sort_by=price&sort_type='desc' Only available options tosort_by
areprice
andname
and forsort_type
areasc
anddesc
if anything else is provided it will return this error JSON. Ifsort_by
is provided andsort_type
is not the default value isdesc
.
- Run
sudo docker exec tajawal jest
to run all the unittests. - Run
sudo docker exec tajawal jest --coverage
to get the unittest coverage.