1
0

Moved data model into own file
Some checks failed
Test Python / Test (push) Failing after 22s

This commit is contained in:
Jon Michael Aanes 2024-09-26 23:07:46 +02:00
parent 15906dac21
commit fe59477cfa
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
3 changed files with 84 additions and 73 deletions

View File

@ -6,80 +6,10 @@ import functools
from collections.abc import Iterator from collections.abc import Iterator
from logging import getLogger from logging import getLogger
from .favro_data_model import Card, CardId, SeqId, OrganizationId
logger = getLogger(__name__) logger = getLogger(__name__)
# Types
@dataclasses.dataclass(frozen=True)
class SeqId:
raw_id: int
@dataclasses.dataclass(frozen=True)
class CardId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class CommonId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class UserId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class OrganizationId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class Card:
card_id: CardId
seq_id: SeqId
common_id: CommonId
organization_id: OrganizationId
is_archived: bool
name: str
dependencies: list[None] # TODO
tags: list[None] # TODO
todo_list_user_id: UserId | None
todo_list_completed: bool | None
creator_user_id: UserId
creation_date: datetime.datetime
detailed_description: str | None
''' TODO, fieds:
'position': -399
'listPosition': -399
'isLane': False
'assignments': [{'userId': 'Faieomp8fuS8DrnyP' 'completed': True}]
'tasksTotal': 0
'tasksDone': 0
'attachments': []
'customFields':
'timeOnBoard': None
'timeOnColumns': None
'favroAttachments': []
'''
@staticmethod
def from_json(json: dict[str, Any]) -> 'Card':
return Card(
card_id = CardId(json['cardId']),
seq_id = SeqId(json['sequentialId']),
common_id = CommonId(json['cardCommonId']),
detailed_description = json.get('detailedDescription'),
is_archived = json['archived'],
organization_id = OrganizationId(json['organizationId']),
name = json['name'],
todo_list_user_id = UserId(json['todoListUserId' ]) if 'todoListUserId' in json else None,
todo_list_completed = json.get('todoListCompleted'),
dependencies = json['dependencies'],
tags = json['tags'],
creator_user_id = UserId(json['createdByUserId']),
creation_date = datetime.datetime.fromisoformat(json['createdAt']),
)
# Endpoints # Endpoints
URL_API_ROOT = 'https://favro.com/api/v1' URL_API_ROOT = 'https://favro.com/api/v1'
URL_GET_ALL_CARDS = URL_API_ROOT+'/cards' URL_GET_ALL_CARDS = URL_API_ROOT+'/cards'

View File

@ -0,0 +1,80 @@
import requests
import dataclasses
import datetime
from typing import Any
import functools
from collections.abc import Iterator
from logging import getLogger
@dataclasses.dataclass(frozen=True)
class SeqId:
raw_id: int
@dataclasses.dataclass(frozen=True)
class CardId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class CommonId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class UserId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class OrganizationId:
raw_id: str
@dataclasses.dataclass(frozen=True)
class Card:
card_id: CardId
seq_id: SeqId
common_id: CommonId
organization_id: OrganizationId
is_archived: bool
name: str
dependencies: list[None] # TODO
tags: list[None] # TODO
todo_list_user_id: UserId | None
todo_list_completed: bool | None
creator_user_id: UserId
creation_date: datetime.datetime
detailed_description: str | None
''' TODO, fieds:
'position': -399
'listPosition': -399
'isLane': False
'assignments': [{'userId': 'Faieomp8fuS8DrnyP' 'completed': True}]
'tasksTotal': 0
'tasksDone': 0
'attachments': []
'customFields':
'timeOnBoard': None
'timeOnColumns': None
'favroAttachments': []
'''
@staticmethod
def from_json(json: dict[str, Any]) -> 'Card':
return Card(
card_id = CardId(json['cardId']),
seq_id = SeqId(json['sequentialId']),
common_id = CommonId(json['cardCommonId']),
detailed_description = json.get('detailedDescription'),
is_archived = json['archived'],
organization_id = OrganizationId(json['organizationId']),
name = json['name'],
todo_list_user_id = UserId(json['todoListUserId' ]) if 'todoListUserId' in json else None,
todo_list_completed = json.get('todoListCompleted'),
dependencies = json['dependencies'],
tags = json['tags'],
creator_user_id = UserId(json['createdByUserId']),
creation_date = datetime.datetime.fromisoformat(json['createdAt']),
)

View File

@ -4,7 +4,8 @@ import re
import dataclasses import dataclasses
from collections.abc import Iterator from collections.abc import Iterator
from .favro_client import FavroClient, CardId, SeqId, Card from .favro_data_model import CardId, SeqId, Card
from .favro_client import FavroClient
fuse.fuse_python_api = (0, 2) fuse.fuse_python_api = (0, 2)