forked from Alexey/DAS_2024_1
немного изменений
This commit is contained in:
parent
a0ef65e0f9
commit
c3537b5abe
@ -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('/<uuid:uuid>', methods=['GET'])
|
||||
@app.route('/<uuid:uuid_>', 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('/<uuid:uuid>', methods=['PUT'])
|
||||
@app.route('/<uuid:uuid_>', 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('/<uuid:uuid>', methods=['DELETE'])
|
||||
@app.route('/<uuid:uuid_>', methods=['DELETE'])
|
||||
def delete(uuid_):
|
||||
for author in authors:
|
||||
if author.uuid_ == uuid_:
|
||||
authors.remove(author)
|
||||
return 200
|
||||
return '', 200
|
||||
|
||||
return 'Автор с таким uuid не был найден', 404
|
||||
|
||||
|
@ -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),
|
||||
]
|
Loading…
Reference in New Issue
Block a user