Skip to content
Permalink
Browse files

fix setupBoard minor issues.

  • Loading branch information...
fiatjaf committed Jul 24, 2018
1 parent 35f3e63 commit b51e8258a1de1291fd52942e306d0ddf7e4d7d72
Showing with 15 additions and 7 deletions.
  1. +9 −5 methods.go
  2. +6 −2 postgres.sql
@@ -1,6 +1,8 @@
package main

import "errors"
import (
"errors"
)

func setupBoard(boardId, userId, email, token string, enabled bool) (err error) {
trello := makeTrelloClient(token)
@@ -30,11 +32,13 @@ func setupBoard(boardId, userId, email, token string, enabled bool) (err error)
proceed:
if enabled {
// create board webhook
var webhook Value
var webhook struct {
Id string `json:"id"`
}
err = trello("put", "/1/webhooks", struct {
CallbackURL string `json:"callbackURL"`
IdModel string `json:"idModel"`
}{s.Host + "/_/webhooks/board", boardId}, webhook)
}{s.Host + "/_/webhooks/board", boardId}, &webhook)
if err != nil {
log.Warn().Err(err).Str("board", boardId).
Msg("failed to create board webhook")
@@ -45,7 +49,7 @@ proceed:
_, err = pg.Exec(`
INSERT INTO boards (id, token, email, webhook_id)
VALUES ($1, $2, $3, $4)
`, boardId, token, email, webhook.Value)
`, boardId, token, email, webhook.Id)
if err != nil {
log.Warn().Err(err).Str("board", boardId).
Msg("failed to set board")
@@ -63,7 +67,7 @@ WITH
wd AS (
SELECT webhook_id, token FROM boards
WHERE id = $1
)
),
del AS (
DELETE FROM boards WHERE id = $1
)
@@ -4,15 +4,19 @@ CREATE TABLE boards (
email text NOT NULL,
webhook_id text NOT NULL,

CHECK (id != '')
CHECK (id != ''),
CHECK (token != ''),
CHECK (email != ''),
CHECK (webhook_id != '')
);

CREATE TABLE backups (
id text PRIMARY KEY,
board text,
data jsonb NOT NULL,

CHECK (id != '')
CHECK (id != ''),
CHECK (board != '')
);

table boards;

0 comments on commit b51e825

Please sign in to comment.
You can’t perform that action at this time.