From f8e055d682b54f768ff6f5d9eb119e2a928fd8bc Mon Sep 17 00:00:00 2001 From: Diego Espindola Date: Wed, 2 Jul 2025 19:46:53 -0300 Subject: [PATCH 1/8] Create Subscription schema --- schemas/schemas.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 schemas/schemas.py diff --git a/schemas/schemas.py b/schemas/schemas.py new file mode 100644 index 0000000..145b3d4 --- /dev/null +++ b/schemas/schemas.py @@ -0,0 +1,7 @@ +from pydantic import BaseModel +from typing import List, Literal + + +class Subscription(BaseModel): + tags: Literal["bug_fix","update","deprecate","new_feature","security_fix"] + libraries_list: List[str] From 596782153359815f7473d33c53ba85080bf96374 Mon Sep 17 00:00:00 2001 From: Diego Espindola Date: Wed, 2 Jul 2025 19:47:09 -0300 Subject: [PATCH 2/8] Create main.py --- main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..ac3132c --- /dev/null +++ b/main.py @@ -0,0 +1,15 @@ +from fastapi import FastAPI +from schemas.schemas import Subscription + + +# Caso precise instanciar o FastAPI +app = FastAPI() + +# TODO inserir no router +@app.post("/libraries/subscribe/") +async def create_subscription(subscription:Subscription): + return { + "message": "Dados recebidos com sucesso", + "tags": subscription.tags, + "libraries_list": subscription.libraries_list + } \ No newline at end of file From 3422f24af65158dc4685287cdd2a241a96e48152 Mon Sep 17 00:00:00 2001 From: Diego Espindola Date: Thu, 3 Jul 2025 08:50:10 -0300 Subject: [PATCH 3/8] =?UTF-8?q?Corre=C3=A7=C3=A3o=20Lista=20tags=20e=20men?= =?UTF-8?q?sagem=20de=20erro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schemas/schemas.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/schemas/schemas.py b/schemas/schemas.py index 145b3d4..0837814 100644 --- a/schemas/schemas.py +++ b/schemas/schemas.py @@ -1,7 +1,18 @@ -from pydantic import BaseModel -from typing import List, Literal +from pydantic import BaseModel, field_validator +from typing import List +ALLOWED_TAGS_SUBSCRIPTION = {"bug_fix", "update", "deprecate", "new_feature", "security_fix"} + class Subscription(BaseModel): - tags: Literal["bug_fix","update","deprecate","new_feature","security_fix"] + tags: List[str] libraries_list: List[str] + + @field_validator("tags") + def validate_tags(cls, tags): + invalid = [tag for tag in tags if tag not in ALLOWED_TAGS_SUBSCRIPTION] + if invalid: + raise ValueError( + f"Tags inválidas: {invalid}. As opções permitidas são: {ALLOWED_TAGS_SUBSCRIPTION}" + ) + return tags From d64b61aa323790a207932f3da956c2da37f4b1c2 Mon Sep 17 00:00:00 2001 From: Diego Espindola Date: Mon, 7 Jul 2025 21:00:14 -0300 Subject: [PATCH 4/8] Update schemas.py --- schemas/schemas.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/schemas/schemas.py b/schemas/schemas.py index 0837814..7853c95 100644 --- a/schemas/schemas.py +++ b/schemas/schemas.py @@ -1,18 +1,15 @@ -from pydantic import BaseModel, field_validator +from pydantic import BaseModel +from enum import Enum from typing import List -ALLOWED_TAGS_SUBSCRIPTION = {"bug_fix", "update", "deprecate", "new_feature", "security_fix"} +class TagEnum(str, Enum): + bug_fix = "bug_fix" + update = "update" + deprecate = "deprecate" + new_feature = "new_feature" + security_fix = "security_fix" class Subscription(BaseModel): - tags: List[str] + tags: List[TagEnum] libraries_list: List[str] - - @field_validator("tags") - def validate_tags(cls, tags): - invalid = [tag for tag in tags if tag not in ALLOWED_TAGS_SUBSCRIPTION] - if invalid: - raise ValueError( - f"Tags inválidas: {invalid}. As opções permitidas são: {ALLOWED_TAGS_SUBSCRIPTION}" - ) - return tags From 15edfed53bf70c87f308d51c7e806d2e5cbebd7f Mon Sep 17 00:00:00 2001 From: Diego Espindola Date: Wed, 16 Jul 2025 21:24:18 -0300 Subject: [PATCH 5/8] Delete schemas.py --- schemas/schemas.py | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 schemas/schemas.py diff --git a/schemas/schemas.py b/schemas/schemas.py deleted file mode 100644 index 7853c95..0000000 --- a/schemas/schemas.py +++ /dev/null @@ -1,15 +0,0 @@ -from pydantic import BaseModel -from enum import Enum -from typing import List - - -class TagEnum(str, Enum): - bug_fix = "bug_fix" - update = "update" - deprecate = "deprecate" - new_feature = "new_feature" - security_fix = "security_fix" - -class Subscription(BaseModel): - tags: List[TagEnum] - libraries_list: List[str] From 955338a645a49f96171040d200191a68e3381675 Mon Sep 17 00:00:00 2001 From: Diego Espindola Date: Wed, 16 Jul 2025 21:24:52 -0300 Subject: [PATCH 6/8] feat(schemas): Adicionar classe subscription aos schemas --- app/schemas.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/schemas.py b/app/schemas.py index 3e40b2f..09c6ce3 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -1,6 +1,22 @@ from pydantic import BaseModel, HttpUrl from datetime import datetime +from typing import List +from enum import Enum + +# Subscription +class TagEnum(str, Enum): + bug_fix = "bug_fix" + update = "update" + deprecate = "deprecate" + new_feature = "new_feature" + security_fix = "security_fix" + +class Subscription(BaseModel): + tags: List[TagEnum] + libraries_list: List[str] + +# News class News(BaseModel): description: str tag: str From 9003ea954ca33339f7f4b19bf107cbe22cd62383 Mon Sep 17 00:00:00 2001 From: Diego Espindola Date: Wed, 16 Jul 2025 21:38:48 -0300 Subject: [PATCH 7/8] Feat(schemas): Criar classe Subscription - pydantic --- app/schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/schemas.py b/app/schemas.py index 09c6ce3..236f2e1 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -4,7 +4,7 @@ from enum import Enum -# Subscription +# Subscription Class class TagEnum(str, Enum): bug_fix = "bug_fix" update = "update" From a280ecf217a50ad617eddda262757908bb37a213 Mon Sep 17 00:00:00 2001 From: Diego Espindola Date: Wed, 16 Jul 2025 21:41:31 -0300 Subject: [PATCH 8/8] Delete main.py --- main.py | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index ac3132c..0000000 --- a/main.py +++ /dev/null @@ -1,15 +0,0 @@ -from fastapi import FastAPI -from schemas.schemas import Subscription - - -# Caso precise instanciar o FastAPI -app = FastAPI() - -# TODO inserir no router -@app.post("/libraries/subscribe/") -async def create_subscription(subscription:Subscription): - return { - "message": "Dados recebidos com sucesso", - "tags": subscription.tags, - "libraries_list": subscription.libraries_list - } \ No newline at end of file