Add VehicleBookingsCreateDiag - second route to create a diag in reservation
Build and Push Docker Image / build_and_push (push) Failing after 1m40s
Details
Build and Push Docker Image / build_and_push (push) Failing after 1m40s
Details
This commit is contained in:
parent
1f265ba4bd
commit
08cfe11814
|
@ -262,6 +262,67 @@ func (h *ApplicationHandler) BookingsCreateDiag(w http.ResponseWriter, r *http.R
|
|||
h.Renderer.BookingsCreateDiag(w, r, bookingID)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) VehicleBookingsCreateDiag(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
bookingID := vars["bookingid"]
|
||||
|
||||
if h.services == nil || (h.services.GRPC == services.GRPCServices{}) || h.services.GRPC.Diags == nil {
|
||||
log.Error().Msg("Diags service is not initialized")
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if r.Method == http.MethodPost {
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
http.Error(w, "Missing group information", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
diagForm, err := parseDiagsForm(r)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Invalid form data")
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
log.Debug().Interface("diagForm", diagForm).Msg("Form data parsed")
|
||||
|
||||
data, err := structpb.NewStruct(map[string]any{
|
||||
"booking": bookingID,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to create protobuf struct")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
request := &diags.CreateDiagRequest{
|
||||
Diag: &diags.Diag{
|
||||
Name: diagForm.Name,
|
||||
Namespace: diagForm.Namespace,
|
||||
JsonSchema: diagForm.JsonSchema,
|
||||
UiSchema: diagForm.UiSchema,
|
||||
Data: data,
|
||||
Deleted: diagForm.Deleted,
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Diags.CreateDiag(context.TODO(), request)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to create diagnostic")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/diags/%s", resp.Diag.Id), http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
h.Renderer.VehicleBookingsCreateDiag(w, r, bookingID)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) DiagsDisplayDiag(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
diagid := vars["diagid"]
|
||||
|
|
|
@ -12,6 +12,8 @@ import (
|
|||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
||||
diags "git.coopgo.io/coopgo-platform/diags/grpcapi"
|
||||
diagsstorage "git.coopgo.io/coopgo-platform/diags/storage"
|
||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||
"git.coopgo.io/coopgo-platform/fleets/storage"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
|
@ -305,7 +307,32 @@ func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http
|
|||
documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid)
|
||||
file_types_map := h.config.GetStringMapString("storage.files.file_types")
|
||||
|
||||
h.Renderer.VehicleBookingDisplay(w, r, booking, booking.Vehicle, beneficiaryresp.Account.ToStorageType(), groupresp.Group.ToStorageType(), documents, file_types_map)
|
||||
diag := []diagsstorage.Diag{}
|
||||
|
||||
diagsrequest := &diags.GetDiagsRequest{
|
||||
Namespaces: []string{"parcoursmob_bookings"},
|
||||
}
|
||||
|
||||
diagsresp, err := h.services.GRPC.Diags.GetDiags(context.TODO(), diagsrequest)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for _, d := range diagsresp.Diags {
|
||||
diagData := d.Data.AsMap()
|
||||
if booking, ok := diagData["booking"].(string); ok && booking == bookingid {
|
||||
diag = append(diag, d.ToStorageType())
|
||||
}
|
||||
}
|
||||
|
||||
diagsAny := make([]any, len(diag))
|
||||
for i, d := range diag {
|
||||
diagsAny[i] = d
|
||||
}
|
||||
|
||||
h.Renderer.VehicleBookingDisplay(w, r, booking, booking.Vehicle, beneficiaryresp.Account.ToStorageType(), groupresp.Group.ToStorageType(), documents, file_types_map, diagsAny)
|
||||
}
|
||||
|
||||
func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
2
main.go
2
main.go
|
@ -196,6 +196,8 @@ func main() {
|
|||
////////////////////////////////////////////////////////////////
|
||||
//////////////////Diag in bookings////////////////////////
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/create-diag", applicationHandler.BookingsCreateDiag)
|
||||
application.HandleFunc("/vehicles/bookings/{vehicleid}/diags", applicationHandler.DiagsHome)
|
||||
application.HandleFunc("/vehicles/bookings/{bookingid}/create-diag", applicationHandler.VehicleBookingsCreateDiag)
|
||||
//////////////////Diags////////////////////////
|
||||
application.HandleFunc("/diags/", applicationHandler.DiagsHome)
|
||||
application.HandleFunc("/diags/{diagid}", applicationHandler.DiagsDisplayDiag)
|
||||
|
|
|
@ -55,6 +55,15 @@ func (renderer *Renderer) BookingsCreateDiag(w http.ResponseWriter, r *http.Requ
|
|||
renderer.Render("diag create for booking", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) VehicleBookingsCreateDiag(w http.ResponseWriter, r *http.Request, booking string) {
|
||||
state := NewState(r, renderer.ThemeConfig, diagsMenu)
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.create_booking_diag.files")
|
||||
state.ViewState = map[string]any{
|
||||
"booking": booking,
|
||||
}
|
||||
renderer.Render("diag create for booking", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) DiagsDisplayDiag(w http.ResponseWriter, r *http.Request, diag any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.diags.display_diag.files")
|
||||
state := NewState(r, renderer.ThemeConfig, diagsMenu)
|
||||
|
|
|
@ -52,7 +52,7 @@ func (renderer *Renderer) VehiclesSearch(w http.ResponseWriter, r *http.Request,
|
|||
renderer.Render("vehicles search", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) VehicleBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string) {
|
||||
func (renderer *Renderer) VehicleBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string, diags []any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.booking_display.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
|
||||
state.ViewState = map[string]any{
|
||||
|
@ -62,6 +62,7 @@ func (renderer *Renderer) VehicleBookingDisplay(w http.ResponseWriter, r *http.R
|
|||
"group": group,
|
||||
"documents": documents,
|
||||
"file_types_map": file_types_map,
|
||||
"diags": diags,
|
||||
}
|
||||
|
||||
renderer.Render("vehicles search", w, r, files, state)
|
||||
|
|
Loading…
Reference in New Issue