Skip to content

Commit c361afd

Browse files
committed
feat: centralize duplicated OfficialCollection and ExternalLink components
Adds a new `components/` directory to the view models directory which is intended to house shared components. Refactors the official collection component into the `collections` view model folder, which is more appropriate given the content.
1 parent 8de4333 commit c361afd

File tree

5 files changed

+32
-29
lines changed

5 files changed

+32
-29
lines changed

src/mavedb/view_models/collection.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import date
2-
from typing import Any, Sequence, Optional
2+
from typing import Any, Optional, Sequence
33

44
from pydantic import Field, model_validator
55

@@ -132,3 +132,14 @@ class Collection(SavedCollection):
132132
# NOTE: Coupled to ContributionRole enum
133133
class AdminCollection(Collection):
134134
pass
135+
136+
137+
# Properties to return for official collections
138+
class OfficialCollection(BaseModel):
139+
badge_name: str
140+
name: str
141+
urn: str
142+
143+
class Config:
144+
arbitrary_types_allowed = True
145+
from_attributes = True
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import Optional
2+
3+
from mavedb.view_models.base.base import BaseModel
4+
5+
6+
class ExternalLink(BaseModel):
7+
"""
8+
Represents an external hyperlink for view models.
9+
10+
Attributes:
11+
url (Optional[str]): Fully qualified URL for the external resource.
12+
May be None if no link is available or applicable.
13+
"""
14+
15+
url: Optional[str] = None

src/mavedb/view_models/experiment.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from mavedb.lib.validation.utilities import is_null
1414
from mavedb.view_models import record_type_validator, set_record_type
1515
from mavedb.view_models.base.base import BaseModel
16+
from mavedb.view_models.collection import OfficialCollection
17+
from mavedb.view_models.components.external_link import ExternalLink
1618
from mavedb.view_models.contributor import Contributor, ContributorCreate
1719
from mavedb.view_models.doi_identifier import (
1820
DoiIdentifier,
@@ -37,20 +39,6 @@
3739
from mavedb.view_models.user import SavedUser, User
3840

3941

40-
class ExternalLink(BaseModel):
41-
url: Optional[str] = None
42-
43-
44-
class OfficialCollection(BaseModel):
45-
badge_name: str
46-
name: str
47-
urn: str
48-
49-
class Config:
50-
arbitrary_types_allowed = True
51-
from_attributes = True
52-
53-
5442
class ExperimentBase(BaseModel):
5543
title: str
5644
short_description: str

src/mavedb/view_models/score_set.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from mavedb.models.enums.processing_state import ProcessingState
2020
from mavedb.view_models import record_type_validator, set_record_type
2121
from mavedb.view_models.base.base import BaseModel
22+
from mavedb.view_models.collection import OfficialCollection
23+
from mavedb.view_models.components.external_link import ExternalLink
2224
from mavedb.view_models.contributor import Contributor, ContributorCreate
2325
from mavedb.view_models.doi_identifier import (
2426
DoiIdentifier,
@@ -49,20 +51,6 @@
4951
UnboundedRange = tuple[Union[float, None], Union[float, None]]
5052

5153

52-
class ExternalLink(BaseModel):
53-
url: Optional[str] = None
54-
55-
56-
class OfficialCollection(BaseModel):
57-
badge_name: str
58-
name: str
59-
urn: str
60-
61-
class Config:
62-
arbitrary_types_allowed = True
63-
from_attributes = True
64-
65-
6654
class ScoreSetBase(BaseModel):
6755
"""Base class for score set view models."""
6856

tests/helpers/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@
544544
"urn": None,
545545
"experimentSetUrn": None,
546546
"officialCollections": [],
547+
"externalLinks": {},
547548
"numScoreSets": 0,
548549
}
549550

0 commit comments

Comments
 (0)