Skip to content

Commit

Permalink
feat: add validate token in routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Moraes committed Oct 13, 2023
1 parent 8829120 commit 433ae58
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
36 changes: 36 additions & 0 deletions api/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

db "github.com/dlmoraes/gofinance-backend/db/sqlc"
"github.com/dlmoraes/gofinance-backend/util"
"github.com/gin-gonic/gin"
)

Expand All @@ -20,6 +21,11 @@ type createAccountRequest struct {
}

func (server *Server) createAccount(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req createAccountRequest
err := ctx.ShouldBindJSON(&req)
if err != nil {
Expand Down Expand Up @@ -65,6 +71,11 @@ type getAccountRequest struct {
}

func (server *Server) getAccount(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req getAccountRequest
err := ctx.ShouldBindUri(&req)
if err != nil {
Expand All @@ -90,6 +101,11 @@ type deleteAccountRequest struct {
}

func (server *Server) deleteAccount(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req getAccountRequest
err := ctx.ShouldBindUri(&req)
if err != nil {
Expand Down Expand Up @@ -118,6 +134,11 @@ type updateAccountRequest struct {
}

func (server *Server) updateAccount(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req updateAccountRequest
err := ctx.ShouldBindJSON(&req)
if err != nil {
Expand Down Expand Up @@ -150,6 +171,11 @@ type getAccountsRequest struct {
}

func (server *Server) getAccounts(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req getAccountsRequest
err := ctx.ShouldBindJSON(&req)

Expand Down Expand Up @@ -182,6 +208,11 @@ type getAccountsGraphRequest struct {
}

func (server *Server) getAccountGraph(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req getAccountsGraphRequest
err := ctx.ShouldBindUri(&req)
if err != nil {
Expand All @@ -208,6 +239,11 @@ type getAccountsReportsRequest struct {
}

func (server *Server) getAccountsReports(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req getAccountsReportsRequest
err := ctx.ShouldBindUri(&req)
if err != nil {
Expand Down
26 changes: 26 additions & 0 deletions api/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

db "github.com/dlmoraes/gofinance-backend/db/sqlc"
"github.com/dlmoraes/gofinance-backend/util"
"github.com/gin-gonic/gin"
)

Expand All @@ -16,6 +17,11 @@ type createCategoryRequest struct {
}

func (server *Server) createCategory(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req createCategoryRequest
err := ctx.ShouldBindJSON(&req)
if err != nil {
Expand Down Expand Up @@ -43,6 +49,11 @@ type getCategoryRequest struct {
}

func (server *Server) getCategory(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req getCategoryRequest
err := ctx.ShouldBindUri(&req)
if err != nil {
Expand All @@ -68,6 +79,11 @@ type deleteCategoryRequest struct {
}

func (server *Server) deleteCategory(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req getCategoryRequest
err := ctx.ShouldBindUri(&req)
if err != nil {
Expand Down Expand Up @@ -95,6 +111,11 @@ type updateCategoryRequest struct {
}

func (server *Server) updateCategory(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req updateCategoryRequest
err := ctx.ShouldBindJSON(&req)
if err != nil {
Expand Down Expand Up @@ -124,6 +145,11 @@ type getCategoriesRequest struct {
}

func (server *Server) getCategories(ctx *gin.Context) {
errOnValidateToken := util.GetTokenInHeaderAndVerify(ctx)
if errOnValidateToken != nil {
return
}

var req getCategoriesRequest
err := ctx.ShouldBindJSON(&req)
if err != nil {
Expand Down

0 comments on commit 433ae58

Please sign in to comment.