Skip to content

Commit

Permalink
Add more service functions
Browse files Browse the repository at this point in the history
facility_cycles -> list cycles for a facility
beamline_by_name -> returns beamline given the name (TLA)
  • Loading branch information
stuartcampbell committed Jul 18, 2023
1 parent dcb55f9 commit 847fc85
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nsls2api/services/beamline_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
from typing import Optional

from nsls2api.models.beamlines import Beamline


async def beamline_count() -> int:
return await Beamline.count()


async def beamline_by_name(name: str) -> Optional[Beamline]:
# TODO: check that the input name looks sensible
# TODO: make this case insensitive
beamline = await Beamline.find_one(Beamline.name == name)
return beamline

19 changes: 19 additions & 0 deletions nsls2api/services/facility_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
from nsls2api.models.facilities import Facility
from nsls2api.models.cycles import Cycle


async def facilities_count() -> int:
"""
Count the number of facilities in the database.
:return: The number of facilities.
"""
return await Facility.count()


async def facility_cycles(facility: str):
"""
Facility Cycles
This method retrieves the cycles for a given facility.
:param facility: The facility name (str).
:return: A list of cycles for the facility (list[Cycle]).
"""
cycles = await Cycle.find(Cycle.facility == facility)
return cycles

0 comments on commit 847fc85

Please sign in to comment.