Skip to content

Commit

Permalink
Initial implementation of bank account
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Dec 17, 2023
1 parent e1dfcb8 commit 9435270
Show file tree
Hide file tree
Showing 14 changed files with 1,347 additions and 478 deletions.
19 changes: 19 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@
// integrated client.
package cli

import (
"net/http"

"connectrpc.com/connect"
"github.com/oxisto/money-gopher/gen/portfoliov1connect"
)

// Session holds all necessary information about the current CLI session.
type Session struct {
PortfolioClient portfoliov1connect.PortfolioServiceClient
}

func NewSession() *Session {
var s Session

s.PortfolioClient = portfoliov1connect.NewPortfolioServiceClient(
http.DefaultClient, "http://localhost:8080",
connect.WithHTTPGet(),
)

return &s
}
37 changes: 37 additions & 0 deletions cli/commands/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package commands

import (
"context"
"fmt"

"connectrpc.com/connect"
"github.com/oxisto/money-gopher/cli"
portfoliov1 "github.com/oxisto/money-gopher/gen"
)

type BankAccountCmd struct {
Create CreateBankAccountCmd `cmd:"" help:"Creates a new bank account."`
}

type CreateBankAccountCmd struct {
Name string `help:"The identifier of the portfolio, e.g. mybank/myportfolio" required:""`
DisplayName string `help:"The display name of the portfolio"`
}

func (cmd *CreateBankAccountCmd) Run(s *cli.Session) error {
res, err := s.PortfolioClient.CreatePortfolio(
context.Background(),
connect.NewRequest(&portfoliov1.CreatePortfolioRequest{
Portfolio: &portfoliov1.Portfolio{
Name: cmd.Name,
DisplayName: cmd.DisplayName,
},
}),
)
if err != nil {
return err
}

fmt.Println(res.Msg)
return nil
}
5 changes: 3 additions & 2 deletions cli/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
var CLI struct {
Debug bool `help:"Enable debug mode."`

Security SecurityCmd `cmd:"" help:"Security commands."`
Portfolio PortfolioCmd `cmd:"" help:"Portfolio commands."`
Security SecurityCmd `cmd:"" help:"Security commands."`
Portfolio PortfolioCmd `cmd:"" help:"Portfolio commands."`
BankAccount BankAccountCmd `cmd:"" help:"Bank account commands."`

Completion kongcompletion.Completion `cmd:"" help:"Outputs shell code for initializing tab completions" hidden:"" completion-shell-default:"false"`
}
2 changes: 0 additions & 2 deletions cli/commands/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ func eventTypeFrom(typ string) portfoliov1.PortfolioEventType {
return portfoliov1.PortfolioEventType_PORTFOLIO_EVENT_TYPE_DELIVERY_INBOUND
} else if typ == "delivery-outbound" {
return portfoliov1.PortfolioEventType_PORTFOLIO_EVENT_TYPE_DELIVERY_OUTBOUND
} else if typ == "dividend" {
return portfoliov1.PortfolioEventType_PORTFOLIO_EVENT_TYPE_DIVIDEND
}

return portfoliov1.PortfolioEventType_PORTFOLIO_EVENT_TYPE_UNSPECIFIED
Expand Down
2 changes: 1 addition & 1 deletion cmd/mgo/mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ func main() {
ctx, err := parser.Parse(os.Args[1:])
parser.FatalIfErrorf(err)

err = ctx.Run(&cli.Session{})
err = ctx.Run(cli.NewSession())
parser.FatalIfErrorf(err)
}
Loading

0 comments on commit 9435270

Please sign in to comment.