api: Update to use hff_notion_api_client instead of defunct notion_utils.
This commit is contained in:
parent
e90f392ef1
commit
b17520946e
@ -1,12 +1,12 @@
|
|||||||
FROM 063932952339.dkr.ecr.us-west-2.amazonaws.com/alpine-nim:nim-1.4.8 AS build
|
FROM 063932952339.dkr.ecr.us-west-2.amazonaws.com/alpine-nim:nim-1.6.10 AS build
|
||||||
MAINTAINER jonathan@jdbernard.com
|
MAINTAINER jonathan@jdbernard.com
|
||||||
|
|
||||||
COPY hff_entry_forms_api.nimble /hff_entry_forms_api/
|
COPY hff_entry_forms_api.nimble /hff_entry_forms_api/
|
||||||
COPY src /hff_entry_forms_api/src
|
COPY src /hff_entry_forms_api/src
|
||||||
WORKDIR /hff_entry_forms_api
|
WORKDIR /hff_entry_forms_api
|
||||||
RUN nimble build -y
|
RUN nimble build -y --passC:-fpermissive
|
||||||
|
|
||||||
FROM alpine
|
FROM alpine:3.16.4
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
RUN apk -v --update add --no-cache \
|
RUN apk -v --update add --no-cache \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
@ -4,7 +4,14 @@ SOURCES=$(wildcard src/*.nim) $(wildcard src/hff_entry_forms_apipkg/*.nim)
|
|||||||
ECR_ACCOUNT_URL ?= 063932952339.dkr.ecr.us-west-2.amazonaws.com
|
ECR_ACCOUNT_URL ?= 063932952339.dkr.ecr.us-west-2.amazonaws.com
|
||||||
|
|
||||||
# The port on the host machine (not the container)
|
# The port on the host machine (not the container)
|
||||||
PORT ?= 8300
|
ifeq ($(TARGET_ENV),prod)
|
||||||
|
PORT=6006
|
||||||
|
else
|
||||||
|
PORT=6005
|
||||||
|
endif
|
||||||
|
|
||||||
|
# The server to target when publishing the API
|
||||||
|
TARGET_SERVER ?= sobeck.jdb-software.com
|
||||||
|
|
||||||
# The Notion integration token.
|
# The Notion integration token.
|
||||||
AUTH_SECRET ?= 123abc
|
AUTH_SECRET ?= 123abc
|
||||||
|
@ -16,7 +16,7 @@ requires @["docopt", "jester"]
|
|||||||
requires "https://git.jdb-software.com/jdb/nim-cli-utils.git >= 0.6.3"
|
requires "https://git.jdb-software.com/jdb/nim-cli-utils.git >= 0.6.3"
|
||||||
requires "https://git.jdb-software.com/jdb/nim-time-utils.git >= 0.5.0"
|
requires "https://git.jdb-software.com/jdb/nim-time-utils.git >= 0.5.0"
|
||||||
requires "https://git.jdb-software.com/jdb/update-nim-package-version.git"
|
requires "https://git.jdb-software.com/jdb/update-nim-package-version.git"
|
||||||
requires "https://git.jdb-software.com/hope-family-fellowship/notion_utils.git"
|
requires "https://git.jdb-software.com/hope-family-fellowship/notion-api-client.git"
|
||||||
|
|
||||||
task updateVersion, "Update the version of this package.":
|
task updateVersion, "Update the version of this package.":
|
||||||
exec "update_nim_package_version hff_entry_forms_api 'src/hff_entry_forms_apipkg/version.nim'"
|
exec "update_nim_package_version hff_entry_forms_api 'src/hff_entry_forms_apipkg/version.nim'"
|
||||||
|
@ -26,7 +26,7 @@ template jsonResp(code: HttpCode,
|
|||||||
headersToSend: RawHeaders = @{:} ) =
|
headersToSend: RawHeaders = @{:} ) =
|
||||||
## Immediately send a JSON response and stop processing the request.
|
## Immediately send a JSON response and stop processing the request.
|
||||||
let reqOrigin =
|
let reqOrigin =
|
||||||
if request.headers.hasKey("Origin"): $(request.headers["Origin"])
|
if headers(request).hasKey("Origin"): $(headers(request)["Origin"])
|
||||||
else: ""
|
else: ""
|
||||||
|
|
||||||
let corsHeaders =
|
let corsHeaders =
|
||||||
@ -34,7 +34,7 @@ template jsonResp(code: HttpCode,
|
|||||||
@{
|
@{
|
||||||
"Access-Control-Allow-Origin": reqOrigin,
|
"Access-Control-Allow-Origin": reqOrigin,
|
||||||
"Access-Control-Allow-Credentials": "true",
|
"Access-Control-Allow-Credentials": "true",
|
||||||
"Access-Control-Allow-Methods": $(request.reqMethod),
|
"Access-Control-Allow-Methods": $(reqMethod(request)),
|
||||||
"Access-Control-Allow-Headers": "Authorization,X-CSRF-TOKEN"
|
"Access-Control-Allow-Headers": "Authorization,X-CSRF-TOKEN"
|
||||||
}
|
}
|
||||||
else: @{:}
|
else: @{:}
|
||||||
@ -81,7 +81,7 @@ template errorResp(err: ref ApiError): void =
|
|||||||
template optionsResp(allowedMethods: seq[HttpMethod]) =
|
template optionsResp(allowedMethods: seq[HttpMethod]) =
|
||||||
|
|
||||||
let reqOrigin =
|
let reqOrigin =
|
||||||
if request.headers.hasKey("Origin"): $(request.headers["Origin"])
|
if headers(request).hasKey("Origin"): $(headers(request)["Origin"])
|
||||||
else: ""
|
else: ""
|
||||||
|
|
||||||
let corsHeaders =
|
let corsHeaders =
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import std/json, std/times
|
import std/json, std/times
|
||||||
import notion_utils, timeutils
|
import hff_notion_api_client/utils, timeutils
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -43,7 +43,7 @@ proc parseEventProposal*(n: JsonNode): EventProposal {.raises: [JsonParsingError
|
|||||||
except:
|
except:
|
||||||
raise newException(JsonParsingError, "Invalid EventProposal: " & getCurrentExceptionMsg())
|
raise newException(JsonParsingError, "Invalid EventProposal: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
proc asNotionPage*(ep: EventProposal): JsonNode =
|
proc toPage*(ep: EventProposal): JsonNode =
|
||||||
result = %*{
|
result = %*{
|
||||||
"properties": {
|
"properties": {
|
||||||
"Event": makeTextProp("title", ep.name),
|
"Event": makeTextProp("title", ep.name),
|
||||||
|
@ -1,22 +1,29 @@
|
|||||||
import std/json, std/logging, std/httpclient, std/sequtils, std/strutils
|
import std/[json, httpclient, logging, options, sequtils, strutils]
|
||||||
import notion_utils
|
import hff_notion_api_client
|
||||||
|
import hff_notion_api_client/config
|
||||||
|
|
||||||
import ./models, ./service
|
import ./models, ./service
|
||||||
|
|
||||||
|
var notionClient = none[NotionClient]()
|
||||||
|
|
||||||
|
proc getNotionClient(cfg: HffEntryFormsApiConfig): NotionClient =
|
||||||
|
if notionClient.isNone:
|
||||||
|
notionClient = some(initNotionClient(NotionClientConfig(
|
||||||
|
apiVersion: cfg.notionVersion,
|
||||||
|
apiBaseUrl: cfg.notionApiBaseUrl,
|
||||||
|
configDbId: "",
|
||||||
|
integrationToken: cfg.integrationToken)))
|
||||||
|
return notionClient.get
|
||||||
|
|
||||||
proc getEventProposalConfig*(cfg: HffEntryFormsApiConfig): EventProposalConfig =
|
proc getEventProposalConfig*(cfg: HffEntryFormsApiConfig): EventProposalConfig =
|
||||||
let http = newNotionClient(
|
let notion = getNotionClient(cfg)
|
||||||
apiVersion = cfg.notionVersion,
|
|
||||||
integrationToken = cfg.integrationToken)
|
|
||||||
|
|
||||||
let apiResp = http.get(cfg.notionApiBaseUrl & "/databases/" & cfg.eventParentId)
|
var bodyJson: JsonNode
|
||||||
debug apiResp.status
|
try: bodyJson = notion.fetchDatabaseObject(cfg.eventParentId)
|
||||||
|
except:
|
||||||
if not apiResp.status.startsWith("2"):
|
|
||||||
debug apiResp.body
|
|
||||||
raiseApiError(Http500,
|
raiseApiError(Http500,
|
||||||
"unable to read event propsal configuration from notion API")
|
"unable to read event propsal configuration from notion API")
|
||||||
|
|
||||||
let bodyJson = parseJson(apiResp.body)
|
|
||||||
let departmentOptionsJson = bodyJson{
|
let departmentOptionsJson = bodyJson{
|
||||||
"properties", "Department", "multi_select", "options"}
|
"properties", "Department", "multi_select", "options"}
|
||||||
|
|
||||||
@ -31,16 +38,9 @@ proc getEventProposalConfig*(cfg: HffEntryFormsApiConfig): EventProposalConfig =
|
|||||||
)
|
)
|
||||||
|
|
||||||
proc createProposedEvent*(cfg: HffEntryFormsApiConfig, ep: EventProposal): bool =
|
proc createProposedEvent*(cfg: HffEntryFormsApiConfig, ep: EventProposal): bool =
|
||||||
let http = newNotionClient(
|
let notion = getNotionClient(cfg)
|
||||||
apiVersion = cfg.notionVersion,
|
|
||||||
integrationToken = cfg.integrationToken)
|
|
||||||
|
|
||||||
let epNotionPage = ep.asNotionPage
|
try:
|
||||||
epNotionPage["parent"] = %*{ "database_id": cfg.eventParentId }
|
discard notion.createDbPage(cfg.eventParentId, ep)
|
||||||
|
return true
|
||||||
let apiResp = http.post(cfg.notionApiBaseUrl & "/pages", $epNotionPage)
|
except: return false
|
||||||
|
|
||||||
debug apiResp.status
|
|
||||||
if not apiResp.status.startsWith("2"): debug apiResp.body
|
|
||||||
|
|
||||||
return apiResp.status.startsWith("2")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user