Skip to content

Commit

Permalink
setting api server and createAccount func
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiraj-ku committed Aug 14, 2024
1 parent 4e121fa commit fded941
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
15 changes: 15 additions & 0 deletions api/account.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
db "example/laxmi_chit_fund/db/sqlc"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -22,4 +23,18 @@ func (server *Server) createAccount(ctx *gin.Context) {

// Create the account after validating the input

arg := db.CreateAccountParams{
Owner: req.Owner,
Currency: req.Currency,
Balance: 0,
}

account, err := server.store.CreateAccount(ctx, arg)

if err != nil {
ctx.JSON(http.StatusInternalServerError, errorResponse(err))
return
}
ctx.JSON(http.StatusOK, account)

}
11 changes: 7 additions & 4 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ package api

import (
db "example/laxmi_chit_fund/db/sqlc"
"example/laxmi_chit_fund/utils"

"github.com/gin-gonic/gin"
)

type Server struct {
config utils.Config
store db.Store
router *gin.Engine
}

// func NewServer(store *db.Store) *Server{
func NewServer(store *db.Store) *Server {
server := &Server{store: store}
router := gin.Default(),

// }
router.POST("/accounts", server.createAccount)
server.router = router
return server
}

// Setup Gin Router to handle all the incoming API routes

Expand Down
2 changes: 2 additions & 0 deletions db/sqlc/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Store interface {
TransferTx(ctx context.Context, arg TransferTxParams) (TransferTxResult, error)
CreateUserTx(ctx context.Context, arg CreateUserTxParams) (CreateUserTxResult, error)
VerifyEmailTx(ctx context.Context, arg VerifyEmailTxParams) (VerifyEmailTxResult, error)
CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) // Add this line

}

// SQLStore provides all functions to execute SQL queries and transactions
Expand Down
8 changes: 8 additions & 0 deletions utils/test.go
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
package utils

import (
"fmt"
)

func main() {
fmt.Println("Hello, world!")
}

0 comments on commit fded941

Please sign in to comment.