hero put
This commit is contained in:
@ -12,7 +12,6 @@ HEROES = [
|
||||
|
||||
|
||||
def get_hero(id=None):
|
||||
if id:
|
||||
try:
|
||||
hero = next(x for x in HEROES if x["id"] == id)
|
||||
return { "id": hero["id"], "name": hero["name"] }
|
||||
@ -26,4 +25,18 @@ def get_heroes():
|
||||
else:
|
||||
return 'No heroes available', 404
|
||||
|
||||
|
||||
def put_hero(id=None, hero=None):
|
||||
if id:
|
||||
# update
|
||||
try:
|
||||
heroToUpdate = next(x for x in HEROES if x["id"] == id)
|
||||
heroToUpdate["name"] = hero["name"]
|
||||
return 'Hero updated', 200
|
||||
except StopIteration:
|
||||
return 'Hero not found', 404
|
||||
else:
|
||||
# insert
|
||||
newHeroId = len(HEROES)
|
||||
hero["id"] = newHeroId
|
||||
HEROES.append(hero)
|
||||
return 'Hero inserted', 201
|
||||
|
@ -37,6 +37,28 @@ paths:
|
||||
$ref: '#/definitions/Hero'
|
||||
404:
|
||||
description: Hero not found
|
||||
put:
|
||||
operationId: heroes.put_hero
|
||||
summary: Insert or update a hero
|
||||
parameters:
|
||||
- name: id
|
||||
in: query
|
||||
type: integer
|
||||
required: false
|
||||
- name: hero
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/Hero'
|
||||
responses:
|
||||
200:
|
||||
description: Hero updated
|
||||
201:
|
||||
description: New hero created
|
||||
403:
|
||||
description: Some error
|
||||
404:
|
||||
description: Hero not found
|
||||
/heroes:
|
||||
get:
|
||||
operationId: heroes.get_heroes
|
||||
|
Reference in New Issue
Block a user