Skip to content

Commit 6f1cf72

Browse files
author
Kai Hendry
committed
Inserting like invite
1 parent 71a06f9 commit 6f1cf72

File tree

7 files changed

+91
-64
lines changed

7 files changed

+91
-64
lines changed

Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
dev:
22
@echo $$AWS_ACCESS_KEY_ID
3-
jq '.profile |= "uneet-dev" |.stages.staging |= (.domain = "unit.dev.unee-t.com" | .zone = "dev.unee-t.com")' up.json.in > up.json
4-
up
3+
jq '.profile |= "uneet-dev" |.stages.production |= (.domain = "unit.dev.unee-t.com" | .zone = "dev.unee-t.com")| .actions[0].emails |= ["[email protected]"]' up.json.in > up.json
4+
up deploy production
55

66
demo:
77
@echo $$AWS_ACCESS_KEY_ID
8-
jq '.profile |= "uneet-demo" |.stages.staging |= (.domain = "unit.demo.unee-t.com" | .zone = "demo.unee-t.com")' up.json.in > up.json
9-
up
8+
jq '.profile |= "uneet-demo" |.stages.production |= (.domain = "unit.demo.unee-t.com" | .zone = "demo.unee-t.com") | .actions[0].emails |= ["[email protected]"]' up.json.in > up.json
9+
up deploy production
1010

1111
prod:
1212
@echo $$AWS_ACCESS_KEY_ID
13-
jq '.profile |= "uneet-prod" |.stages.staging |= (.domain = "unit.unee-t.com" | .zone = "unee-t.com")' up.json.in > up.json
14-
up
13+
jq '.profile |= "uneet-prod" |.stages.production |= (.domain = "unit.unee-t.com" | .zone = "unee-t.com")| .actions[0].emails |= ["[email protected]"]' up.json.in > up.json
14+
up deploy production
1515

16+
testlocal:
17+
curl -i -H "Authorization: Bearer $(shell aws --profile uneet-dev ssm get-parameters --names API_ACCESS_TOKEN --with-decryption --query Parameters[0].Value --output text)" -X POST -d @tests/sample.json http://localhost:3000/create
1618

1719
.PHONY: dev demo prod

README.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1 @@
1-
# Different environments
2-
3-
This is codified over at: https://github.com/unee-t/env
4-
5-
## dev environment
6-
7-
* AWS account id: 812644853088
8-
* profile: uneet-dev
9-
* https://unit.dev.unee-t.com
10-
11-
## demo environment
12-
13-
* AWS account id: 915001051872
14-
* profile: uneet-demo
15-
* https://unit.demo.unee-t.com
16-
17-
## prod environment
18-
19-
* AWS account id: 192458993663
20-
* profile: uneet-prod
21-
* https://unit.unee-t.com
1+
Please view documentation in Postman under the folder Unit.

goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ dockers:
1212

