from http import HTTPStatus from marshmallow import Schema, fields from src.exceptions import BaseSchemaErrorRequest class BaseSchema(Schema): class Meta: strict = True def handle_error(self, exc, data, **kwargs): raise BaseSchemaErrorRequest(error_message=exc.messages, status_code=HTTPStatus.UNPROCESSABLE_ENTITY).respond() class NonSignedArtist(Schema): total_nsa = fields.Integer() new_nsa = fields.Integer() dropped_nsa = fields.Integer() created_at = fields.DateTime() class NonSignedTrack(Schema): total_nst = fields.Integer() new_nst = fields.Integer() created_at = fields.DateTime() # =================Response Schemas================= class PullLastData(BaseSchema): artist = fields.Nested(NonSignedArtist(exclude=('dropped_nsa', 'new_nsa',))) track = fields.Nested(NonSignedTrack(exclude=("new_nst",))) class PullWeeklyReportData(BaseSchema): created_at = fields.DateTime() # =================Request Schemas================= class CreateLastData(BaseSchema): artist = fields.Nested(NonSignedArtist(exclude=("created_at",))) track = fields.Nested(NonSignedTrack(exclude=("created_at",))) class CreateWeeklyReportData(BaseSchema): artist_name = fields.String(allow_none=True) drop_off_date = fields.DateTime() release_date = fields.Date(allow_none=True) label = fields.String(allow_none=True) album_type = fields.String(allow_none=True) tiktok_verified = fields.Boolean(allow_none=True) tiktok_followers = fields.Integer(allow_none=True) popularity_score = fields.Integer(allow_none=True) spotify_followers = fields.Integer(allow_none=True) spotify_link = fields.String(allow_none=True) dna_link = fields.String(allow_none=True) chartmetric_link = fields.String(allow_none=True)