feat: Add authentication DTOs and setup API routes for user and activity management
This commit is contained in:
+31
-16
@@ -9,47 +9,62 @@ import (
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
_ "github.com/timetracker/backend/docs" // This line is important for swag to work
|
||||
"github.com/timetracker/backend/internal/api/routes"
|
||||
"github.com/timetracker/backend/internal/models"
|
||||
_ "gorm.io/driver/postgres"
|
||||
// GORM IMPORTS MARKER
|
||||
)
|
||||
|
||||
// @title Time Tracker API
|
||||
// @version 1.0
|
||||
// @description This is a simple time tracker API.
|
||||
// @host localhost:8080
|
||||
// @BasePath /
|
||||
// @title Time Tracker API
|
||||
// @version 1.0
|
||||
// @description This is a simple time tracker API.
|
||||
// @host localhost:8080
|
||||
// @BasePath /api
|
||||
// @securityDefinitions.apikey BearerAuth
|
||||
// @in header
|
||||
// @name Authorization
|
||||
|
||||
// @Summary Say hello
|
||||
// @Description Get a hello message
|
||||
// @ID hello
|
||||
// @Produce plain
|
||||
// @Success 200 {string} string "Hello from the Time Tracker Backend!"
|
||||
// @Router / [get]
|
||||
// @x-extension ulid.ULID string
|
||||
|
||||
// @Summary Say hello
|
||||
// @Description Get a hello message
|
||||
// @ID hello
|
||||
// @Produce plain
|
||||
// @Success 200 {string} string "Hello from the Time Tracker Backend!"
|
||||
// @Router / [get]
|
||||
func helloHandler(c *gin.Context) {
|
||||
c.String(http.StatusOK, "Hello from the Time Tracker Backend!")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// Configure database
|
||||
dbConfig := models.DatabaseConfig{
|
||||
Host: "localhost",
|
||||
Port: 5432,
|
||||
User: "postgres",
|
||||
Password: "password",
|
||||
DBName: "mydatabase",
|
||||
SSLMode: "disable", // Für Entwicklungsumgebung
|
||||
SSLMode: "disable", // For development environment
|
||||
}
|
||||
|
||||
// Datenbank initialisieren
|
||||
// Initialize database
|
||||
if err := models.InitDB(dbConfig); err != nil {
|
||||
log.Fatalf("Fehler bei der DB-Initialisierung: %v", err)
|
||||
log.Fatalf("Error initializing database: %v", err)
|
||||
}
|
||||
|
||||
// Create Gin router
|
||||
r := gin.Default()
|
||||
|
||||
// Basic route for health check
|
||||
r.GET("/", helloHandler)
|
||||
|
||||
// Setup API routes
|
||||
routes.SetupRouter(r)
|
||||
|
||||
// Swagger documentation
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
// Start server
|
||||
fmt.Println("Server listening on port 8080")
|
||||
r.Run(":8080") // Use Gin's Run method
|
||||
r.Run(":8080")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user