Skip to content

Commit

Permalink
db updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaelicke committed Jan 9, 2025
1 parent 2944e94 commit 2e938ea
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions metacatalog_api/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,18 @@ def get_author_by_name(session: Session, name: str, strict: bool = False) -> mod


def create_or_get_author(session: Session, author: models.AuthorCreate) -> models.Author:
sql = select(models.PersonTable).where(
models.PersonTable.first_name == author.first_name &
models.PersonTable.last_name == author.last_name &
models.PersonTable.organisation_name == author.organisation_name &
models.PersonTable.organisation_abbrev == author.organisation_abbrev
sql = select(models.PersonTable)
if author.is_organisation:
sql = sql.where(
(models.PersonTable.is_organisation == True) &
(models.PersonTable.organisation_name == author.organisation_name) &
(models.PersonTable.organisation_abbrev == author.organisation_abbrev)
)
else:
sql = sql.where(
(models.PersonTable.is_organisation == False) &
(models.PersonTable.first_name == author.first_name) &
(models.PersonTable.last_name == author.last_name)
)

author = session.exec(sql).first()
Expand Down

0 comments on commit 2e938ea

Please sign in to comment.