Skip to content

Commit

Permalink
-feature ✨ add 3 layers of cockroach
Browse files Browse the repository at this point in the history
  • Loading branch information
RuangyotN committed Nov 24, 2023
1 parent 1c7e5dd commit be6e61d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cockroach/handlers/cockroachHttpHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ type cockroachHttpHandler struct {
cockroachUsecase usecases.CockroachUsecase
}

func NewCockroachHttpHandler(cockroachUsecase usecases.CockroachUsecase) CockroachHandler {
return &cockroachHttpHandler{
cockroachUsecase: cockroachUsecase,
}
}

func (h *cockroachHttpHandler) DetectCockroach(c echo.Context) error {
return nil
}
4 changes: 4 additions & 0 deletions cockroach/repositories/cockroachFCM.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (

type cockroachFCMMessaging struct{}

func NewCockroachFCMMessaging() CockroachMessaging {
return &cockroachFCMMessaging{}
}

func (c *cockroachFCMMessaging) PushNotification(m entities.CockroachPushNotificationDto) error {
// ... handle logic to push FCM notification here ...
log.Info("Pushing notification to FCM")
Expand Down
4 changes: 4 additions & 0 deletions cockroach/repositories/cockroachPostgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ type cockroachPostgresRepository struct {
db *gorm.DB
}

func NewCockroachPostgresRepository(db *gorm.DB) CockroachRepository {
return &cockroachPostgresRepository{db: db}
}

func (r *cockroachPostgresRepository) InsertCockroachData(
in entities.InsertCockroachDto,
) error {
Expand Down
25 changes: 21 additions & 4 deletions server/echoServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package server

import (
"fmt"
"net/http"

"github.com/Rayato159/go-clean-arch-v2/cockroach/handlers"
cockroachRepositories "github.com/Rayato159/go-clean-arch-v2/cockroach/repositories"
cockroachUsecases "github.com/Rayato159/go-clean-arch-v2/cockroach/usecases"
"github.com/Rayato159/go-clean-arch-v2/config"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
Expand All @@ -24,10 +26,25 @@ func NewEchoServer(cfg *config.Config, db *gorm.DB) Server {
}

func (s *echoServer) Start() {
s.app.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
s.initializeCockroachHttpHandler()

serverUrl := fmt.Sprintf(":%d", s.cfg.App.Port)
s.app.Logger.Fatal(s.app.Start(serverUrl))
}

func (s *echoServer) initializeCockroachHttpHandler() {
// Initialize all layers
cockroachPostgresRepository := cockroachRepositories.NewCockroachPostgresRepository(s.db)
cockroachFCMMessaging := cockroachRepositories.NewCockroachFCMMessaging()

cockroachUsecase := cockroachUsecases.NewCockroachUsecaseImpl(
cockroachPostgresRepository,
cockroachFCMMessaging,
)

cockroachHttpHandler := handlers.NewCockroachHttpHandler(cockroachUsecase)

// Routers
cockroachRouters := s.app.Group("/cockroach")
cockroachRouters.POST("/", cockroachHttpHandler.DetectCockroach)
}

0 comments on commit be6e61d

Please sign in to comment.