Update: Few issues to resolve see readme
this push will conclude the majority of pulls. this repos will now, not be actively be managed or any further code pushes will not be frequent.
This commit is contained in:
65
app/main.go
65
app/main.go
@@ -16,35 +16,6 @@ import (
|
||||
_ "github.com/lib/pq" // use PostgreSQL
|
||||
)
|
||||
|
||||
// Helper function to determine navigation visibility based on role
|
||||
func getNavFlags(role int) (bool, bool, bool) {
|
||||
showAdminNav := role == 1 // Admin role
|
||||
showLeaderNav := role == 2 // Team Leader role
|
||||
showVolunteerNav := role == 3 // Volunteer role
|
||||
return showAdminNav, showVolunteerNav, showLeaderNav
|
||||
}
|
||||
|
||||
// Helper function to create template data with proper nav flags
|
||||
func createTemplateData(title, activeSection string, role int, isAuthenticated bool, additionalData map[string]interface{}) map[string]interface{} {
|
||||
showAdminNav, showVolunteerNav, _ := getNavFlags(role)
|
||||
|
||||
data := map[string]interface{}{
|
||||
"Title": title,
|
||||
"IsAuthenticated": isAuthenticated,
|
||||
"Role": role,
|
||||
"ShowAdminNav": showAdminNav,
|
||||
"ShowVolunteerNav": showVolunteerNav,
|
||||
"ActiveSection": activeSection,
|
||||
}
|
||||
|
||||
// Add any additional data
|
||||
for key, value := range additionalData {
|
||||
data[key] = value
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
func authMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
@@ -103,12 +74,6 @@ func volunteerMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||
})
|
||||
}
|
||||
|
||||
func schedualHandler(w http.ResponseWriter, r *http.Request) {
|
||||
role := r.Context().Value("user_role").(int)
|
||||
data := createTemplateData("My Schedule", "schedual", role, true, nil)
|
||||
utils.Render(w, "Schedual/schedual.html", data)
|
||||
}
|
||||
|
||||
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
utils.Render(w, "dashboard.html", map[string]interface{}{
|
||||
"Title": "Admin Dashboard",
|
||||
@@ -116,14 +81,15 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
"ActiveSection": "dashboard",
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
models.InitDB()
|
||||
|
||||
|
||||
models.EmailMessage("hellow")
|
||||
|
||||
// Static file servers
|
||||
fs := http.FileServer(http.Dir("static"))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||
|
||||
|
||||
uploadsFs := http.FileServer(http.Dir("uploads"))
|
||||
http.Handle("/uploads/", http.StripPrefix("/uploads/", uploadsFs))
|
||||
|
||||
@@ -143,31 +109,32 @@ func main() {
|
||||
http.HandleFunc("/dashboard", adminMiddleware(handlers.AdminDashboardHandler))
|
||||
http.HandleFunc("/volunteers", adminMiddleware(handlers.VolunteerHandler))
|
||||
http.HandleFunc("/volunteer/edit", adminMiddleware(handlers.EditVolunteerHandler))
|
||||
|
||||
http.HandleFunc("/team_builder", adminMiddleware(handlers.TeamBuilderHandler))
|
||||
http.HandleFunc("/team_builder/remove_volunteer", adminMiddleware(handlers.RemoveVolunteerHandler))
|
||||
|
||||
http.HandleFunc("/addresses", adminMiddleware(handlers.AddressHandler))
|
||||
http.HandleFunc("/assign_address", adminMiddleware(handlers.AssignAddressHandler))
|
||||
http.HandleFunc("/remove_assigned_address", adminMiddleware(handlers.RemoveAssignedAddressHandler))
|
||||
|
||||
http.HandleFunc("/addresses/upload-csv", adminMiddleware(handlers.CSVUploadHandler))
|
||||
http.HandleFunc("/reports", adminMiddleware(handlers.ReportsHandler))
|
||||
|
||||
http.HandleFunc("/posts", adminMiddleware(handlers.PostsHandler))
|
||||
|
||||
// Assignment management routes (Admin only)
|
||||
// API Routes
|
||||
http.HandleFunc("/api/validated-addresses", handlers.GetValidatedAddressesHandler)
|
||||
http.HandleFunc("/api/validated-addresses/stats", handlers.GetValidatedAddressesStatsHandler)
|
||||
|
||||
http.HandleFunc("/api/validated-addresses/stats", handlers.GetValidatedAddressesStatsHandler)
|
||||
|
||||
//--- Volunteer-only routes
|
||||
//--- Volunteer-only routes
|
||||
http.HandleFunc("/volunteer/dashboard", volunteerMiddleware(handlers.VolunteerPostsHandler))
|
||||
http.HandleFunc("/volunteer/Addresses", volunteerMiddleware(handlers.VolunteerAppointmentHandler))
|
||||
http.HandleFunc("/schedual", volunteerMiddleware(schedualHandler))
|
||||
http.HandleFunc("/volunteer/addresses", volunteerMiddleware(handlers.VolunteerAppointmentHandler))
|
||||
|
||||
// Schedule/Availability routes (Volunteer only)
|
||||
http.HandleFunc("/volunteer/schedule", volunteerMiddleware(handlers.VolunteerGetAvailabilityHandler))
|
||||
http.HandleFunc("/volunteer/schedule/post", volunteerMiddleware(handlers.VolunteerPostScheduleHandler))
|
||||
http.HandleFunc("/volunteer/schedule/delete", volunteerMiddleware(handlers.VolunteerDeleteScheduleHandler))
|
||||
|
||||
// Poll routes (volunteer only)
|
||||
http.HandleFunc("/poll", volunteerMiddleware(handlers.PollHandler))
|
||||
|
||||
|
||||
log.Println("Server started on http://localhost:8080")
|
||||
log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user