Skip to content

Commit

Permalink
Links were not saved when creating new person.
Browse files Browse the repository at this point in the history
  • Loading branch information
Makistos committed Jun 12, 2024
1 parent 784eb5e commit af80b1d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
18 changes: 17 additions & 1 deletion app/impl_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ def person_add(params: Any) -> ResponseType:
person.image_src = data['image_src'] if 'image_src' in data else None
person.dob = data['dob'] if 'dob' in data else None
person.dod = data['dod'] if 'dod' in data else None
if 'nationality' in data and 'id' in data['nationality']:
if ('nationality' in data and data['nationality'] is not None
and 'id' in data['nationality']):
person.nationality_id = data['nationality']['id']
else:
person.nationality_id = data['nationality_id'] \
Expand All @@ -477,6 +478,21 @@ def person_add(params: Any) -> ResponseType:
return ResponseType('Tietokantavirhe.',
HttpResponseCode.INTERNAL_SERVER_ERROR.value)

if 'links' in data:
for link in data['links']:
pl = PersonLink(
person_id=person.id, link=link['link'],
description=link['description']
)
session.add(pl)
try:
session.add(person)
session.commit()
except SQLAlchemyError as exp:
app.logger.error('Exception in person_add: ' + str(exp))
return ResponseType('Tietokantavirhe.',
HttpResponseCode.INTERNAL_SERVER_ERROR.value)

return ResponseType(str(person.id), HttpResponseCode.CREATED.value)


Expand Down
12 changes: 6 additions & 6 deletions app/impl_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from app.impl import (ResponseType, SearchResult,
SearchResultFields, searchscore, set_language, check_int,
get_join_changes)
from app.orm_decl import (Edition, Genre, Part, Tag, Work, WorkType, WorkTag,
WorkGenre, WorkLink, Bookseries, ShortStory,
from app.orm_decl import (Edition, Genre, Part, Tag, Work, WorkType,
WorkTag, WorkGenre, WorkLink, Bookseries, ShortStory,
Contributor)
from app.model import (WorkBriefSchema, WorkTypeBriefSchema,
ShortBriefSchema)
Expand Down Expand Up @@ -524,17 +524,17 @@ def search_works_by_author(params: Dict[str, str]) -> ResponseType:
.filter(Work.author_str.ilike(params['letter'] + '%'))\
.order_by(Work.author_str).all()
except SQLAlchemyError as exp:
app.logger.error('Exception in SearchWorksByAuthor: ' + str(exp))
return ResponseType(f'SearchWorksByAuthor: Tietokantavirhe. id={id}',
app.logger.error(exp)
return ResponseType('Tietokantavirhe',
HttpResponseCode.INTERNAL_SERVER_ERROR.value)

try:
# schema = WorkBriefSchema(many=True)
schema = BookIndexSchema(many=True)
retval = schema.dump(works)
except exceptions.MarshmallowError as exp:
app.logger.error('SearchWorksByAuthor schema error: ' + str(exp))
return ResponseType('SearchWorksByAuthor: Skeemavirhe.',
app.logger.error(exp)
return ResponseType('Skeemavirhe.',
HttpResponseCode.INTERNAL_SERVER_ERROR.value)

return ResponseType(retval, HttpResponseCode.OK.value)
Expand Down

0 comments on commit af80b1d

Please sign in to comment.