-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run payload validation as part of dataset endpoints (#319)
- Loading branch information
1 parent
199afcb
commit 1e1cd58
Showing
5 changed files
with
68 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from typing import List, Optional | ||
|
||
from pydantic import BaseModel, validator | ||
|
||
from server.domain.datasets.entities import DataFormat | ||
|
||
|
||
class CreateDatasetValidationMixin(BaseModel): | ||
@validator("formats", check_fields=False) | ||
def check_formats_at_least_one(cls, value: List[DataFormat]) -> List[DataFormat]: | ||
if not value: | ||
raise ValueError("formats must contain at least one item") | ||
return value | ||
|
||
@validator("contact_emails", check_fields=False) | ||
def check_contact_emails_at_least_one(cls, value: List[str]) -> List[str]: | ||
if not value: | ||
raise ValueError("contact_emails must contain at least one item") | ||
return value | ||
|
||
|
||
class UpdateDatasetValidationMixin(BaseModel): | ||
@validator("title", check_fields=False) | ||
def check_title_not_empty(cls, value: str) -> str: | ||
if not value: | ||
raise ValueError("title must not be empty") | ||
return value | ||
|
||
@validator("description", check_fields=False) | ||
def check_description_not_empty(cls, value: str) -> str: | ||
if not value: | ||
raise ValueError("description must not be empty") | ||
return value | ||
|
||
@validator("service", check_fields=False) | ||
def check_service_not_empty(cls, value: str) -> str: | ||
if not value: | ||
raise ValueError("service must not be empty") | ||
return value | ||
|
||
@validator("formats", check_fields=False) | ||
def check_formats_at_least_one(cls, value: List[DataFormat]) -> List[DataFormat]: | ||
if not value: | ||
raise ValueError("formats must contain at least one item") | ||
return value | ||
|
||
@validator("contact_emails", check_fields=False) | ||
def check_contact_emails_at_least_one(cls, value: List[str]) -> List[str]: | ||
if not value: | ||
raise ValueError("contact_emails must contain at least one item") | ||
return value | ||
|
||
@validator("published_url", check_fields=False) | ||
def check_published_url_not_empty(cls, value: Optional[str]) -> Optional[str]: | ||
if value is not None and not value: | ||
raise ValueError("published_url must not be empty") | ||
return value |