Skip to content

Commit

Permalink
Added all server routes and stub functions (#7)
Browse files Browse the repository at this point in the history
* Writing endpoints for the server and stub functions

* Added variable types for the server routes

---------

Co-authored-by: dzl-i <[email protected]>
  • Loading branch information
denzel-i and dzl-i authored Mar 8, 2023
1 parent c800085 commit cb69564
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 22 deletions.
22 changes: 22 additions & 0 deletions src/invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Dict

def invoice_quick_fix_wellformedness_v1(report_id) -> Dict:
return {}

def invoice_quick_fix_syntax_v1(report_id) -> Dict:
return {}

def invoice_quick_fix_peppol_v1(report_id) -> Dict:
return {}

def invoice_quick_fix_schema_v1(report_id) -> Dict:
return {}

def invoice_check_validity_v1(report_id) -> Dict:
return {}

def invoice_generate_hash_v1(name, format, source, data) -> Dict:
return {}

def invoice_bulk_quick_fix_v1(invoices) -> Dict:
return {}
77 changes: 56 additions & 21 deletions src/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,62 @@
from tempfile import NamedTemporaryFile
import requests

def report_json_report_v1(name, format, source, data) -> Dict:
return {}

def report_visual_report_v1(name, format, source, data, report_format) -> Dict:
return {}

def report_wellformedness_v1(name, format, source, data) -> Dict:
return {}

def report_schema_v1(name, format, source, data) -> Dict:
return {}

def report_syntax_v1(name, format, source, data) -> Dict:
return {}

def report_peppol_v1(name, format, source, data) -> Dict:
if source == "file":
with open(data, 'r') as f:
data = f.read()
elif source == "url":
response = requests.get(data)
if response.status_code != 200:
raise Exception("Could not retrieve file from url")

data = response.text

return generate_xslt_evaluation(data, "src/validation_artefacts/AUNZ-PEPPOL-validation.xslt")

def report_get_v1(report_id) -> Dict:
return {}

def report_list_all_v1(order_by) -> Dict:
return {}

def report_list_score_v1(score, order_by) -> Dict:
return {}

def report_export_v1(report_id, report_format) -> Dict:
return {}

def report_change_name_v1(report_id, new_name) -> Dict:
return {}

def report_delete_v1(report_id) -> Dict:
return {}

def report_bulk_generate_v1(invoices) -> Dict:
return {}

def report_bulk_export_v1(report_ids, report_format) -> Dict:
return {}

def report_bulk_export_v1(report_ids, report_format) -> Dict:
return {}

# Helper functions

def generate_xslt_evaluation(invoice_text, xslt_path) -> Dict:
with PySaxonProcessor(license=False) as proc:
Expand Down Expand Up @@ -75,24 +131,3 @@ def generate_xslt_evaluation(invoice_text, xslt_path) -> Dict:
}

return result


# Syntax report stub
def report_syntax_v1(name, format, source, data) -> Dict:
return {}


def report_peppol_v1(name, format, source, data) -> Dict:
if source == "file":
with open(data, 'r') as f:
data = f.read()
elif source == "url":
response = requests.get(data)
if response.status_code != 200:
raise Exception("Could not retrieve file from url")

data = response.text

return generate_xslt_evaluation(data, "src/validation_artefacts/AUNZ-PEPPOL-validation.xslt")


82 changes: 81 additions & 1 deletion src/server.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import signal
from src.config import base_url, port
from src.health_check import health_check_v1
from src.report import report_json_report_v1, report_visual_report_v1, report_wellformedness_v1, report_schema_v1, \
report_syntax_v1, report_peppol_v1, report_get_v1, report_list_all_v1, report_list_score_v1, report_export_v1, \
report_change_name_v1, report_delete_v1, report_bulk_generate_v1, report_bulk_export_v1
from src.invoice import invoice_quick_fix_wellformedness_v1, invoice_quick_fix_syntax_v1, invoice_quick_fix_peppol_v1, \
invoice_quick_fix_schema_v1, invoice_check_validity_v1, invoice_generate_hash_v1, invoice_bulk_quick_fix_v1
from src.report import report_syntax_v1, report_peppol_v1
from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import JSONResponse
from src.error import AuthenticationError, InputError
import uvicorn
from pydantic import BaseModel
from typing import List

