diff --git a/tsukanova_irina_lab_3/author_service/author_service.py b/tsukanova_irina_lab_3/author_service/author_service.py index 7240f45..367cf3a 100644 --- a/tsukanova_irina_lab_3/author_service/author_service.py +++ b/tsukanova_irina_lab_3/author_service/author_service.py @@ -1,11 +1,11 @@ from flask import Flask, jsonify, request -from uuid import uuid1 +from uuid import uuid4 import uuid class Author: def __init__(self, name, surname): - self.uuid_: uuid = uuid1() + self.uuid_: uuid = uuid4() self.name: str = name self.surname: str = surname @@ -35,7 +35,7 @@ def get_all(): return list_jsonify(), 200 -@app.route('/', methods=['GET']) +@app.route('/', methods=['GET']) def get_one(uuid_): for author in authors: if author.uuid_ == uuid_: @@ -57,7 +57,7 @@ def create(): return get_one(new_author.uuid_) -@app.route('/', methods=['PUT']) +@app.route('/', methods=['PUT']) def update_by_id(uuid_): data = request.json new_name = data.get('name', None) @@ -74,12 +74,12 @@ def update_by_id(uuid_): return 'Автор с таким uuid не был найден', 404 -@app.route('/', methods=['DELETE']) +@app.route('/', methods=['DELETE']) def delete(uuid_): for author in authors: if author.uuid_ == uuid_: authors.remove(author) - return 200 + return '', 200 return 'Автор с таким uuid не был найден', 404 diff --git a/tsukanova_irina_lab_3/book_service/book_service.py b/tsukanova_irina_lab_3/book_service/book_service.py index e69de29..bbd9c7e 100644 --- a/tsukanova_irina_lab_3/book_service/book_service.py +++ b/tsukanova_irina_lab_3/book_service/book_service.py @@ -0,0 +1,32 @@ +from flask import Flask, jsonify, request +from uuid import uuid4 +import uuid +from author_service.author_service import Author + + +class Book: + def __init__(self, title, year, author_id): + self.uuid_: uuid = uuid4() + self.title: str = title + self.year: int = year + self.author_id: uuid = author_id + + def to_dict(self, author: Author): + return { + 'title': self.title, + 'year': self.year, + 'author_id': self.author_id, + 'author_info': author.to_dict(), + } + + +app = Flask(__name__) + +books: list[Book] = [ + Book(title='Garden', year=1977, author_id=1), + Book(title='New York', year=1977, author_id=1), + Book(title='The story of flowers', year=1977, author_id=1), + Book(title='Little Rock', year=1977, author_id=1), + Book(title='One Piece', year=1977, author_id=1), + Book(title='Clack clover', year=1977, author_id=1), +]