Mercurial > gemma
diff pkg/controllers/printtemplates.go @ 2161:7444b75d5497
Print templates endpoints: Get rid of useless models.PrintTemplateIn model.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 08 Feb 2019 12:56:33 +0100 |
parents | 7bd485bf85e8 |
children | 0627565fb4d2 |
line wrap: on
line diff
--- a/pkg/controllers/printtemplates.go Fri Feb 08 12:51:20 2019 +0100 +++ b/pkg/controllers/printtemplates.go Fri Feb 08 12:56:33 2019 +0100 @@ -16,6 +16,7 @@ import ( "bytes" "database/sql" + "encoding/json" "net/http" "time" @@ -122,16 +123,17 @@ ) (jr JSONResult, err error) { ctx := req.Context() - in := input.(*models.PrintTemplateIn) + name := mux.Vars(req)["name"] + in := input.(*json.RawMessage) - if in.Name == "" { + if name == "" { err = JSONError{ Code: http.StatusBadRequest, Message: "Template must have a none empty name", } return } - if len(in.Template) == 0 { + if len(*in) == 0 { err = JSONError{ Code: http.StatusBadRequest, Message: "Template must have a none empty template", @@ -145,7 +147,7 @@ defer tx.Rollback() var dummy bool - err = tx.QueryRowContext(ctx, hasPrintTemplateSQL, in.Name).Scan(&dummy) + err = tx.QueryRowContext(ctx, hasPrintTemplateSQL, name).Scan(&dummy) switch { case err == sql.ErrNoRows: @@ -159,9 +161,9 @@ } return } - data := pgtype.Bytea{Bytes: in.Template, Status: pgtype.Present} + data := pgtype.Bytea{Bytes: *in, Status: pgtype.Present} - if _, err = tx.ExecContext(ctx, insertPrintTemplateSQL, in.Name, &data); err != nil { + if _, err = tx.ExecContext(ctx, insertPrintTemplateSQL, name, &data); err != nil { return } @@ -171,7 +173,7 @@ jr = JSONResult{ Code: http.StatusCreated, Result: map[string]string{ - "created": in.Name, + "created": name, }, } return