app = FastAPI()

Expand Down Expand Up @@ -35,16 +41,90 @@ class Invoice(BaseModel):
async def health_check():
return health_check_v1()

@app.post("/report/json_report/v1")
async def report_json_report(invoice: Invoice):
return report_json_report_v1(invoice.name, invoice.format, invoice.source, invoice.data)

@app.post("/report/visual_report/v1")
async def report_visual_report(invoice: Invoice, format: str):
return report_visual_report_v1(invoice.name, invoice.format, invoice.source, invoice.data, format)

@app.post("/report/wellformedness/v1")
async def report_wellformedness(invoice: Invoice):
return report_wellformedness_v1(invoice.name, invoice.format, invoice.source, invoice.data)

@app.post("/report/schema/v1")
async def report_schema(invoice: Invoice):
return report_schema_v1(invoice.name, invoice.format, invoice.source, invoice.data)

@app.post("/report/syntax/v1")
async def report_syntax(invoice: Invoice):
return report_syntax_v1(invoice.name, invoice.format, invoice.source, invoice.data)


@app.post("/report/peppol/v1")
async def report_peppol(invoice: Invoice):
return report_peppol_v1(invoice.name, invoice.format, invoice.source, invoice.data)

@app.get("/report/get/v1")
async def report_get(report_id: int):
return report_get_v1(report_id)

@app.get("/report/list_all/v1")
async def report_list_all(order_by: str):
return report_list_all_v1(order_by)

@app.get("/report/list_score/v1")
async def report_list_score(score: int, order_by: str):
return report_list_score_v1(score, order_by)

@app.get("/report/export/v1")
async def report_export(report_id: int, report_format: str):
return report_export_v1(report_id, report_format)

@app.put("/report/change_name/v1")
async def report_change_name(report_id: int, new_name: str):
return report_change_name_v1(report_id, new_name)

@app.delete("/report/delete/v1")
async def report_delete(report_id: int):
return report_delete_v1(report_id)

@app.get("/invoice/quick_fix_wellformedness/v1")
async def invoice_quick_fix_wellformedness(report_id: int):
return invoice_quick_fix_wellformedness_v1(report_id)

@app.get("/invoice/quick_fix_syntax/v1")
async def invoice_quick_fix_syntax(report_id: int):
return invoice_quick_fix_syntax_v1(report_id)

@app.get("/invoice/quick_fix_peppol/v1")
async def invoice_quick_fix_peppol(report_id: int):
return invoice_quick_fix_peppol_v1(report_id)

@app.get("/invoice/quick_fix_schema/v1")
async def invoice_quick_fix_schema(report_id: int):
return invoice_quick_fix_schema_v1(report_id)

@app.get("/invoice/check_validity/v1")
async def invoice_check_validity(report_id: int):
return invoice_check_validity_v1(report_id)

@app.post("/invoice/generate_hash/v1")
async def invoice_generate_hash(invoice: Invoice):
return invoice_generate_hash_v1(invoice.name, invoice.format, invoice.source, invoice.data)

@app.post("/report/bulk_generate/v1")
async def report_bulk_generate(invoices: List[Invoice]):
return report_bulk_generate_v1(invoices)

@app.get("/invoice/bulk_quick_fix/v1")
async def invoice_bulk_quick_fix(invoices: List[Invoice]):
return invoice_bulk_quick_fix_v1(invoices)

@app.get("/report/bulk_export/v1")
async def report_bulk_export(report_ids: int, report_format: str):
return report_bulk_export_v1(report_ids, report_format)


# Samples below

Expand Down

0 comments on commit cb69564

Please sign in to comment.