From 8342a8f5f479352000e91833ffedd1fb759a2945 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sat, 30 Dec 2023 14:10:41 -0800 Subject: [PATCH] added post request support --- api.go | 10 +++++----- main.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api.go b/api.go index 16c73a4..24ec9c1 100644 --- a/api.go +++ b/api.go @@ -3,7 +3,6 @@ package main import ( "net/http" "encoding/json" - //"io/ioutil" //"context" "fmt" @@ -65,11 +64,12 @@ func getTransactions(w http.ResponseWriter, req *http.Request) { } func newTransaction(w http.ResponseWriter, req *http.Request) { - fmt.Fprintf(w, "ding") - /* - body, err := ioutil.ReadAll(req.Body) + decoder := json.NewDecoder(req.Body) + var t Transaction + err := decoder.Decode(&t) if err != nil { log.Fatal(err) } - */ + fmt.Fprintf(w, "New transaction created for Account: %d, with an Amount of: %s", + t.Account, t.Amount) } diff --git a/main.go b/main.go index 4313d3f..9494fc1 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "log" "time" - "github.com/shopspring/decimal" + //"github.com/shopspring/decimal" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) @@ -17,7 +17,7 @@ import ( // if you use `json:"-"` it doesn't encode it type Transaction struct { Id int `db:"trns_id" json:"Id"` - Amount decimal.Decimal `db:"trns_amount" json:"Amount"` + Amount string `db:"trns_amount" json:"Amount"` Description sql.NullString `db:"trns_description" json:"Description"` Account int `db:"trns_account" json:"Account"` Bucket sql.NullInt64 `db:"trns_bucket" json:"Bucket"`