Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
__pycache__
**/databases/*
51 changes: 47 additions & 4 deletions booking/booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,58 @@

PORT = 3201
HOST = '0.0.0.0'
TIMES_HOST = 'http://localhost:3202/showmovies/'

with open('{}/databases/bookings.json'.format("."), "r") as jsf:
bookings = json.load(jsf)["bookings"]
bookings = json.load(jsf)["bookings"]

@app.route("/", methods=['GET'])
def home():
return "<h1 style='color:blue'>Welcome to the Booking service!</h1>"
return "<h1 style='color:blue'>Welcome to the Booking service!</h1>"

@app.route("/bookings", methods=['GET'])
def get_all():
return make_response(jsonify(bookings), 200)

@app.route('/bookings/<userid>', methods=['GET'])
def bookings_user(userid):
for b in bookings:
if str(b['userid']) == str(userid):
return make_response(jsonify(b), 200)
return make_response(jsonify({'error': 'bad input parameter'}), 400)

@app.route('/bookings/<userid>', methods=['POST'])
def add_booking(userid):
req = request.get_json()
g = requests.get(TIMES_HOST + str(req['date']))
if g.status_code != 200:
return make_response({'error': 'date indisponible'}, 409)
get = json.loads(g.content)
if req['movieid'] not in get['movies']:
return make_response(jsonify({'error': 'This movie isn\'t planned for this date'}), 409)
booking = None
for b in bookings:
if str(b['userid']) == str(userid):
booking = b
if booking == None:
booking = {"userid": str(userid), "dates": []}
bookings.append(booking)
need_new = True
for d in booking["dates"]:
if d["date"] == req["date"]:
if any([m == req["movieid"] for m in d["movies"]]):
return make_response(jsonify({'error': 'booking already exists'}), 409)
d["movies"].append(req["movieid"])
need_new = False
if need_new:
booking["dates"].append({"date": req["date"], "movies": [req["movieid"]]})
write(bookings)
return make_response(jsonify(booking), 200)

def write(bookings):
with open('{}/databases/bookings.json'.format("."), 'w') as f:
json.dump({'bookings':bookings}, f, indent=4)

if __name__ == "__main__":
print("Server running in port %s"%(PORT))
app.run(host=HOST, port=PORT)
print("Server running in port %s"%(PORT))
app.run(host=HOST, port=PORT)
83 changes: 53 additions & 30 deletions booking/databases/bookings.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,62 @@
{
"bookings": [
{
"userid": "chris_rivers",
"dates": [
"bookings": [
{
"date": "20151201",
"movies": ["267eedb8-0f5d-42d5-8f43-72426b9fb3e6"]
}
]
},
{
"userid": "garret_heaton",
"dates": [
{
"date": "20151201",
"movies": ["267eedb8-0f5d-42d5-8f43-72426b9fb3e6"]
"userid": "chris_rivers",
"dates": [
{
"date": "20151201",
"movies": [
"267eedb8-0f5d-42d5-8f43-72426b9fb3e6"
]
}
]
},
{
"date": "20151202",
"movies": ["276c79ec-a26a-40a6-b3d3-fb242a5947b6"]
}
]
},
{
"userid": "dwight_schrute",
"dates": [
"userid": "garret_heaton",
"dates": [
{
"date": "20151201",
"movies": [
"267eedb8-0f5d-42d5-8f43-72426b9fb3e6"
]
},
{
"date": "20151202",
"movies": [
"276c79ec-a26a-40a6-b3d3-fb242a5947b6"
]
}
]
},
{
"date": "20151201",
"movies": ["7daf7208-be4d-4944-a3ae-c1c2f516f3e6","267eedb8-0f5d-42d5-8f43-72426b9fb3e6"]
"userid": "dwight_schrute",
"dates": [
{
"date": "20151201",
"movies": [
"7daf7208-be4d-4944-a3ae-c1c2f516f3e6",
"267eedb8-0f5d-42d5-8f43-72426b9fb3e6"
]
},
{
"date": "20151205",
"movies": [
"a8034f44-aee4-44cf-b32c-74cf452aaaae",
"276c79ec-a26a-40a6-b3d3-fb242a5947b6"
]
}
]
},
{
"date": "20151205",
"movies": ["a8034f44-aee4-44cf-b32c-74cf452aaaae","276c79ec-a26a-40a6-b3d3-fb242a5947b6"]
"userid": "chris_pratt",
"dates": [
{
"date": "20151208",
"movies": [
"276c79ec-a26a-40a6-b3d3-fb242a5947b6"
]
}
]
}
]
}
]
]
}
1 change: 0 additions & 1 deletion movie/UE-archi-distribuees-Movie-1.0.0-resolved.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
openapi: 3.0.3
info:
title: Movie API
summary: This is the API of the Movie service
description: This is the API of the Movie service, it should be much much much much much much much much much much much much much much much much much much much much much longer
contact:
name: Helene Coullon
Expand Down
50 changes: 48 additions & 2 deletions movie/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,55 @@
# root message
@app.route("/", methods=['GET'])
def home():
return make_response("<h1 style='color:blue'>Welcome to the Movie service!</h1>",200)
return make_response("<h1 style='color:blue'>Welcome to the Movie service! :groalex:</h1>",200)

@app.route("/json", methods=['GET'])
def get_json():
res = make_response(jsonify(movies), 200)
return res

@app.route("/movies/<movieid>", methods=['GET'])
def get_movie_by_id(movieid):
for m in movies:
if str(m['id']) == str(movieid):
res = make_response(jsonify(m), 200)
return res
return make_response(jsonify({'error': 'Movie ID not found'}), 400)


@app.route('/addmovie/<movieid>', methods=['POST'])
def add_movie(movieid):
req = request.get_json()
for m in movies:
if str(m['id']) == str(movieid):
return make_response(jsonify({'error': 'Movie ID already exists'}), 409)
movies.append(req)
write(movies)
res = make_response(jsonify({"message":"movie added"}),200)
return res

@app.route('/movies/<movieid>/<rating>', methods=['PUT'])
def update_rating(movieid, rating):
for m in movies:
if str(m['id']) == str(movieid):
m['rating'] = rating
write(movies)
return make_response(jsonify({'message': 'Success'}), 200)
return make_response(jsonify({'error': 'Movie ID not found'}), 400)

@app.route('/movies/<movieid>', methods=['DELETE'])
def delete_movie(movieid):
for m in movies:
if str(m['id']) == str(movieid):
movies.remove(m)
write(movies)
return make_response(jsonify({'message': 'Deleted successfully'}), 200)
return make_response(jsonify({'error': 'Movie not found'}), 400)

def write(movies):
with open('{}/databases/movies.json'.format("."), 'w') as f:
json.dump({'movies':movies}, f, indent=4)

if __name__ == "__main__":
#p = sys.argv[1]
print("Server running in port %s"%(PORT))
app.run(host=HOST, port=PORT)
13 changes: 13 additions & 0 deletions showtime/showtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
def home():
return "<h1 style='color:blue'>Welcome to the Showtime service!</h1>"

@app.route("/showtimes", methods=['GET'])
def showtimes():
res = make_response(jsonify(schedule), 200)
return res

@app.route("/showmovies/<date>", methods=['GET'])
def showmovies(date):
for s in schedule:
if str(s['date']) == str(date):
res = make_response(jsonify(s), 200)
return res
return make_response(jsonify({'error': 'showtime date not found'}), 400)

if __name__ == "__main__":
print("Server running in port %s"%(PORT))
app.run(host=HOST, port=PORT)
Loading