Skip to content
Snippets Groups Projects
rootmux.go 2.16 KiB
Newer Older
  • Learn to ignore specific revisions
  • Rémi PAILHAREY's avatar
    Rémi PAILHAREY committed
    package rootmux
    
    import (
    	"net/http"
    
    	_ "forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/docs"
    
    	"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/auth"
    
    	"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/monthlyNews"
    
    	"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/poll"
    
    	"github.com/gorilla/mux"
    
    	httpSwagger "github.com/swaggo/http-swagger"
    
    Rémi PAILHAREY's avatar
    Rémi PAILHAREY committed
    )
    
    
    type RootMux struct {
    
    	Router  *mux.Router
    
    	Manager *auth.Manager
    }
    
    
    // @title Backoffice API
    // @version 1.0
    // @description This is a sample service for managing newsletters for Ecolyo
    // @termsOfService http://swagger.io/terms/
    // @contact.name API Support
    // @contact.email rpailharey@grandlyon.com
    // @host localhost:1443
    // @BasePath /
    
    
    func CreateRootMux(staticDir string) RootMux {
    
    
    	r := mux.NewRouter()
    
    	m := auth.NewManager()
    
    	r.HandleFunc("/OAuth2Login", m.HandleOAuth2Login)
    	r.Handle("/OAuth2Callback", m.HandleOAuth2Callback())
    	r.HandleFunc("/Logout", m.HandleLogout)
    	r.Handle("/api/common/WhoAmI", auth.ValidateAuthMiddleware(auth.WhoAmI(), []string{"*"}, false))
    
    	apiAdmin := r.PathPrefix("/api/admin").Subrouter()
    	apiAdmin.Use(auth.AdminAuthMiddleware)
    
    	apiAdmin.HandleFunc("/monthlyNews", monthlyNews.GetAllMonthlyNews).Methods(http.MethodGet)
    	apiAdmin.HandleFunc("/monthlyNews/{year}/{month}", monthlyNews.GetSingleMonthlyNews).Methods(http.MethodGet)
    
    	apiAdmin.HandleFunc("/monthlyNews", monthlyNews.AddMonthlyNews).Methods(http.MethodPost)
    
    	apiAdmin.HandleFunc("/monthlyNews", monthlyNews.UpdateMonthlyNews).Methods(http.MethodPut)
    
    	apiAdmin.HandleFunc("/monthlyNews/{year}/{month}", monthlyNews.DeleteMonthlyNews).Methods(http.MethodDelete)
    
    
    	apiAdmin.HandleFunc("/poll", poll.GetAllPolls).Methods(http.MethodGet)
    	apiAdmin.HandleFunc("/poll/{year}/{month}", poll.GetSinglePoll).Methods(http.MethodGet)
    	apiAdmin.HandleFunc("/poll", poll.AddPoll).Methods(http.MethodPost)
    	apiAdmin.HandleFunc("/poll", poll.UpdatePoll).Methods(http.MethodPut)
    	apiAdmin.HandleFunc("/poll/{year}/{month}", poll.DeletePoll).Methods(http.MethodDelete)
    
    
    	// Swagger
    	r.PathPrefix("/swagger").Handler(httpSwagger.WrapHandler)
    
    
    	return RootMux{r, &m}
    
    Rémi PAILHAREY's avatar
    Rémi PAILHAREY committed
    }