roots.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package routes
  2. import (
  3. "github.com/gofiber/fiber/v2"
  4. "github.com/gofiber/fiber/v2/middleware/cors"
  5. jwtware "github.com/gofiber/jwt/v3"
  6. "notabug.org/alimiracle/my-website-api/handlers"
  7. )
  8. func SetupRoutes(app *fiber.App) {
  9. handler := handlers.Init()
  10. api := app.Group("/api")
  11. app.Use(cors.New())
  12. api.Get("/projects", handler.GetAllProjects)
  13. api.Get("/skills", handler.GetAllSkills)
  14. api.Get("/jobs", handler.GetAllJobs)
  15. api.Get("/contacts", handler.GetAllContacts)
  16. api.Get("/users", handler.GetAllUsers)
  17. api.Post("/login", handler.Login)
  18. // JWT Middleware
  19. app.Use(jwtware.New(jwtware.Config{
  20. SigningKey: []byte("secret"),
  21. }))
  22. api.Post("/projects", handler.AddProject)
  23. api.Post("/skills", handler.AddSkill)
  24. api.Post("/jobs", handler.AddJob)
  25. api.Post("/users", handler.AddUser)
  26. api.Put("/projects/:id", handler.UpdateProject)
  27. api.Put("/skills/:id", handler.UpdateSkill)
  28. api.Put("/jobs/:id", handler.UpdateJob)
  29. api.Put("/contacts/:id", handler.UpdateContact)
  30. api.Put("/users/:id", handler.UpdateUser)
  31. api.Delete("/projects/:id", handler.DeleteProject)
  32. api.Delete("/jobs/:id", handler.DeleteJob)
  33. api.Delete("/skills/:id", handler.DeleteSkill)
  34. api.Delete("/contacts/:id", handler.DeleteContact)
  35. api.Delete("/users/:id", handler.DeleteUser)
  36. }