Skip to content

Commit

Permalink
post transaction endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
altitude committed Jun 18, 2021
1 parent 757bc52 commit d779025
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
10 changes: 8 additions & 2 deletions api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/gin-gonic/gin"
"go.uber.org/fx"
"numary.io/ledger/core"
"numary.io/ledger/ledger"
"numary.io/ledger/ledger/query"
)
Expand Down Expand Up @@ -46,8 +47,13 @@ func NewHttpAPI(lc fx.Lifecycle, l *ledger.Ledger) *HttpAPI {
})

r.POST("/transactions", func(c *gin.Context) {
c.JSON(200, gin.H{
"ok": true,
var t core.Transaction
c.ShouldBind(&t)

err := l.Commit(t)

c.JSON(304, gin.H{
"ok": err != nil,
})
})

Expand Down
42 changes: 36 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ type Config struct {
func DefaultConfig() Config {
c := Config{}

h, err := os.UserHomeDir()

if err != nil {
panic("cannot get home directory")
}

p := path.Join(h, ".numary")

c.Server.Http.BindAddress = "127.0.0.1:3068"
c.Storage.Driver = "sqlite"
c.Storage.SQLiteOpts.DBName = "ledger"
c.Storage.SQLiteOpts.Directory = ".numary"
c.Storage.SQLiteOpts.Directory = path.Join(p, "storage")

return c
}
Expand All @@ -50,13 +58,35 @@ func GetConfig() Config {

h, err := os.UserHomeDir()

if err == nil {
candidates = append(
candidates,
path.Join(h, ".numary", filename),
)
if err != nil {
panic("cannot get home directory")
}

p := path.Join(h, ".numary")

if _, err := os.Stat(p); os.IsNotExist(err) {
err := os.Mkdir(p, 0700)

if err != nil {
panic(err)
}
}

ps := path.Join(p, "storage")

if _, err := os.Stat(ps); os.IsNotExist(err) {
err := os.Mkdir(ps, 0700)

if err != nil {
panic(err)
}
}

candidates = append(
candidates,
path.Join(h, ".numary", filename),
)

found := false
conf := DefaultConfig()

Expand Down

0 comments on commit d779025

Please sign in to comment.