Skip to content

Commit

Permalink
bug fixed espo routes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmargutt committed Oct 18, 2024
1 parent ba6573f commit 1ffe3a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 8 additions & 4 deletions routes/routesEspo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
from fastapi import APIRouter, Request, Depends, HTTPException
from fastapi import APIRouter, Request, Depends
from fastapi.responses import JSONResponse
from utils.utilsKobo import (
add_submission,
clean_kobo_data,
get_attachment_dict,
update_submission_status
get_kobo_attachment,
update_submission_status,
)
from utils.utilsEspo import espo_request, required_headers_espocrm
import logging
from utils.logger import logger
from clients.espo_api_client import EspoAPI
import os
import re
import base64

router = APIRouter()


@router.post("/kobo-to-espocrm")
async def kobo_to_espocrm(
request: Request, dependencies=Depends(required_headers_espocrm)
Expand Down Expand Up @@ -214,4 +219,3 @@ async def kobo_to_espocrm(
logger.info("Success", extra=extra_logs)
update_submission_status(submission, "success")
return JSONResponse(status_code=200, content=target_response)

11 changes: 9 additions & 2 deletions utils/utilsKobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
from fastapi import HTTPException, Header
from azure.cosmos.exceptions import CosmosResourceExistsError
from utils.cosmos import cosmos_container_client
import sys


def required_headers_kobo(kobotoken: str = Header(), koboasset: str = Header()):
return kobotoken, koboasset


def required_headers_121_kobo(
url121: str = Header(), username121: str = Header(), password121: str = Header(), kobotoken: str = Header(), koboasset: str = Header()
url121: str = Header(),
username121: str = Header(),
password121: str = Header(),
kobotoken: str = Header(),
koboasset: str = Header(),
):
return url121, username121, password121, kobotoken, koboasset


def add_submission(kobo_data):
"""Add submission to CosmosDB. If submission already exists and status is pending, raise HTTPException."""
submission = {
Expand Down Expand Up @@ -94,4 +102,3 @@ def clean_kobo_data(kobo_data):
new_key = key.split("/")[-1]
kobo_data_clean[new_key] = kobo_data_clean.pop(key)
return kobo_data_clean

0 comments on commit 1ffe3a8

Please sign in to comment.