added post request support
This commit is contained in:
parent
a88a18fe0e
commit
8342a8f5f4
2 changed files with 7 additions and 7 deletions
10
api.go
10
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)
|
||||
}
|
||||
|
|
4
main.go
4
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"`
|
||||
|
|
Loading…
Reference in a new issue