From 391cd5a2826a64dfa5089715c2686c14669568ff Mon Sep 17 00:00:00 2001 From: Louis Bruneteau Date: Fri, 27 Sep 2024 11:18:38 +0200 Subject: [PATCH 1/9] kdjkmjd --- .gitignore | 3 +++ movie/movie.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 .gitignore 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/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) From a8c5475a6969349702a909e55350037c0d5f036c Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 27 Sep 2024 11:35:10 +0200 Subject: [PATCH 2/9] Showtime --- showtime/showtime.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) From ca8b6b481f625cec919aae3d27b18266c63a3fed Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 27 Sep 2024 12:02:37 +0200 Subject: [PATCH 3/9] =?UTF-8?q?Cr=C3=A9ation=20fichier=20OpenAPI=20User?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...archi-distribuees-User-1.0.0-resolved.yaml | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 user/UE-archi-distribuees-User-1.0.0-resolved.yaml 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..2f3dc20 --- /dev/null +++ b/user/UE-archi-distribuees-User-1.0.0-resolved.yaml @@ -0,0 +1,72 @@ +--- +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' + +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 \ No newline at end of file From 856e0aa3135f0e9065c365aa18553eaafdbe4939 Mon Sep 17 00:00:00 2001 From: Louis Bruneteau Date: Fri, 27 Sep 2024 12:05:43 +0200 Subject: [PATCH 4/9] =?UTF-8?q?tout=20sauf=20v=C3=A9rif=20showtime=20dans?= =?UTF-8?q?=20booking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- booking/booking.py | 46 ++++++++++++++++-- booking/databases/bookings.json | 83 +++++++++++++++++++++------------ 2 files changed, 95 insertions(+), 34 deletions(-) diff --git a/booking/booking.py b/booking/booking.py index 267e439..e58ed23 100644 --- a/booking/booking.py +++ b/booking/booking.py @@ -7,15 +7,53 @@ PORT = 3201 HOST = '0.0.0.0' +TIMES_HOST = 'http:localhost:3202/showtimes' 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): + # TODO appeler Times pour vérifier + req = request.get_json() + 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 From fbca65bf92e2d1c054ece208c0077432b519c2c7 Mon Sep 17 00:00:00 2001 From: Louis Bruneteau Date: Sun, 29 Sep 2024 12:48:44 +0200 Subject: [PATCH 5/9] booking finished --- booking/booking.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/booking/booking.py b/booking/booking.py index e58ed23..ee96b0e 100644 --- a/booking/booking.py +++ b/booking/booking.py @@ -7,7 +7,7 @@ PORT = 3201 HOST = '0.0.0.0' -TIMES_HOST = 'http:localhost:3202/showtimes' +TIMES_HOST = 'http://localhost:3202/showmovies/' with open('{}/databases/bookings.json'.format("."), "r") as jsf: bookings = json.load(jsf)["bookings"] @@ -29,8 +29,13 @@ def bookings_user(userid): @app.route('/bookings/', methods=['POST']) def add_booking(userid): - # TODO appeler Times pour vérifier 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): From 2ae7453188e4cb772c0af2c758b7fd256b0af5e6 Mon Sep 17 00:00:00 2001 From: Louis Bruneteau Date: Thu, 3 Oct 2024 18:58:17 +0200 Subject: [PATCH 6/9] user get --- user/user.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/user/user.py b/user/user.py index 8a17e84..1c2e5bc 100644 --- a/user/user.py +++ b/user/user.py @@ -9,13 +9,17 @@ HOST = '0.0.0.0' 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) 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) From 8ceb27576f66468fe1cd4fb0b1332f059922c52d Mon Sep 17 00:00:00 2001 From: Louis Bruneteau Date: Fri, 4 Oct 2024 10:30:09 +0200 Subject: [PATCH 7/9] yaml --- ...rchi-distribuees-Movie-1.0.0-resolved.yaml | 1 - ...archi-distribuees-User-1.0.0-resolved.yaml | 225 +++++++++++++++++- 2 files changed, 223 insertions(+), 3 deletions(-) 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/user/UE-archi-distribuees-User-1.0.0-resolved.yaml b/user/UE-archi-distribuees-User-1.0.0-resolved.yaml index 2f3dc20..b2ffba7 100644 --- a/user/UE-archi-distribuees-User-1.0.0-resolved.yaml +++ b/user/UE-archi-distribuees-User-1.0.0-resolved.yaml @@ -42,7 +42,155 @@ paths: 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: @@ -69,4 +217,77 @@ components: example: "Chris Rivers" last_active: type: integer - example: 1360031010 \ No newline at end of file + 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 From c1859aed27774e0107b6415ff07f8f495203a2f5 Mon Sep 17 00:00:00 2001 From: Louis Bruneteau Date: Fri, 4 Oct 2024 10:32:05 +0200 Subject: [PATCH 8/9] url --- user/user.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user/user.py b/user/user.py index 1c2e5bc..18e86dc 100644 --- a/user/user.py +++ b/user/user.py @@ -7,6 +7,8 @@ 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"] From 21070931db6d05215021dbd88e8f3b3ebf50317b Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 4 Oct 2024 10:50:27 +0200 Subject: [PATCH 9/9] Users --- user/user.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/user/user.py b/user/user.py index 18e86dc..3d046ff 100644 --- a/user/user.py +++ b/user/user.py @@ -21,6 +21,29 @@ def home(): 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))