Compare commits
8 Commits
0.2.3
...
dfaede9fd8
Author | SHA1 | Date | |
---|---|---|---|
dfaede9fd8 | |||
955f83b8ad | |||
219796f9e2 | |||
845273eaf7 | |||
2112d1c970 | |||
fed6a48332 | |||
4e7b072745 | |||
06d2b3f384 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -25,3 +25,4 @@ pnpm-debug.log*
|
|||||||
.*.sw?
|
.*.sw?
|
||||||
|
|
||||||
api/hff_entry_forms_api
|
api/hff_entry_forms_api
|
||||||
|
api/test/runner
|
||||||
|
28
Makefile
28
Makefile
@ -1,32 +1,36 @@
|
|||||||
VERSION:=$(shell git describe --always)
|
VERSION:=$(shell git describe --always)
|
||||||
TARGET_ENV ?= dev
|
TARGET_ENV ?= dev
|
||||||
|
|
||||||
build: dist/hff-entry-forms-api.tar.gz dist/hff-entry-forms-web.tar.gz
|
build: api-image dist/hff-entry-forms-web.${TARGET_ENV}.tar.gz
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -r dist
|
-rm -r dist
|
||||||
-rm -r web/dist
|
make -C api clean
|
||||||
-docker container prune
|
make -C web clean
|
||||||
-docker image prune
|
|
||||||
|
test:
|
||||||
|
(cd api && nimble unittest)
|
||||||
|
|
||||||
update-version:
|
update-version:
|
||||||
operations/update-version.sh
|
operations/update-version.sh
|
||||||
|
|
||||||
dist/hff-entry-forms-web.tar.gz:
|
api-image:
|
||||||
|
make -C api build-image
|
||||||
|
|
||||||
|
dist/hff-entry-forms-web-${VERSION}.${TARGET_ENV}.tar.gz:
|
||||||
-mkdir dist
|
-mkdir dist
|
||||||
TARGET_ENV=$(TARGET_ENV) make -C web build
|
TARGET_ENV=${TARGET_ENV} make -C web build
|
||||||
tar czf dist/hff-entry-forms-web-${VERSION}.tar.gz -C web/dist .
|
tar czf dist/hff-entry-forms-web-${VERSION}.${TARGET_ENV}.tar.gz -C web/dist .
|
||||||
cp dist/hff-entry-forms-web-${VERSION}.tar.gz dist/hff-entry-forms-web.tar.gz
|
|
||||||
|
|
||||||
deploy-api:
|
deploy-api:
|
||||||
make -C api build-image push-image
|
make -C api build-image push-image
|
||||||
cd operations/terraform && terraform apply -target module.${TARGET_ENV}_env.aws_ecs_task_definition.hff_entry_forms_api -target module.${TARGET_ENV}_env.aws_ecs_service.hff_entry_forms_api
|
cd operations/terraform && terraform apply -target module.${TARGET_ENV}_env.aws_ecs_task_definition.hff_entry_forms_api -target module.${TARGET_ENV}_env.aws_ecs_service.hff_entry_forms_api
|
||||||
|
|
||||||
deploy-web: dist/hff-entry-forms-web.tar.gz
|
deploy-web: dist/hff-entry-forms-web-${VERSION}.${TARGET_ENV}.tar.gz
|
||||||
mkdir -p temp-deploy/hff-entry-forms-web-${VERSION}
|
mkdir -p temp-deploy/hff-entry-forms-web-${VERSION}
|
||||||
tar xzf dist/hff-entry-forms-web-${VERSION}.tar.gz -C temp-deploy/hff-entry-forms-web-${VERSION}
|
tar xzf dist/hff-entry-forms-web-${VERSION}.${TARGET_ENV}.tar.gz -C temp-deploy/hff-entry-forms-web-${VERSION}
|
||||||
aws s3 sync temp-deploy/hff-entry-forms-web-${VERSION} s3://forms.hopefamilyfellowship.com/$(TARGET_ENV)/webroot
|
aws s3 sync temp-deploy/hff-entry-forms-web-${VERSION} s3://forms.hopefamilyfellowship.com/${TARGET_ENV}/webroot
|
||||||
TARGET_ENV=${TARGET_ENV} operations/invalidate-cdn-cache.sh
|
TARGET_ENV=${TARGET_ENV} operations/invalidate-cdn-cache.sh
|
||||||
rm -r temp-deploy
|
rm -r temp-deploy
|
||||||
|
|
||||||
deploy: deploy-api deploy-web
|
deploy: test deploy-api deploy-web
|
||||||
|
@ -69,6 +69,9 @@ serve-docker: build-image
|
|||||||
# Utility
|
# Utility
|
||||||
# -------
|
# -------
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-docker image rm $(ECR_ACCOUNT_URL)/hff_entry_forms_api:$(VERSION)
|
||||||
|
|
||||||
# Authenticate docker to the AWS private elastic container repository.
|
# Authenticate docker to the AWS private elastic container repository.
|
||||||
ecr-auth:
|
ecr-auth:
|
||||||
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $(ECR_ACCOUNT_URL)
|
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $(ECR_ACCOUNT_URL)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.2.3"
|
version = "0.3.1"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Hope Family Fellowship entry forms."
|
description = "Hope Family Fellowship entry forms."
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
@ -15,7 +15,11 @@ 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"
|
requires "https://git.jdb-software.com/jdb/update-nim-package-version.git"
|
||||||
|
requires "https://git.jdb-software.com/hope-family-fellowship/notion_utils.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'"
|
||||||
|
|
||||||
|
task unittest, "Runs the unit test suite.":
|
||||||
|
exec "nim c -r test/runner"
|
||||||
|
@ -42,7 +42,7 @@ Usage:
|
|||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
-C, --config <cfgFile> Location of the config file to use (defaults to
|
-c, --config <cfgFile> Location of the config file to use (defaults to
|
||||||
hff_entry_forms_api.config.json)
|
hff_entry_forms_api.config.json)
|
||||||
|
|
||||||
-d, --debug Log debugging information.
|
-d, --debug Log debugging information.
|
||||||
@ -52,7 +52,8 @@ Options:
|
|||||||
|
|
||||||
let consoleLogger = newConsoleLogger(
|
let consoleLogger = newConsoleLogger(
|
||||||
levelThreshold=lvlInfo,
|
levelThreshold=lvlInfo,
|
||||||
fmtStr="$app - $levelname: ")
|
fmtStr="$appname - $levelname: ",
|
||||||
|
useStderr=true)
|
||||||
logging.addHandler(consoleLogger)
|
logging.addHandler(consoleLogger)
|
||||||
|
|
||||||
# Initialize our service context
|
# Initialize our service context
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import json, times, timeutils
|
import std/json, std/times
|
||||||
|
import notion_utils, timeutils
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
EventProposal* = object
|
EventProposal* = object
|
||||||
@ -26,14 +28,6 @@ proc getOrFail(n: JsonNode, key: string): JsonNode =
|
|||||||
proc parseIso8601(n: JsonNode, key: string): DateTime =
|
proc parseIso8601(n: JsonNode, key: string): DateTime =
|
||||||
return parseIso8601(n.getOrFail(key).getStr)
|
return parseIso8601(n.getOrFail(key).getStr)
|
||||||
|
|
||||||
proc textProp(value: string): JsonNode =
|
|
||||||
return %*[
|
|
||||||
{
|
|
||||||
"type": "text",
|
|
||||||
"text": { "content": value }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
proc parseEventProposal*(n: JsonNode): EventProposal {.raises: [JsonParsingError].} =
|
proc parseEventProposal*(n: JsonNode): EventProposal {.raises: [JsonParsingError].} =
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -52,33 +46,34 @@ proc parseEventProposal*(n: JsonNode): EventProposal {.raises: [JsonParsingError
|
|||||||
proc asNotionPage*(ep: EventProposal): JsonNode =
|
proc asNotionPage*(ep: EventProposal): JsonNode =
|
||||||
result = %*{
|
result = %*{
|
||||||
"properties": {
|
"properties": {
|
||||||
"Event": { "title": textProp(ep.name) },
|
"Event": makeTextProp("title", ep.name),
|
||||||
"Date": { "date": { "start": formatIso8601(ep.date) } },
|
"Date": { "date": { "start": formatIso8601(ep.date) } },
|
||||||
"Department": { "multi_select": [ { "name": ep.department } ] },
|
"Department": { "multi_select": [ { "name": ep.department } ] },
|
||||||
"Location": { "rich_text": textProp(ep.location) },
|
"Location": makeTextProp("rich_text", ep.location),
|
||||||
"Owner": { "rich_text": textProp(ep.owner) },
|
"Owner": makeTextProp("rich_text", ep.owner),
|
||||||
"State": { "select": { "name": "Proposed" } }
|
"State": { "select": { "name": "Proposed" } },
|
||||||
|
"Visibility": { "select": { "name": "Public" } }
|
||||||
},
|
},
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"object": "block",
|
"object": "block",
|
||||||
"type": "heading_2",
|
"type": "heading_2",
|
||||||
"heading_2": { "text": textProp("Purpose") }
|
"heading_2": makeTextProp("text", "Purpose")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"object": "block",
|
"object": "block",
|
||||||
"type": "paragraph",
|
"type": "paragraph",
|
||||||
"paragraph": { "text": textProp(ep.purpose) }
|
"paragraph": makeTextProp("text", ep.purpose)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"object": "block",
|
"object": "block",
|
||||||
"type": "heading_2",
|
"type": "heading_2",
|
||||||
"heading_2": { "text": textProp("Description") }
|
"heading_2": makeTextProp("text", "Description")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"object": "block",
|
"object": "block",
|
||||||
"type": "paragraph",
|
"type": "paragraph",
|
||||||
"paragraph": { "text": textProp(ep.description) }
|
"paragraph": makeTextProp("text", ep.description)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
import json, logging, std/httpclient, sequtils, strutils
|
import std/json, std/logging, std/httpclient, std/sequtils, std/strutils
|
||||||
|
import notion_utils
|
||||||
|
|
||||||
import ./models, ./service
|
import ./models, ./service
|
||||||
|
|
||||||
proc makeHttpClient(cfg: HffEntryFormsApiConfig): HttpClient =
|
|
||||||
let headers = newHttpHeaders([
|
|
||||||
("Content-Type", "application/json"),
|
|
||||||
("Authorization", "Bearer " & cfg.integrationToken),
|
|
||||||
("Notion-Version", cfg.notionVersion)
|
|
||||||
], true)
|
|
||||||
debug $headers
|
|
||||||
return newHttpClient(headers = headers, )
|
|
||||||
|
|
||||||
proc getEventProposalConfig*(cfg: HffEntryFormsApiConfig): EventProposalConfig =
|
proc getEventProposalConfig*(cfg: HffEntryFormsApiConfig): EventProposalConfig =
|
||||||
let http = makeHttpClient(cfg)
|
let http = newNotionClient(
|
||||||
|
apiVersion = cfg.notionVersion,
|
||||||
|
integrationToken = cfg.integrationToken)
|
||||||
|
|
||||||
let apiResp = http.get(cfg.notionApiBaseUrl & "/databases/" & cfg.eventParentId)
|
let apiResp = http.get(cfg.notionApiBaseUrl & "/databases/" & cfg.eventParentId)
|
||||||
debug apiResp.status
|
debug apiResp.status
|
||||||
@ -37,7 +31,10 @@ proc getEventProposalConfig*(cfg: HffEntryFormsApiConfig): EventProposalConfig =
|
|||||||
)
|
)
|
||||||
|
|
||||||
proc createProposedEvent*(cfg: HffEntryFormsApiConfig, ep: EventProposal): bool =
|
proc createProposedEvent*(cfg: HffEntryFormsApiConfig, ep: EventProposal): bool =
|
||||||
let http = makeHttpClient(cfg)
|
let http = newNotionClient(
|
||||||
|
apiVersion = cfg.notionVersion,
|
||||||
|
integrationToken = cfg.integrationToken)
|
||||||
|
|
||||||
let epNotionPage = ep.asNotionPage
|
let epNotionPage = ep.asNotionPage
|
||||||
epNotionPage["parent"] = %*{ "database_id": cfg.eventParentId }
|
epNotionPage["parent"] = %*{ "database_id": cfg.eventParentId }
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
const HFF_ENTRY_FORMS_API_VERSION* = "0.2.3"
|
const HFF_ENTRY_FORMS_API_VERSION* = "0.3.1"
|
2
api/test/config.nims
Normal file
2
api/test/config.nims
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
switch("path", "../src")
|
||||||
|
switch("verbosity", "0")
|
3
api/test/runner.nim
Normal file
3
api/test/runner.nim
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import std/unittest
|
||||||
|
|
||||||
|
import ./tmodels
|
20
api/test/tmodels.nim
Normal file
20
api/test/tmodels.nim
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import std/json, std/times, std/unittest
|
||||||
|
|
||||||
|
import hff_entry_forms_apipkg/models
|
||||||
|
|
||||||
|
suite "models":
|
||||||
|
|
||||||
|
test "asNotionPage(EventProposal)":
|
||||||
|
let ep = EventProposal(
|
||||||
|
name: "Test Event",
|
||||||
|
description: "A test event.",
|
||||||
|
purpose: "Event example for unit testing.",
|
||||||
|
department: "Testing",
|
||||||
|
location: "Hope Family Fellowship",
|
||||||
|
owner: "Jonathan Bernard",
|
||||||
|
date: parse("2021-10-30", "YYYY-MM-dd"),
|
||||||
|
budgetInDollars: 56)
|
||||||
|
|
||||||
|
let expectedJson = """{"properties":{"Event":{"title":[{"type":"text","text":{"content":"Test Event"}}]},"Date":{"date":{"start":"2021-10-30T00:00:00.000-05:00"}},"Department":{"multi_select":[{"name":"Testing"}]},"Location":{"rich_text":[{"type":"text","text":{"content":"Hope Family Fellowship"}}]},"Owner":{"rich_text":[{"type":"text","text":{"content":"Jonathan Bernard"}}]},"State":{"select":{"name":"Proposed"}},"Visibility":{"select":{"name":"Public"}}},"children":[{"object":"block","type":"heading_2","heading_2":{"text":[{"type":"text","text":{"content":"Purpose"}}]}},{"object":"block","type":"paragraph","paragraph":{"text":[{"type":"text","text":{"content":"Event example for unit testing."}}]}},{"object":"block","type":"heading_2","heading_2":{"text":[{"type":"text","text":{"content":"Description"}}]}},{"object":"block","type":"paragraph","paragraph":{"text":[{"type":"text","text":{"content":"A test event."}}]}}]}"""
|
||||||
|
|
||||||
|
check $(ep.asNotionPage) == expectedJson
|
@ -3,3 +3,6 @@ build:
|
|||||||
|
|
||||||
serve:
|
serve:
|
||||||
npm run serve
|
npm run serve
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -r dist
|
||||||
|
2
web/package-lock.json
generated
2
web/package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hff-entry-form-web",
|
"name": "hff-entry-form-web",
|
||||||
"version": "0.2.3",
|
"version": "0.3.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hff-entry-form-web",
|
"name": "hff-entry-form-web",
|
||||||
"version": "0.2.3",
|
"version": "0.3.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "npx servor dist",
|
"serve": "npx servor dist",
|
||||||
|
Reference in New Issue
Block a user