This commit is contained in:
2025-07-17 15:51:53 -03:00
parent b30b158917
commit 8821325e19
8 changed files with 95 additions and 13 deletions

View File

@@ -1,4 +1,3 @@
from dataclasses import dataclass
from urllib.parse import quote_plus, urlparse
import requests
@@ -27,15 +26,6 @@ class EmailAlreadyExistsError(KonvivaError):
pass
@dataclass(frozen=True)
class User:
IDUsuario: int
Identificador: str
NomeUsuario: str
Email: str
CPF: str | None = None
def create_user(
id: str,
name: str,
@@ -97,7 +87,6 @@ def update_user(id: str, **kwargs) -> dict:
)
r.raise_for_status()
# Because Konviva does not return the proper HTTP status code
if err := glom(r.json(), 'errors', default=None):
err = err[0] if isinstance(err, list) else err
raise KonvivaError(err)
@@ -120,3 +109,24 @@ def get_users_by_email(email: str) -> list[dict]:
return []
return r.json()
def enroll(user_id: str, class_id: str) -> str:
url = urlparse(KONVIVA_API_URL)._replace(path='/action/api/integrarMatricula')
r = requests.post(
url=url.geturl(),
headers=headers,
json={
'IDUsuario': str(user_id),
'IDTurma': str(class_id),
'StatusMatricula': 'MATRICULADO',
},
)
r.raise_for_status()
if err := glom(r.json(), 'errors', default=None):
err = err[0] if isinstance(err, list) else err
raise KonvivaError(err)
return r.json().get('IDMatricula')