completed go backend
This commit is contained in:
@@ -1,32 +1,72 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"actatempus_backend/internal/application/services"
|
||||
"actatempus_backend/internal/infrastructure/config"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
cfg *config.Config
|
||||
cfg *config.Config
|
||||
userService *services.UserService
|
||||
projectService *services.ProjectService
|
||||
projectTaskService *services.ProjectTaskService
|
||||
timeEntryService *services.TimeEntryService
|
||||
}
|
||||
|
||||
func NewServer(cfg *config.Config) *Server {
|
||||
return &Server{cfg: cfg}
|
||||
// NewServer initializes the Server with its dependencies.
|
||||
func NewServer(
|
||||
cfg *config.Config,
|
||||
userService *services.UserService,
|
||||
projectService *services.ProjectService,
|
||||
projectTaskService *services.ProjectTaskService,
|
||||
timeEntryService *services.TimeEntryService,
|
||||
) *Server {
|
||||
return &Server{
|
||||
cfg: cfg,
|
||||
userService: userService,
|
||||
projectService: projectService,
|
||||
projectTaskService: projectTaskService,
|
||||
timeEntryService: timeEntryService,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "Welcome to ActaTempus!")
|
||||
r := gin.Default()
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "Welcome to ActaTempus!",
|
||||
})
|
||||
})
|
||||
// Health Check
|
||||
r.GET("/health", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "Server is running",
|
||||
})
|
||||
})
|
||||
|
||||
r := gin.Default()
|
||||
r.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
// Register Service Routes
|
||||
api := r.Group("/api")
|
||||
{
|
||||
userRouter := api.Group("/users")
|
||||
s.userService.RegisterRoutes(userRouter)
|
||||
|
||||
return r.Run()
|
||||
projectRouter := api.Group("/projects")
|
||||
s.projectService.RegisterRoutes(projectRouter)
|
||||
|
||||
projectTaskRouter := api.Group("/project-tasks")
|
||||
s.projectTaskService.RegisterRoutes(projectTaskRouter)
|
||||
|
||||
timeEntryRouter := api.Group("/time-entries")
|
||||
s.timeEntryService.RegisterRoutes(timeEntryRouter)
|
||||
}
|
||||
|
||||
port := s.cfg.Port
|
||||
if !strings.HasPrefix(port, ":") {
|
||||
port = ":" + port // Add the colon if it's missing
|
||||
}
|
||||
return r.Run(port) // Start the server on the configured port
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user