1313
archive:
1414
files:
15-
- sql/
15+
- sql/*

main.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ type handler struct {
3131
}
3232

3333
type unit struct {
34-
MefeUnitID sql.NullString `json:"mefe_unit_id"` // mefe_unit_id
35-
MefeCreatorUserID sql.NullString `json:"mefe_creator_user_id"` // mefe_creator_user_id
36-
BzfeCreatorUserID int `json:"bzfe_creator_user_id"` // bzfe_creator_user_id
37-
ClassificationID int16 `json:"classification_id"` // classification_id
38-
UnitName string `json:"unit_name"` // unit_name
39-
UnitDescriptionDetails sql.NullString `json:"unit_description_details"` // unit_description_details
34+
MefeUnitID string `json:"mefe_unit_id"` // mefe_unit_id
35+
MefeCreatorUserID string `json:"mefe_creator_user_id"` // mefe_creator_user_id
36+
BzfeCreatorUserID int `json:"bzfe_creator_user_id"` // bzfe_creator_user_id
37+
ClassificationID int `json:"classification_id"` // classification_id
38+
UnitName string `json:"unit_name"` // unit_name
39+
UnitDescriptionDetails string `json:"unit_description_details"` // unit_description_details
4040
}
4141

4242
func init() {
@@ -49,7 +49,7 @@ func init() {
4949

5050
func (h handler) step1Insert(unit unit) (err error) {
5151
_, err = h.db.Exec(
52-
`INSERT INTO ut_data_to_create_units (mefe_unit_id
52+
`INSERT INTO ut_data_to_create_units (mefe_unit_id,
5353
mefe_creator_user_id,
5454
bzfe_creator_user_id,
5555
classification_id,
@@ -165,7 +165,7 @@ func (h handler) createUnit(w http.ResponseWriter, r *http.Request) {
165165
"unit": unit,
166166
})
167167

168-
if !unit.MefeUnitID.Valid {
168+
if unit.MefeUnitID == "" {
169169
ctx.Error("missing ID")
170170
response.BadRequest(w, "Missing ID")
171171
return
@@ -174,12 +174,13 @@ func (h handler) createUnit(w http.ResponseWriter, r *http.Request) {
174174
err := h.step1Insert(unit)
175175
if err != nil {
176176
ctx.WithError(err).Error("failed to run step1Insert")
177-
http.Error(w, err.Error(), http.StatusBadRequest)
177+
response.BadRequest(w, err.Error())
178+
return
178179
}
179180

180181
ctx.Info("inserted")
181182

182-
err = h.runsql("unit_create_new.sql", unit.MefeUnitID.String)
183+
err = h.runsql("unit_create_new.sql", unit.MefeUnitID)
183184
if err != nil {
184185
ctx.WithError(err).Errorf("unit_create_new.sql failed")
185186
response.BadRequest(w, err.Error())

test.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/sample.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{
2+
"mefe_unit_id": "foobar2",
3+
"mefe_creator_user_id": "user",
4+
"bzfe_creator_user_id": 55,
5+
"classification_id": 12,
6+
"unit_name": "Villa Paridiso",
7+
"unit_description_details": "Up on the hills"
8+
}]

up.json.in

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,66 @@
11
{
2-
"name": "unit",
3-
"profile": "uneet-dev",
4-
"stages": {
5-
"staging": {
6-
"domain": "unit.dev.unee-t.com",
7-
"zone": "dev.unee-t.com"
8-
}
9-
},
10-
"regions": [
11-
"ap-southeast-1"
12-
],
13-
"error_pages": {
14-
"disable": true
15-
},
16-
"lambda": {
17-
"policy": [
18-
{
19-
"Effect": "Allow",
20-
"Resource": "*",
21-
"Action": [
22-
"ssm:GetParameter"
2+
"name": "unit",
3+
"profile": "uneet-dev",
4+
"stages": {
5+
"production": {
6+
"domain": "unit.dev.unee-t.com",
7+
"zone": "dev.unee-t.com"
8+
}
9+
},
10+
"regions": [
11+
"ap-southeast-1"
12+
],
13+
"error_pages": {
14+
"disable": true
15+
},
16+
"lambda": {
17+
"policy": [
18+
{
19+
"Effect": "Allow",
20+
"Resource": "*",
21+
"Action": [
22+
"ssm:GetParameter"
23+
]
24+
}
2325
]
24-
}
26+
},
27+
"actions": [
28+
{
29+
"name": "email.backend",
30+
"type": "email",
31+
"emails": [
32+
33+
]
34+
}
35+
],
36+
"alerts": [
37+
{
38+
"metric": "http.count",
39+
"statistic": "sum",
40+
"threshold": 100,
41+
"action": "email.backend"
42+
},
43+
{
44+
"metric": "http.5xx",
45+
"statistic": "sum",
46+
"threshold": 1,
47+
"period": "1m",
48+
"action": "email.backend"
49+
},
50+
{
51+
"metric": "http.4xx",
52+
"statistic": "sum",
53+
"threshold": 50,
54+
"period": "5m",
55+
"action": "email.backend"
56+
},
57+
{
58+
"namespace": "AWS/ApiGateway",
59+
"metric": "Count",
60+
"statistic": "sum",
61+
"threshold": 500,
62+
"action": "email.backend",
63+
"description": "Note how you can use AWS namespaces and metrics directly if necessary."
64+
}
2565
]
26-
}
2766
}

0 commit comments

Comments
 (0)