Skip to content

Commit

Permalink
feat: move tests and some cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemarlon committed Nov 16, 2024
1 parent 00f7963 commit 55c9d7c
Show file tree
Hide file tree
Showing 16 changed files with 1,502 additions and 1,371 deletions.
128 changes: 0 additions & 128 deletions cmd/dapp/dapp.go

This file was deleted.

64 changes: 64 additions & 0 deletions cmd/dapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,76 @@ package main

import (
"context"
"log"
"log/slog"
"os"

"github.com/rollmelette/rollmelette"
"github.com/tribeshq/tribes/configs"
"github.com/tribeshq/tribes/pkg/router"
)

func NewDApp() *router.Router {
//////////////////////// Setup Database //////////////////////////
db, err := configs.SetupSQlite()
if err != nil {
log.Fatalf("Failed to setup sqlite database: %v", err)
}

//////////////////////// Setup Handlers //////////////////////////
ah, err := NewAdvanceHandlers(db)
if err != nil {
log.Fatalf("Failed to initialize advance handlers from wire: %v", err)
}

ih, err := NewInspectHandlers(db)
if err != nil {
log.Fatalf("Failed to initialize inspect handlers from wire: %v", err)
}

ms, err := NewMiddlewares(db)
if err != nil {
log.Fatalf("Failed to initialize middlewares from wire: %v", err)
}

//////////////////////// Router //////////////////////////
app := router.NewRouter()

//////////////////////// Advance //////////////////////////
app.HandleAdvance("createContract", ms.RBAC.Middleware(ah.ContractAdvanceHandlers.CreateContractHandler, "admin"))
app.HandleAdvance("updateContract", ms.RBAC.Middleware(ah.ContractAdvanceHandlers.UpdateContractHandler, "admin"))
app.HandleAdvance("deleteContract", ms.RBAC.Middleware(ah.ContractAdvanceHandlers.DeleteContractHandler, "admin"))

app.HandleAdvance("createOrder", ah.OrderAdvanceHandlers.CreateOrderHandler)

app.HandleAdvance("createCrowdfunding", ms.TLSN.Middleware(ah.CrowdfundingAdvanceHandlers.CreateCrowdfundingHandler))
app.HandleAdvance("closeCrowdfunding", ah.CrowdfundingAdvanceHandlers.CloseCrowdfundingHandler)
app.HandleAdvance("settleCrowdfunding", ms.RBAC.Middleware(ah.CrowdfundingAdvanceHandlers.SettleCrowdfundingHandler, "creator"))

app.HandleAdvance("withdraw", ah.UserAdvanceHandlers.WithdrawHandler)
app.HandleAdvance("withdrawApp", ms.RBAC.Middleware(ah.UserAdvanceHandlers.WithdrawAppHandler, "admin"))

app.HandleAdvance("createUser", ms.RBAC.Middleware(ah.UserAdvanceHandlers.CreateUserHandler, "admin"))
app.HandleAdvance("deleteUser", ms.RBAC.Middleware(ah.UserAdvanceHandlers.DeleteUserHandler, "admin"))

//////////////////////// Inspect //////////////////////////
app.HandleInspect("crowdfunding", ih.CrowdfundingInspectHandlers.FindAllCrowdfundingsHandler)
app.HandleInspect("crowdfunding/{id}", ih.CrowdfundingInspectHandlers.FindCrowdfundingByIdHandler)

app.HandleInspect("order", ih.OrderInspectHandlers.FindAllOrdersHandler)
app.HandleInspect("order/{id}", ih.OrderInspectHandlers.FindOrderByIdHandler)
app.HandleInspect("order/crowdfunding/{id}", ih.OrderInspectHandlers.FindBisdByCrowdfundingIdHandler)

app.HandleInspect("contract", ih.ContractInspectHandlers.FindAllContractsHandler)
app.HandleInspect("contract/{symbol}", ih.ContractInspectHandlers.FindContractBySymbolHandler)

app.HandleInspect("user", ih.UserInspectHandlers.FindAllUsersHandler)
app.HandleInspect("user/{address}", ih.UserInspectHandlers.FindUserByAddressHandler)
app.HandleInspect("balance/{symbol}/{address}", ih.UserInspectHandlers.BalanceHandler)

return app
}

func main() {
//////////////////////// Setup DApp /////////////////////////
app := NewDApp()
Expand Down
33 changes: 0 additions & 33 deletions cmd/dapp/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ func NewMiddlewares(gormDB *gorm.DB) (*Middlewares, error) {
return nil, nil
}

func NewMiddlewaresMemory(gormDB *gorm.DB) (*Middlewares, error) {
wire.Build(
setUserRepositoryDependency,
setMiddleware,
wire.Struct(new(Middlewares), "*"),
)
return nil, nil
}

func NewAdvanceHandlers(gormDB *gorm.DB) (*AdvanceHandlers, error) {
wire.Build(
setOrderRepositoryDependency,
Expand All @@ -82,18 +73,6 @@ func NewAdvanceHandlers(gormDB *gorm.DB) (*AdvanceHandlers, error) {
return nil, nil
}

func NewAdvanceHandlersMemory(gormDB *gorm.DB) (*AdvanceHandlers, error) {
wire.Build(
setOrderRepositoryDependency,
setUserRepositoryDependency,
setCrowdfundingRepositoryDependency,
setContractRepositoryDependency,
setAdvanceHandlers,
wire.Struct(new(AdvanceHandlers), "*"),
)
return nil, nil
}

func NewInspectHandlers(gormDB *gorm.DB) (*InspectHandlers, error) {
wire.Build(
setOrderRepositoryDependency,
Expand All @@ -106,18 +85,6 @@ func NewInspectHandlers(gormDB *gorm.DB) (*InspectHandlers, error) {
return nil, nil
}

func NewInspectHandlersMemory(gormDB *gorm.DB) (*InspectHandlers, error) {
wire.Build(
setOrderRepositoryDependency,
setUserRepositoryDependency,
setCrowdfundingRepositoryDependency,
setContractRepositoryDependency,
setInspectHandlers,
wire.Struct(new(InspectHandlers), "*"),
)
return nil, nil
}

type Middlewares struct {
TLSN *middleware.TLSNMiddleware
RBAC *middleware.RBACMiddleware
Expand Down
79 changes: 16 additions & 63 deletions cmd/dapp/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 55c9d7c

Please sign in to comment.