diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f6ecfee
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.venv
+__pycache__
+**/databases/*
diff --git a/booking/booking.py b/booking/booking.py
index 267e439..ee96b0e 100644
--- a/booking/booking.py
+++ b/booking/booking.py
@@ -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 "
Welcome to the Booking service!
"
+ return "Welcome to the Booking service!
"
+@app.route("/bookings", methods=['GET'])
+def get_all():
+ return make_response(jsonify(bookings), 200)
+
+@app.route('/bookings/', 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/', 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)
diff --git a/booking/databases/bookings.json b/booking/databases/bookings.json
index 55e4853..1080813 100644
--- a/booking/databases/bookings.json
+++ b/booking/databases/bookings.json
@@ -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"
+ ]
+ }
+ ]
}
- ]
- }
- ]
+ ]
}
\ No newline at end of file
diff --git a/movie/UE-archi-distribuees-Movie-1.0.0-resolved.yaml b/movie/UE-archi-distribuees-Movie-1.0.0-resolved.yaml
index 73dfb68..93e4b2e 100644
--- a/movie/UE-archi-distribuees-Movie-1.0.0-resolved.yaml
+++ b/movie/UE-archi-distribuees-Movie-1.0.0-resolved.yaml
@@ -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
diff --git a/movie/movie.py b/movie/movie.py
index a0ddb16..7d019ba 100644
--- a/movie/movie.py
+++ b/movie/movie.py
@@ -14,9 +14,55 @@
# root message
@app.route("/", methods=['GET'])
def home():
- return make_response("Welcome to the Movie service!
",200)
+ return make_response("Welcome to the Movie service! :groalex:
",200)
+
+@app.route("/json", methods=['GET'])
+def get_json():
+ res = make_response(jsonify(movies), 200)
+ return res
+
+@app.route("/movies/", 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/', 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//', 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/', 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)
diff --git a/showtime/showtime.py b/showtime/showtime.py
index 6cf26fd..6e1c4f6 100644
--- a/showtime/showtime.py
+++ b/showtime/showtime.py
@@ -14,6 +14,19 @@
def home():
return "Welcome to the Showtime service!
"
+@app.route("/showtimes", methods=['GET'])
+def showtimes():
+ res = make_response(jsonify(schedule), 200)
+ return res
+
+@app.route("/showmovies/", 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)
diff --git a/user/UE-archi-distribuees-User-1.0.0-resolved.yaml b/user/UE-archi-distribuees-User-1.0.0-resolved.yaml
new file mode 100644
index 0000000..b2ffba7
--- /dev/null
+++ b/user/UE-archi-distribuees-User-1.0.0-resolved.yaml
@@ -0,0 +1,293 @@
+---
+openapi: 3.0.3
+info:
+ title: User API
+ description: This is the API of the User service
+ contact:
+ email: helene.coullon@imt-atlantique.fr
+ license:
+ name: GPL v3
+ url: https://www.gnu.org/licenses/gpl-3.0.en.html
+ version: 1.0.0
+tags:
+- name: admins
+ description: Secured Admin-only calls
+- name: developers
+ description: Operations available to regular developers
+paths:
+ /:
+ get:
+ tags:
+ - developers
+ summary: home page of the service
+ operationId: home
+ responses:
+ "200":
+ description: welcome message
+ content:
+ text/html:
+ schema:
+ type: string
+ example: Test
+ /users:
+ get:
+ tags:
+ - developers
+ summary: get the full JSON database
+ operationId: get_user
+ responses:
+ "200":
+ description: full JSON
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/AllUser'
+ /users/{userid}:
+ post:
+ tags:
+ - admins
+ summary: Adds a new user
+ operationId: create_user
+ parameters:
+ - name: userid
+ in: path
+ description: User ID.
+ required: true
+ style: simple
+ explode: false
+ schema:
+ type: string
+ requestBody:
+ description: Inventory item to add
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/User'
+ responses:
+ "200":
+ description: User created
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/User'
+ "409":
+ description: an existing item already exists
+ delete:
+ tags:
+ - admins
+ summary: delete a user item
+ operationId: del_user
+ parameters:
+ - name: userid
+ in: path
+ description: User ID.
+ required: true
+ style: simple
+ explode: false
+ schema:
+ type: string
+ responses:
+ "200":
+ description: item deleted
+ "400":
+ description: ID not found
+ get:
+ tags:
+ - developers
+ summary: get the user by its id
+ description: By passing in the appropriate options, you can get info of a User
+ operationId: get_user_byid
+ parameters:
+ - name: userid
+ in: path
+ description: User ID.
+ required: true
+ schema:
+ type: string
+ responses:
+ "200":
+ description: User description
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/User'
+ "400":
+ description: bad input parameter
+ /bookings/{userid}:
+ get:
+ tags:
+ - developer
+ summary: lists the bookings of a user
+ operationId: bookings_user
+ parameters:
+ - name: userid
+ required: true
+ in: path
+ description: User ID
+ style: simple
+ explode: false
+ schema:
+ type: string
+ responses:
+ "200":
+ description: List of bookings
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/BookingsUser'
+ "400":
+ description: user not found
+ post:
+ tags:
+ - developer
+ summary: adds a new movie to the bookings of a user
+ operationId: add_bookings_user
+ parameters:
+ - name: userid
+ required: true
+ in: path
+ description: User ID
+ style: simple
+ explode: false
+ schema:
+ type: string
+ requestBody:
+ description: Inventory item to add
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/DateItem'
+ responses:
+ "200":
+ description: new booking
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/DateItem'
+ "400":
+ description: user not found
+ /movieinfos/{userid}:
+ get:
+ tags:
+ - developer
+ summary: Lists the infos of movies seen or booked by the user
+ operationId: movieinfos_user
+ parameters:
+ - name: userid
+ required: true
+ in: path
+ description: User ID
+ style: simple
+ explode: false
+ schema:
+ type: string
+ responses:
+ "200":
+ description: List of bookings
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/AllMovies'
+ "400":
+ description: user not found
+
+components:
+ schemas:
+ AllUser:
+ required:
+ - user
+ type: object
+ properties:
+ user:
+ type: array
+ items:
+ $ref: '#/components/schemas/User'
+ User:
+ required:
+ - id
+ - name
+ - last_active
+ type: object
+ properties:
+ id:
+ type: string
+ example: "chris_rivers"
+ movies:
+ type: string
+ example: "Chris Rivers"
+ last_active:
+ type: integer
+ example: 1360031010
+ AllBookings:
+ type: array
+ items:
+ $ref: '#/components/schemas/BookingsUser'
+ BookingsUser:
+ required:
+ - dates
+ - userid
+ type: object
+ properties:
+ userid:
+ type: string
+ example: chris_rivers
+ dates:
+ type: array
+ items:
+ $ref: '#/components/schemas/DateItem'
+ DateItem:
+ required:
+ - date
+ - movies
+ type: object
+ properties:
+ date:
+ type: string
+ example: "20151201"
+ movies:
+ type: array
+ items:
+ type: string
+ example: 276c79ec-a26a-40a6-b3d3-fb242a5947b6
+ NewMovie:
+ required:
+ - date
+ - movieid
+ type: object
+ properties:
+ date:
+ type: string
+ example: "20151201"
+ movieid:
+ type: string
+ example: 276c79ec-a26a-40a6-b3d3-fb242a5947b6
+ AllMovies:
+ type: object
+ required:
+ - movies
+ properties:
+ movies:
+ type: array
+ items:
+ type: object
+ $ref: '#/components/schemas/MovieItem'
+ MovieItem:
+ type: object
+ required:
+ - title
+ - rating
+ - director
+ - id
+ properties:
+ title:
+ type: string
+ example: The Martian
+ rating:
+ type: integer
+ example: 7
+ director:
+ type: string
+ example: Paul McGuigan
+ id:
+ type: string
+ example: 39ab85e5-5e8e-4dc5-afea-65dc368bd7ab
diff --git a/user/user.py b/user/user.py
index 8a17e84..3d046ff 100644
--- a/user/user.py
+++ b/user/user.py
@@ -7,15 +7,44 @@
PORT = 3203
HOST = '0.0.0.0'
+BOOKING_HOST = 'http://localhost:3201/bookings/'
+MOVIES_HOST = 'http://localhost:3200/movies/'
with open('{}/databases/users.json'.format("."), "r") as jsf:
- users = json.load(jsf)["users"]
+ users = json.load(jsf)["users"]
@app.route("/", methods=['GET'])
def home():
- return "Welcome to the User service!
"
+ return "Welcome to the User service!
"
+@app.route("/users", methods=['GET'])
+def user():
+ return make_response(jsonify(users), 200)
+
+@app.route("/users/", methods=['POST'])
+def add_user(userid):
+ req = request.get_json()
+ for u in users:
+ if str(u['id']) == str(userid):
+ return make_response(jsonify({'error': 'User ID already exists'}), 409)
+ users.append(req)
+ write(users)
+ res = make_response(jsonify({"message":"user added"}),200)
+ return res
+
+@app.route('/users/', methods=['DELETE'])
+def delete_movie(userid):
+ for u in users:
+ if str(u['id']) == str(userid):
+ users.remove(u)
+ write(users)
+ return make_response(jsonify({'message': 'Deleted successfully'}), 200)
+ return make_response(jsonify({'error': 'User not found'}), 400)
+
+def write(users):
+ with open('{}/databases/users.json'.format("."), 'w') as f:
+ json.dump({'users':users}, 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)