added post request support

This commit is contained in:
Nickiel12 2023-12-30 14:10:41 -08:00
parent a88a18fe0e
commit 8342a8f5f4
2 changed files with 7 additions and 7 deletions

10
api.go
View file

@ -3,7 +3,6 @@ package main
import ( import (
"net/http" "net/http"
"encoding/json" "encoding/json"
//"io/ioutil"
//"context" //"context"
"fmt" "fmt"
@ -65,11 +64,12 @@ func getTransactions(w http.ResponseWriter, req *http.Request) {
} }
func newTransaction(w http.ResponseWriter, req *http.Request) { func newTransaction(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "ding") decoder := json.NewDecoder(req.Body)
/* var t Transaction
body, err := ioutil.ReadAll(req.Body) err := decoder.Decode(&t)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
*/ fmt.Fprintf(w, "New transaction created for Account: %d, with an Amount of: %s",
t.Account, t.Amount)
} }

View file

@ -8,7 +8,7 @@ import (
"log" "log"
"time" "time"
"github.com/shopspring/decimal" //"github.com/shopspring/decimal"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware" "github.com/go-chi/chi/v5/middleware"
) )
@ -17,7 +17,7 @@ import (
// if you use `json:"-"` it doesn't encode it // if you use `json:"-"` it doesn't encode it
type Transaction struct { type Transaction struct {
Id int `db:"trns_id" json:"Id"` 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"` Description sql.NullString `db:"trns_description" json:"Description"`
Account int `db:"trns_account" json:"Account"` Account int `db:"trns_account" json:"Account"`
Bucket sql.NullInt64 `db:"trns_bucket" json:"Bucket"` Bucket sql.NullInt64 `db:"trns_bucket" json:"Bucket"`