lot of new functionalities
This commit is contained in:
47
servers/web/exports/agenda.go
Normal file
47
servers/web/exports/agenda.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package exports
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *Handler) AllAgendaEvents(w http.ResponseWriter, r *http.Request) {
|
||||
result, err := h.applicationHandler.ExportAllAgendaEvents()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to export all agenda events")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := result.ExcelFile.Close(); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to close Excel file")
|
||||
}
|
||||
}()
|
||||
|
||||
h.writeFileResponse(w, "Agenda_Events.xlsx")
|
||||
result.ExcelFile.Write(w)
|
||||
}
|
||||
|
||||
func (h *Handler) SingleAgendaEvent(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
eventID := vars["eventid"]
|
||||
|
||||
result, err := h.applicationHandler.ExportSingleAgendaEvent(eventID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to export single agenda event")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := result.ExcelFile.Close(); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to close Excel file")
|
||||
}
|
||||
}()
|
||||
|
||||
h.writeFileResponse(w, "Event_"+eventID+".xlsx")
|
||||
result.ExcelFile.Write(w)
|
||||
}
|
||||
66
servers/web/exports/fleets.go
Normal file
66
servers/web/exports/fleets.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package exports
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
|
||||
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *Handler) AllFleetBookings(w http.ResponseWriter, r *http.Request) {
|
||||
// Extract filter parameters from query
|
||||
status := r.URL.Query().Get("status")
|
||||
dateStart := r.URL.Query().Get("date_start")
|
||||
dateEnd := r.URL.Query().Get("date_end")
|
||||
|
||||
// Get bookings using the admin stats function (all bookings across all groups)
|
||||
result, err := h.applicationHandler.GetBookingsStats(status, dateStart, dateEnd)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get all vehicle bookings for export")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Convert vehicles map to the format expected by VehicleBookings renderer
|
||||
vehiclesMap := make(map[string]interface{})
|
||||
for k, v := range result.Vehicles {
|
||||
vehiclesMap[k] = v
|
||||
}
|
||||
|
||||
// Convert beneficiaries map to the format expected by VehicleBookings renderer
|
||||
driversMap := make(map[string]interface{})
|
||||
for k, v := range result.BeneficiariesMap {
|
||||
driversMap[k] = v
|
||||
}
|
||||
|
||||
// Render to Excel
|
||||
h.renderer.XLSX.VehicleBookingsAdmin(w, result.Bookings, vehiclesMap, driversMap, result.Groups)
|
||||
}
|
||||
|
||||
func (h *Handler) FleetBookingsInGroup(w http.ResponseWriter, r *http.Request) {
|
||||
// Get current group from context (set by middleware)
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
log.Error().Msg("No group found in context")
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
group := g.(groupsstorage.Group)
|
||||
|
||||
// Extract filter parameters from query
|
||||
status := r.URL.Query().Get("status")
|
||||
dateStart := r.URL.Query().Get("date_start")
|
||||
dateEnd := r.URL.Query().Get("date_end")
|
||||
|
||||
result, err := h.applicationHandler.GetVehiclesManagementBookingsList(r.Context(), group.ID, status, dateStart, dateEnd)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get vehicle bookings for export")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Render to Excel
|
||||
h.renderer.XLSX.VehicleBookings(w, result.Bookings, result.VehiclesMap, result.DriversMap)
|
||||
}
|
||||
|
||||
33
servers/web/exports/handler.go
Normal file
33
servers/web/exports/handler.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package exports
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/core/application"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
config *viper.Viper
|
||||
applicationHandler *application.ApplicationHandler
|
||||
idp *identification.IdentificationProvider
|
||||
renderer *renderer.Renderer
|
||||
}
|
||||
|
||||
func NewHandler(cfg *viper.Viper, applicationHandler *application.ApplicationHandler, idp *identification.IdentificationProvider, renderer *renderer.Renderer) *Handler {
|
||||
return &Handler{
|
||||
config: cfg,
|
||||
applicationHandler: applicationHandler,
|
||||
idp: idp,
|
||||
renderer: renderer,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) writeFileResponse(w http.ResponseWriter, filename string) {
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename="+filename)
|
||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
w.Header().Set("Expires", "0")
|
||||
}
|
||||
99
servers/web/exports/organized-carpool.go
Normal file
99
servers/web/exports/organized-carpool.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package exports
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *Handler) OrganizedCarpoolBookings(w http.ResponseWriter, r *http.Request) {
|
||||
// Parse query parameters
|
||||
var startDate, endDate *time.Time
|
||||
|
||||
if startDateStr := r.URL.Query().Get("start_date"); startDateStr != "" {
|
||||
if parsed, err := time.Parse("2006-01-02", startDateStr); err == nil {
|
||||
startDate = &parsed
|
||||
}
|
||||
}
|
||||
|
||||
if endDateStr := r.URL.Query().Get("end_date"); endDateStr != "" {
|
||||
if parsed, err := time.Parse("2006-01-02", endDateStr); err == nil {
|
||||
endDate = &parsed
|
||||
}
|
||||
}
|
||||
|
||||
status := r.URL.Query().Get("status")
|
||||
driverID := r.URL.Query().Get("driver_id")
|
||||
|
||||
// Parse geography parameters
|
||||
departureGeo := r.URL.Query().Get("departure_geo")
|
||||
destinationGeo := r.URL.Query().Get("destination_geo")
|
||||
passengerAddressGeo := r.URL.Query().Get("passenger_address_geo")
|
||||
|
||||
departureGeoLayer, departureGeoCode := "", ""
|
||||
if departureGeo != "" {
|
||||
parts := strings.SplitN(departureGeo, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
departureGeoLayer, departureGeoCode = parts[0], parts[1]
|
||||
}
|
||||
}
|
||||
destinationGeoLayer, destinationGeoCode := "", ""
|
||||
if destinationGeo != "" {
|
||||
parts := strings.SplitN(destinationGeo, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
destinationGeoLayer, destinationGeoCode = parts[0], parts[1]
|
||||
}
|
||||
}
|
||||
passengerAddressGeoLayer, passengerAddressGeoCode := "", ""
|
||||
if passengerAddressGeo != "" {
|
||||
parts := strings.SplitN(passengerAddressGeo, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
passengerAddressGeoLayer, passengerAddressGeoCode = parts[0], parts[1]
|
||||
}
|
||||
}
|
||||
|
||||
// Get bookings data
|
||||
result, err := h.applicationHandler.GetOrganizedCarpoolBookings(r.Context(), startDate, endDate, status, driverID, departureGeoLayer, departureGeoCode, destinationGeoLayer, destinationGeoCode, passengerAddressGeoLayer, passengerAddressGeoCode)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get organized carpool bookings")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Render to Excel
|
||||
h.renderer.XLSX.OrganizedCarpoolBookings(w, result)
|
||||
}
|
||||
|
||||
func (h *Handler) OrganizedCarpoolDrivers(w http.ResponseWriter, r *http.Request) {
|
||||
// Parse query parameters - same as web page
|
||||
archivedFilter := r.URL.Query().Get("archived") == "true"
|
||||
driverAddressGeo := r.URL.Query().Get("driver_address_geo")
|
||||
|
||||
// Parse driver address geography parameter
|
||||
driverAddressGeoLayer, driverAddressGeoCode := "", ""
|
||||
if driverAddressGeo != "" {
|
||||
parts := strings.SplitN(driverAddressGeo, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
driverAddressGeoLayer, driverAddressGeoCode = parts[0], parts[1]
|
||||
}
|
||||
}
|
||||
|
||||
// Get drivers data through overview (same as web page)
|
||||
result, err := h.applicationHandler.GetOrganizedCarpoolOverview(
|
||||
r.Context(),
|
||||
"", "", "", "", "", "", "", "", "", "", // booking filters (empty)
|
||||
"", "", "", "", "", "", "", "", "", "", // history booking filters (empty)
|
||||
archivedFilter,
|
||||
driverAddressGeoLayer, driverAddressGeoCode,
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get organized carpool drivers")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Render to Excel
|
||||
h.renderer.XLSX.OrganizedCarpoolDrivers(w, result)
|
||||
}
|
||||
99
servers/web/exports/solidarity-transport.go
Normal file
99
servers/web/exports/solidarity-transport.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package exports
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *Handler) SolidarityTransportBookings(w http.ResponseWriter, r *http.Request) {
|
||||
// Parse query parameters
|
||||
var startDate, endDate *time.Time
|
||||
|
||||
if startDateStr := r.URL.Query().Get("start_date"); startDateStr != "" {
|
||||
if parsed, err := time.Parse("2006-01-02", startDateStr); err == nil {
|
||||
startDate = &parsed
|
||||
}
|
||||
}
|
||||
|
||||
if endDateStr := r.URL.Query().Get("end_date"); endDateStr != "" {
|
||||
if parsed, err := time.Parse("2006-01-02", endDateStr); err == nil {
|
||||
endDate = &parsed
|
||||
}
|
||||
}
|
||||
|
||||
status := r.URL.Query().Get("status")
|
||||
driverID := r.URL.Query().Get("driver_id")
|
||||
|
||||
// Parse geography parameters
|
||||
departureGeo := r.URL.Query().Get("departure_geo")
|
||||
destinationGeo := r.URL.Query().Get("destination_geo")
|
||||
passengerAddressGeo := r.URL.Query().Get("passenger_address_geo")
|
||||
|
||||
departureGeoLayer, departureGeoCode := "", ""
|
||||
if departureGeo != "" {
|
||||
parts := strings.SplitN(departureGeo, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
departureGeoLayer, departureGeoCode = parts[0], parts[1]
|
||||
}
|
||||
}
|
||||
destinationGeoLayer, destinationGeoCode := "", ""
|
||||
if destinationGeo != "" {
|
||||
parts := strings.SplitN(destinationGeo, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
destinationGeoLayer, destinationGeoCode = parts[0], parts[1]
|
||||
}
|
||||
}
|
||||
passengerAddressGeoLayer, passengerAddressGeoCode := "", ""
|
||||
if passengerAddressGeo != "" {
|
||||
parts := strings.SplitN(passengerAddressGeo, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
passengerAddressGeoLayer, passengerAddressGeoCode = parts[0], parts[1]
|
||||
}
|
||||
}
|
||||
|
||||
// Get bookings data
|
||||
result, err := h.applicationHandler.GetSolidarityTransportBookings(r.Context(), startDate, endDate, status, driverID, departureGeoLayer, departureGeoCode, destinationGeoLayer, destinationGeoCode, passengerAddressGeoLayer, passengerAddressGeoCode)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get solidarity transport bookings")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Render to Excel
|
||||
h.renderer.XLSX.SolidarityTransportBookings(w, result)
|
||||
}
|
||||
|
||||
func (h *Handler) SolidarityTransportDrivers(w http.ResponseWriter, r *http.Request) {
|
||||
// Parse query parameters - same as web page
|
||||
archivedFilter := r.URL.Query().Get("archived") == "true"
|
||||
driverAddressGeo := r.URL.Query().Get("driver_address_geo")
|
||||
|
||||
// Parse driver address geography parameter
|
||||
driverAddressGeoLayer, driverAddressGeoCode := "", ""
|
||||
if driverAddressGeo != "" {
|
||||
parts := strings.SplitN(driverAddressGeo, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
driverAddressGeoLayer, driverAddressGeoCode = parts[0], parts[1]
|
||||
}
|
||||
}
|
||||
|
||||
// Get drivers data through overview (same as web page)
|
||||
result, err := h.applicationHandler.GetSolidarityTransportOverview(
|
||||
r.Context(),
|
||||
"", "", "", "", "", "", "", "", "", "", // booking filters (empty)
|
||||
"", "", "", "", "", "", "", "", "", "", // history booking filters (empty)
|
||||
archivedFilter,
|
||||
driverAddressGeoLayer, driverAddressGeoCode,
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get solidarity transport drivers")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Render to Excel
|
||||
h.renderer.XLSX.SolidarityTransportDrivers(w, result)
|
||||
}
|
||||
Reference in New Issue
Block a user