Coverage for middle_layer/propose/application_layer/orm_repositories/field_source.py: 100.00%
29 statements
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
1# Copyright 2024 Associated Universities, Inc.
2#
3# This file is part of Telescope Time Allocation Tools (TTAT).
4#
5# TTAT is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# any later version.
9#
10# TTAT is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with TTAT. If not, see <https://www.gnu.org/licenses/>.
17#
18from datetime import datetime, timezone
20from sqlalchemy import update
21from sqlalchemy.orm import Session
23from allocate.domain_layer.entities.tac_member import TACMember
24from common.application_layer.orm_repositories import add_entity, get_object_by_id, list_entities
25from propose.domain_layer.entities.field_source import FieldSource
26from propose.domain_layer.entities.proposal import AllocationRequest, Author, Proposal, ProposalCopy
27from propose.domain_layer.repositories.proposal import FieldSourceRepository
28from review.domain_layer.entities.conflict_declaration import ConflictDeclaration
29from review.domain_layer.entities.individual_science_review import IndividualScienceReview
30from review.domain_layer.entities.science_reviewer import ScienceReviewer
33class FieldSourceORMRepository(FieldSourceRepository):
34 def __init__(self, session: Session):
35 self.session = session
37 def by_id(self, ar_id: int) -> FieldSource:
38 return get_object_by_id(self.session, ar_id, FieldSource, FieldSource.field_source_id)
40 def list_all(self) -> list[FieldSource]:
41 return list_entities(self.session, FieldSource, FieldSource.field_source_id)
43 def add(self, field_source: FieldSource) -> int:
44 add_entity(self.session, field_source)
45 self.session.flush()
46 return field_source.field_source_id
48 def update(self, field_source: FieldSource) -> None:
49 if field_source is not None:
50 self.session.add(field_source)
51 self.session.flush()
53 def delete(self, field_source: FieldSource) -> None:
54 self.session.delete(field_source)
55 self.session.flush()