deploy api and make ids unique
This commit is contained in:
parent
0dd81e68d4
commit
84fcab202f
|
@ -1,2 +1,3 @@
|
|||
*.db
|
||||
emdb
|
||||
emdb
|
||||
emdb-api
|
7
Makefile
7
Makefile
|
@ -1,6 +1,9 @@
|
|||
|
||||
run-server:
|
||||
run-api:
|
||||
go run ./cmd/api-service/service.go -apikey localOnly
|
||||
|
||||
run-tui:
|
||||
go run ./cmd/terminal-client/main.go
|
||||
go run ./cmd/terminal-client/main.go
|
||||
|
||||
build-api:
|
||||
go build -o emdb-api ./cmd/api-service/service.go
|
|
@ -1,49 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"ewintr.nl/emdb/movie"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
apiKey string
|
||||
url string
|
||||
c *http.Client
|
||||
}
|
||||
|
||||
func New(url, apiKey string) *Client {
|
||||
return &Client{
|
||||
apiKey: apiKey,
|
||||
url: url,
|
||||
c: &http.Client{Timeout: 10 * time.Second},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Store(m *movie.Movie) error {
|
||||
url := fmt.Sprintf("%s/movie/%s", c.url, m.ID)
|
||||
bodyJSON, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
body := bytes.NewBuffer(bodyJSON)
|
||||
req, err := http.NewRequest(http.MethodPut, url, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Authorization", c.apiKey)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := c.c.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -29,6 +29,25 @@ var sqliteMigrations = []sqliteMigration{
|
|||
`INSERT INTO system (latest_sync) VALUES (0)`,
|
||||
`ALTER TABLE movie ADD COLUMN tmdb_id INTEGER NOT NULL DEFAULT 0`,
|
||||
`ALTER TABLE movie ADD COLUMN summary TEXT NOT NULL DEFAULT ""`,
|
||||
`BEGIN TRANSACTION;
|
||||
CREATE TABLE movie_new (
|
||||
"id" TEXT UNIQUE NOT NULL,
|
||||
"imdb_id" TEXT UNIQUE NOT NULL DEFAULT "",
|
||||
"tmdb_id" INTEGER UNIQUE NOT NULL DEFAULT 0,
|
||||
"title" TEXT NOT NULL DEFAULT "",
|
||||
"english_title" TEXT NOT NULL DEFAULT "",
|
||||
"year" INTEGER NOT NULL DEFAULT 0,
|
||||
"directors" TEXT NOT NULL DEFAULT "",
|
||||
"summary" TEXT NOT NULL DEFAULT "",
|
||||
"watched_on" TEXT NOT NULL DEFAULT "",
|
||||
"rating" INTEGER NOT NULL DEFAULT 0,
|
||||
"comment" TEXT NOT NULL DEFAULT ""
|
||||
);
|
||||
INSERT INTO movie_new (id, imdb_id, tmdb_id, title, english_title, year, directors, summary, watched_on, rating, comment)
|
||||
SELECT id, imdb_id, tmdb_id, title, english_title, year, directors, summary, watched_on, rating, comment FROM movie;
|
||||
DROP TABLE movie;
|
||||
ALTER TABLE movie_new RENAME TO movie;
|
||||
COMMIT`,
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
Loading…
Reference in New Issue