Moving things around, combining and splitting ...
This commit is contained in:
0
ares/server/__init__.py
Normal file
0
ares/server/__init__.py
Normal file
41
ares/server/person.py
Normal file
41
ares/server/person.py
Normal file
@@ -0,0 +1,41 @@
|
||||
class Person(object):
|
||||
_people = [
|
||||
{
|
||||
'name': {
|
||||
'first': 'Hammy',
|
||||
'last': 'Spammy',
|
||||
},
|
||||
'age': 42,
|
||||
'id': 1,
|
||||
},
|
||||
{
|
||||
'name': {
|
||||
'first': 'Sampers',
|
||||
'last': 'Dancer',
|
||||
},
|
||||
'age': 38,
|
||||
'id': 2
|
||||
},
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
self._index()
|
||||
|
||||
def _index(self):
|
||||
self._people_by_id = dict(((p['id'], p) for p in self._people))
|
||||
|
||||
def getall(self):
|
||||
return self._people
|
||||
|
||||
def get(self, person_id):
|
||||
return self._people_by_id[person_id]
|
||||
|
||||
def add(self, person):
|
||||
if None in (person.get('name'), person.get('age')):
|
||||
raise ValueError('Missing required fields!: {}'.format(person))
|
||||
|
||||
person['id'] = len(self._people) + 1
|
||||
self._people.append(person)
|
||||
self._index()
|
||||
return person['id']
|
||||
|
Reference in New Issue
Block a user