update api

This commit is contained in:
Paul J Stevens 2024-04-07 13:19:37 +02:00
parent 4c77e32b77
commit 8c75c1836f
3 changed files with 110 additions and 27 deletions

View File

@ -214,18 +214,18 @@ files = [
[[package]]
name = "fastapi"
version = "0.108.0"
version = "0.110.1"
requires_python = ">=3.8"
summary = "FastAPI framework, high performance, easy to learn, fast to code, ready for production"
groups = ["default"]
dependencies = [
"pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4",
"starlette<0.33.0,>=0.29.0",
"starlette<0.38.0,>=0.37.2",
"typing-extensions>=4.8.0",
]
files = [
{file = "fastapi-0.108.0-py3-none-any.whl", hash = "sha256:8c7bc6d315da963ee4cdb605557827071a9a7f95aeb8fcdd3bde48cdc8764dd7"},
{file = "fastapi-0.108.0.tar.gz", hash = "sha256:5056e504ac6395bf68493d71fcfc5352fdbd5fda6f88c21f6420d80d81163296"},
{file = "fastapi-0.110.1-py3-none-any.whl", hash = "sha256:5df913203c482f820d31f48e635e022f8cbfe7350e4830ef05a3163925b1addc"},
{file = "fastapi-0.110.1.tar.gz", hash = "sha256:6feac43ec359dfe4f45b2c18ec8c94edb8dc2dfc461d417d9e626590c071baad"},
]
[[package]]
@ -404,7 +404,7 @@ files = [
[[package]]
name = "marshmallow"
version = "3.20.1"
version = "3.21.1"
requires_python = ">=3.8"
summary = "A lightweight library for converting complex datatypes to and from native Python datatypes."
groups = ["default"]
@ -412,8 +412,8 @@ dependencies = [
"packaging>=17.0",
]
files = [
{file = "marshmallow-3.20.1-py3-none-any.whl", hash = "sha256:684939db93e80ad3561392f47be0230743131560a41c5110684c16e21ade0a5c"},
{file = "marshmallow-3.20.1.tar.gz", hash = "sha256:5d2371bbe42000f2b3fb5eaa065224df7d8f8597bc19a1bbfa5bfe7fba8da889"},
{file = "marshmallow-3.21.1-py3-none-any.whl", hash = "sha256:f085493f79efb0644f270a9bf2892843142d80d7174bbbd2f3713f2a589dc633"},
{file = "marshmallow-3.21.1.tar.gz", hash = "sha256:4e65e9e0d80fc9e609574b9983cf32579f305c718afb30d7233ab818571768c3"},
]
[[package]]
@ -495,7 +495,7 @@ files = [
[[package]]
name = "pre-commit"
version = "3.6.0"
version = "3.7.0"
requires_python = ">=3.9"
summary = "A framework for managing and maintaining multi-language pre-commit hooks."
groups = ["dev"]
@ -507,8 +507,8 @@ dependencies = [
"virtualenv>=20.10.0",
]
files = [
{file = "pre_commit-3.6.0-py2.py3-none-any.whl", hash = "sha256:c255039ef399049a5544b6ce13d135caba8f2c28c3b4033277a788f434308376"},
{file = "pre_commit-3.6.0.tar.gz", hash = "sha256:d30bad9abf165f7785c15a21a1f46da7d0677cb00ee7ff4c579fd38922efe15d"},
{file = "pre_commit-3.7.0-py2.py3-none-any.whl", hash = "sha256:5eae9e10c2b5ac51577c3452ec0a490455c45a0533f7960f993a0d01e59decab"},
{file = "pre_commit-3.7.0.tar.gz", hash = "sha256:e209d61b8acdcf742404408531f0c37d49d2c734fd7cff2d6076083d191cb060"},
]
[[package]]
@ -542,7 +542,7 @@ files = [
[[package]]
name = "pyairtable"
version = "2.2.1"
version = "2.3.3"
summary = "Python Client for the Airtable API"
groups = ["default"]
dependencies = [
@ -553,8 +553,8 @@ dependencies = [
"urllib3>=1.26",
]
files = [
{file = "pyairtable-2.2.1-py2.py3-none-any.whl", hash = "sha256:682f69611c80dcf769ec75c033a75dc5390ad530a4423b145333d8a3bdfca6f1"},
{file = "pyairtable-2.2.1.tar.gz", hash = "sha256:1913cfa5a1fc98c4723fafcafde1b4cbc97546b7ea84f37e51f24d43f641f051"},
{file = "pyairtable-2.3.3-py2.py3-none-any.whl", hash = "sha256:2fa872971e31e3e8675cb6d9606362ea8072bbb7971592826edc7010b6afa87b"},
{file = "pyairtable-2.3.3.tar.gz", hash = "sha256:6f52bd270d28ba6459b7cc473588e517085a737d70c68e855e6d104972e1121e"},
]
[[package]]
@ -805,7 +805,7 @@ files = [
[[package]]
name = "schwifty"
version = "2023.11.2"
version = "2024.1.1.post0"
requires_python = ">=3.8"
summary = ""
groups = ["default"]
@ -814,8 +814,8 @@ dependencies = [
"pycountry",
]
files = [
{file = "schwifty-2023.11.2-py3-none-any.whl", hash = "sha256:81bfa92a32a4a2098a793f2e99dc468b3027c13ca64d9d328ace24d1766aea40"},
{file = "schwifty-2023.11.2.tar.gz", hash = "sha256:972c80c7c5432113bbdb15bae208dcb19c360b7d615776022c819299d94825e2"},
{file = "schwifty-2024.1.1.post0-py3-none-any.whl", hash = "sha256:5eeb587919f331f0c5ffce7de5cc6b0279c0e6e9e2cf1b96fb64e421884ed235"},
{file = "schwifty-2024.1.1.post0.tar.gz", hash = "sha256:6450eefacb6e29db1573c6d3b926782d95fc06e4213918f210ca2c9eb935ad7d"},
]
[[package]]
@ -879,7 +879,7 @@ files = [
[[package]]
name = "starlette"
version = "0.32.0.post1"
version = "0.37.2"
requires_python = ">=3.8"
summary = "The little ASGI library that shines."
groups = ["default"]
@ -887,8 +887,8 @@ dependencies = [
"anyio<5,>=3.4.0",
]
files = [
{file = "starlette-0.32.0.post1-py3-none-any.whl", hash = "sha256:cd0cb10ddb49313f609cedfac62c8c12e56c7314b66d89bb077ba228bada1b09"},
{file = "starlette-0.32.0.post1.tar.gz", hash = "sha256:e54e2b7e2fb06dff9eac40133583f10dfa05913f5a85bf26f427c7a40a9a3d02"},
{file = "starlette-0.37.2-py3-none-any.whl", hash = "sha256:6fe59f29268538e5d0d182f2791a479a0c64638e6935d1c6989e63fb2699c6ee"},
{file = "starlette-0.37.2.tar.gz", hash = "sha256:9af890290133b79fc3db55474ade20f6220a364a0402e0b556e7cd5e1e093823"},
]
[[package]]
@ -1313,7 +1313,7 @@ files = [
[[package]]
name = "uvicorn"
version = "0.25.0"
version = "0.29.0"
requires_python = ">=3.8"
summary = "The lightning-fast ASGI server."
groups = ["default"]
@ -1322,8 +1322,8 @@ dependencies = [
"h11>=0.8",
]
files = [
{file = "uvicorn-0.25.0-py3-none-any.whl", hash = "sha256:ce107f5d9bd02b4636001a77a4e74aab5e1e2b146868ebbad565237145af444c"},
{file = "uvicorn-0.25.0.tar.gz", hash = "sha256:6dddbad1d7ee0f5140aba5ec138ddc9612c5109399903828b4874c9937f009c2"},
{file = "uvicorn-0.29.0-py3-none-any.whl", hash = "sha256:2c2aac7ff4f4365c206fd773a39bf4ebd1047c238f8b8268ad996829323473de"},
{file = "uvicorn-0.29.0.tar.gz", hash = "sha256:6a69214c0b6a087462412670b3ef21224fa48cae0e452b5883e8e8bdfdd11dd0"},
]
[[package]]

View File

@ -1,4 +1,5 @@
from fastapi import FastAPI
from typing import Annotated
from fastapi import FastAPI, Body, Path
from bij1.erp.models import Member
from trytond.transaction import Transaction
from bij1.erp import pool
@ -16,7 +17,52 @@ def valid(member: Member) -> bool:
@app.post("/members/")
async def create_member(member: Member):
async def create_member(
member: Annotated[
Member,
Body(
openapi_examples={
"normal": {
"summary": "A valid new member to be added",
"description": "A new member that does not exist yet",
"value": {
"name": "Jane Doe",
"email": "jane@example.com",
"phone": "+31612312312",
"address": "Mainstreet 1",
"postcode": "1234 AA",
"city": "Amsterdam",
"status": "Lid",
"since": "24-12-2021",
"iban": "NL32RABO0137767804",
"periode": "per maand",
"amount": "10.00",
"mandate": "cst_VhCgFjpP94",
},
},
"ex-lid": {
"summary": "A valid former member to be added",
"description": "A former member that does not exist yet",
"value": {
"name": "Jane Doe",
"email": "jane@example.com",
"phone": "+31612312312",
"address": "Mainstreet 1",
"postcode": "1234 AA",
"city": "Amsterdam",
"status": "Ex-lid",
"since": "24-12-2021",
"until": "15-7-2022",
"iban": "NL32RABO0137767804",
"periode": "per maand",
"amount": "10.00",
"mandate": "cst_VhCgFjpP94",
},
},
}
),
]
):
with Transaction().start(pool.database_name, 0):
if member.exists():
# return 401
@ -27,7 +73,45 @@ async def create_member(member: Member):
@app.put("/members/{member_email}")
async def update_member(member_email: str, member: Member):
async def update_member(
member_email: Annotated[
str,
Path(
openapi_examples={
"normal": {
"summary": "known email address",
"description": "This must be a known email address",
"value": "jane@example.com",
}
}
),
],
member: Annotated[
Member,
Body(
openapi_examples={
"normal": {
"summary": "Update member",
"description": "Updated data for known member",
"value": {
"name": "Jane Doe",
"email": "jane@example.com",
"phone": "+31612312312",
"address": "Mainstreet 1",
"postcode": "1234 AA",
"city": "Amsterdam",
"status": "Lid",
"since": "24-12-2021",
"iban": "NL32RABO0137767804",
"periode": "per maand",
"amount": "10.00",
"mandate": "cst_VhCgFjpP94",
},
},
}
),
],
):
with Transaction().start(pool.database_name, 0):
if not member.exists():
# return 401

View File

@ -2,7 +2,6 @@ from schwifty import IBAN
from datetime import date
from decimal import Decimal
import typing
from typing import Annotated
import logging
from bij1.erp import pool
from bij1.erp.config import config
@ -24,7 +23,7 @@ class Member(BaseModel):
since: typing.Optional[date] = None
until: typing.Optional[date] = None
iban: typing.Optional[str] = None
period: typing.Optional[Annotated[str, "'per maand' of 'per jaar'"]] = None
period: typing.Optional[str] = None
amount: typing.Optional[Decimal] = None
mandate: typing.Optional[str] = None