Compare commits
4 Commits
a1adc028df
...
351b21f553
Author | SHA1 | Date |
---|---|---|
|
351b21f553 | |
|
0a690cadf1 | |
|
d0fc96f8bb | |
|
023f5c735d |
2
go.mod
2
go.mod
|
@ -51,7 +51,7 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
ariga.io/atlas v0.12.0 // indirect
|
ariga.io/atlas v0.12.0 // indirect
|
||||||
git.coopgo.io/coopgo-platform/diags v0.0.0-20241120133550-917ed8705c73
|
git.coopgo.io/coopgo-platform/diags v0.0.0-20250212093351-64da61495c9d
|
||||||
github.com/agext/levenshtein v1.2.1 // indirect
|
github.com/agext/levenshtein v1.2.1 // indirect
|
||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
||||||
github.com/coreos/go-semver v0.3.0 // indirect
|
github.com/coreos/go-semver v0.3.0 // indirect
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -2,8 +2,12 @@ ariga.io/atlas v0.12.0 h1:jDfjxT3ppKhzqLS26lZv9ni7p9TVNrhy7SQquaF7bPs=
|
||||||
ariga.io/atlas v0.12.0/go.mod h1:+TR129FJZ5Lvzms6dvCeGWh1yR6hMvmXBhug4hrNIGk=
|
ariga.io/atlas v0.12.0/go.mod h1:+TR129FJZ5Lvzms6dvCeGWh1yR6hMvmXBhug4hrNIGk=
|
||||||
git.coopgo.io/coopgo-platform/agenda v1.0.0 h1:rTHgva1JKKO0wAPlINegifMkHm+xOg3IWW4yQRy334w=
|
git.coopgo.io/coopgo-platform/agenda v1.0.0 h1:rTHgva1JKKO0wAPlINegifMkHm+xOg3IWW4yQRy334w=
|
||||||
git.coopgo.io/coopgo-platform/agenda v1.0.0/go.mod h1:/hToSla0p6SeWn1zo1MDrfxdmo7RBdZDkbLqCVituIM=
|
git.coopgo.io/coopgo-platform/agenda v1.0.0/go.mod h1:/hToSla0p6SeWn1zo1MDrfxdmo7RBdZDkbLqCVituIM=
|
||||||
git.coopgo.io/coopgo-platform/diags v0.0.0-20241120133550-917ed8705c73 h1:Xyc2Xuf7VnaOVD7sro2GPD1gzwo+R9lyfkWjyrTYlqY=
|
git.coopgo.io/coopgo-platform/diags v0.0.0-20250210110754-726bb4643c63 h1:BvNTshj4TToGptaheeAzEmaNeuqPCR/NIH6TGePd54A=
|
||||||
git.coopgo.io/coopgo-platform/diags v0.0.0-20241120133550-917ed8705c73/go.mod h1:diyq11WNkgJ0kYHdT7SphXPMQUyoq4lRk7T6IgM5yPA=
|
git.coopgo.io/coopgo-platform/diags v0.0.0-20250210110754-726bb4643c63/go.mod h1:diyq11WNkgJ0kYHdT7SphXPMQUyoq4lRk7T6IgM5yPA=
|
||||||
|
git.coopgo.io/coopgo-platform/diags v0.0.0-20250211082457-291671c295e6 h1:McRGfPLueD+wcx8yf19a31uei4Ha0ugiDtnYtHYErrg=
|
||||||
|
git.coopgo.io/coopgo-platform/diags v0.0.0-20250211082457-291671c295e6/go.mod h1:diyq11WNkgJ0kYHdT7SphXPMQUyoq4lRk7T6IgM5yPA=
|
||||||
|
git.coopgo.io/coopgo-platform/diags v0.0.0-20250212093351-64da61495c9d h1:fBxVvik4Cb/6d4+HAXZi9e8x8P9UBCJt8JcWgqnNjsE=
|
||||||
|
git.coopgo.io/coopgo-platform/diags v0.0.0-20250212093351-64da61495c9d/go.mod h1:diyq11WNkgJ0kYHdT7SphXPMQUyoq4lRk7T6IgM5yPA=
|
||||||
git.coopgo.io/coopgo-platform/emailing v0.0.0-20241119141913-9836b30191c1 h1:gAhJ9wwlitMiETmnD4U2L6xLnVd5xE4hPX72IJ5s7+I=
|
git.coopgo.io/coopgo-platform/emailing v0.0.0-20241119141913-9836b30191c1 h1:gAhJ9wwlitMiETmnD4U2L6xLnVd5xE4hPX72IJ5s7+I=
|
||||||
git.coopgo.io/coopgo-platform/emailing v0.0.0-20241119141913-9836b30191c1/go.mod h1:EXy6NRvFfpW6yIHoZUixldkXrj1qzjCbTHpumDvzaKI=
|
git.coopgo.io/coopgo-platform/emailing v0.0.0-20241119141913-9836b30191c1/go.mod h1:EXy6NRvFfpW6yIHoZUixldkXrj1qzjCbTHpumDvzaKI=
|
||||||
git.coopgo.io/coopgo-platform/fleets v0.0.0-20230310144446-feb935f8bf4e h1:eHahRTKlC8aBWYCd6LbXNcX8HoQhuZj31OFWrw0EL0U=
|
git.coopgo.io/coopgo-platform/fleets v0.0.0-20230310144446-feb935f8bf4e h1:eHahRTKlC8aBWYCd6LbXNcX8HoQhuZj31OFWrw0EL0U=
|
||||||
|
|
|
@ -5,27 +5,31 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
// "io"
|
// "io"
|
||||||
"net/http"
|
"net/http"
|
||||||
// "strconv"
|
// "strconv"
|
||||||
"strings"
|
"strings"
|
||||||
// "time"
|
"time"
|
||||||
|
|
||||||
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
||||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||||
|
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
||||||
|
|
||||||
// filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
// filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
||||||
diags "git.coopgo.io/coopgo-platform/diags/grpcapi"
|
diags "git.coopgo.io/coopgo-platform/diags/grpcapi"
|
||||||
diagsstorage "git.coopgo.io/coopgo-platform/diags/storage"
|
diagsstorage "git.coopgo.io/coopgo-platform/diags/storage"
|
||||||
|
|
||||||
// groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||||
// "git.coopgo.io/coopgo-platform/groups-management/storage"
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
// mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
// mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||||
// "github.com/google/uuid"
|
// "github.com/google/uuid"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"google.golang.org/protobuf/types/known/structpb"
|
"google.golang.org/protobuf/types/known/structpb"
|
||||||
// "google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiagsForm struct {
|
type DiagsForm struct {
|
||||||
|
@ -35,12 +39,15 @@ type DiagsForm struct {
|
||||||
UiSchema string `json:"ui_schema"`
|
UiSchema string `json:"ui_schema"`
|
||||||
Data map[string]any `json:"data"`
|
Data map[string]any `json:"data"`
|
||||||
Deleted bool `json:"deleted"`
|
Deleted bool `json:"deleted"`
|
||||||
|
Diagdate *time.Time `json:"diagdate"`
|
||||||
|
Owners []string `json:"owners"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) DiagsHome(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) DiagsHome(w http.ResponseWriter, r *http.Request) {
|
||||||
|
groupID := r.Context().Value(identification.GroupKey).(storage.Group).ID
|
||||||
|
|
||||||
resp, err := h.services.GRPC.Diags.GetDiags(context.TODO(), &diags.GetDiagsRequest{
|
resp, err := h.services.GRPC.Diags.GetDiags(context.TODO(), &diags.GetDiagsRequest{
|
||||||
Namespaces: []string{"parcoursmob_beneficiaries", "parcoursmob_diagnostiques", "parcoursmob_vehicles", "parcoursmob_bookings"},
|
Namespaces: []string{"parcoursmob_beneficiaries", "parcoursmob_diagnostiques", "parcoursmob_vehicles", "parcoursmob_bookings"},
|
||||||
// Mindate: timestamppb.New(time.Now().Add(-24 * time.Hour)),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,17 +58,40 @@ func (h *ApplicationHandler) DiagsHome(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
responses := []diagsstorage.Diag{}
|
responses := []diagsstorage.Diag{}
|
||||||
|
|
||||||
|
groupids := []string{}
|
||||||
for _, e := range resp.Diags {
|
for _, e := range resp.Diags {
|
||||||
|
groupids = append(groupids, e.Owners...)
|
||||||
responses = append(responses, e.ToStorageType())
|
responses = append(responses, e.ToStorageType())
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Renderer.DiagsHome(w, r, responses)
|
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||||
|
Groupids: groupids,
|
||||||
|
})
|
||||||
|
groups := map[string]any{}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
for _, g := range groupsresp.Groups {
|
||||||
|
groups[g.Id] = g.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredDiags := []diagsstorage.Diag{}
|
||||||
|
for _, diag := range responses {
|
||||||
|
for _, owner := range diag.Owners {
|
||||||
|
if string(owner) == groupID {
|
||||||
|
filteredDiags = append(filteredDiags, diag)
|
||||||
|
log.Debug().Msgf("Diag %s added to filtered list", diag.ID)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h.Renderer.DiagsHome(w, r, filteredDiags, groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) DiagsHistory(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) DiagsHistory(w http.ResponseWriter, r *http.Request) {
|
||||||
resp, err := h.services.GRPC.Diags.GetDiags(context.TODO(), &diags.GetDiagsRequest{
|
resp, err := h.services.GRPC.Diags.GetDiags(context.TODO(), &diags.GetDiagsRequest{
|
||||||
Namespaces: []string{"parcoursmob_beneficiaries", "parcoursmob_diagnostiques", "parcoursmob_vehicles", "parcoursmob_bookings"},
|
Namespaces: []string{"parcoursmob_beneficiaries", "parcoursmob_diagnostiques", "parcoursmob_vehicles", "parcoursmob_bookings"},
|
||||||
//Maxdate: timestamppb.New(time.Now().Add(24 * time.Hour)),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -99,6 +129,8 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
diagForm, err := parseDiagsForm(r)
|
diagForm, err := parseDiagsForm(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Invalid form data")
|
log.Error().Err(err).Msg("Invalid form data")
|
||||||
|
@ -106,8 +138,6 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Interface("diagForm", diagForm).Msg("Form data parsed")
|
|
||||||
|
|
||||||
data, err := structpb.NewStruct(map[string]any{
|
data, err := structpb.NewStruct(map[string]any{
|
||||||
"beneficiary": beneficiaryID,
|
"beneficiary": beneficiaryID,
|
||||||
})
|
})
|
||||||
|
@ -125,6 +155,8 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
|
||||||
UiSchema: diagForm.UiSchema,
|
UiSchema: diagForm.UiSchema,
|
||||||
Data: data,
|
Data: data,
|
||||||
Deleted: diagForm.Deleted,
|
Deleted: diagForm.Deleted,
|
||||||
|
Diagdate: timestamppb.New(time.Now()),
|
||||||
|
Owners: []string{group.ID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,11 +167,46 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentType := r.Header.Get("Content-Type")
|
||||||
|
if strings.HasPrefix(contentType, "multipart/form-data") {
|
||||||
|
err = r.ParseMultipartForm(100 * 1024 * 1024) // 100 MB limit
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Error parsing multipart form")
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file, header, err := r.FormFile("file-upload")
|
||||||
|
if err == nil {
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
document_type := r.FormValue("file_type")
|
||||||
|
document_name := r.FormValue("file_name")
|
||||||
|
|
||||||
|
fileid := uuid.NewString()
|
||||||
|
|
||||||
|
metadata := map[string]string{
|
||||||
|
"file_type": document_type,
|
||||||
|
"file_name": document_name,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.filestorage.Put(file, filestorage.PREFIX_DIAGS, fmt.Sprintf("%s/%s_%s", resp.Diag.Id, fileid, header.Filename), header.Size, metadata); err != nil {
|
||||||
|
log.Error().Err(err).Msg("Error uploading file")
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else if err != http.ErrMissingFile {
|
||||||
|
log.Error().Err(err).Msg("Error retrieving file")
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/diags/%s", resp.Diag.Id), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/diags/%s", resp.Diag.Id), http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Renderer.BeneficiariesCreateDiag(w, r, beneficiaryID)
|
h.Renderer.BeneficiariesCreateDiag(w, r, beneficiaryID, h.config.GetStringSlice("modules.diags.documents_types"), h.config.GetStringMapString("storage.files.file_types"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) VehiclesCreateDiag(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) VehiclesCreateDiag(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -178,6 +245,8 @@ func (h *ApplicationHandler) VehiclesCreateDiag(w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
request := &diags.CreateDiagRequest{
|
request := &diags.CreateDiagRequest{
|
||||||
Diag: &diags.Diag{
|
Diag: &diags.Diag{
|
||||||
Name: diagForm.Name,
|
Name: diagForm.Name,
|
||||||
|
@ -186,6 +255,8 @@ func (h *ApplicationHandler) VehiclesCreateDiag(w http.ResponseWriter, r *http.R
|
||||||
UiSchema: diagForm.UiSchema,
|
UiSchema: diagForm.UiSchema,
|
||||||
Data: data,
|
Data: data,
|
||||||
Deleted: diagForm.Deleted,
|
Deleted: diagForm.Deleted,
|
||||||
|
Diagdate: timestamppb.New(time.Now()),
|
||||||
|
Owners: []string{group.ID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +310,8 @@ func (h *ApplicationHandler) BookingsCreateDiag(w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
request := &diags.CreateDiagRequest{
|
request := &diags.CreateDiagRequest{
|
||||||
Diag: &diags.Diag{
|
Diag: &diags.Diag{
|
||||||
Name: diagForm.Name,
|
Name: diagForm.Name,
|
||||||
|
@ -247,6 +320,8 @@ func (h *ApplicationHandler) BookingsCreateDiag(w http.ResponseWriter, r *http.R
|
||||||
UiSchema: diagForm.UiSchema,
|
UiSchema: diagForm.UiSchema,
|
||||||
Data: data,
|
Data: data,
|
||||||
Deleted: diagForm.Deleted,
|
Deleted: diagForm.Deleted,
|
||||||
|
Diagdate: timestamppb.New(time.Now()),
|
||||||
|
Owners: []string{group.ID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,6 +375,8 @@ func (h *ApplicationHandler) VehicleBookingsCreateDiag(w http.ResponseWriter, r
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
request := &diags.CreateDiagRequest{
|
request := &diags.CreateDiagRequest{
|
||||||
Diag: &diags.Diag{
|
Diag: &diags.Diag{
|
||||||
Name: diagForm.Name,
|
Name: diagForm.Name,
|
||||||
|
@ -308,6 +385,8 @@ func (h *ApplicationHandler) VehicleBookingsCreateDiag(w http.ResponseWriter, r
|
||||||
UiSchema: diagForm.UiSchema,
|
UiSchema: diagForm.UiSchema,
|
||||||
Data: data,
|
Data: data,
|
||||||
Deleted: diagForm.Deleted,
|
Deleted: diagForm.Deleted,
|
||||||
|
Diagdate: timestamppb.New(time.Now()),
|
||||||
|
Owners: []string{group.ID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +427,12 @@ func (h *ApplicationHandler) DiagsDisplayDiag(w http.ResponseWriter, r *http.Req
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
h.Renderer.DiagsDisplayDiag(w, r, resp.Diag.ToStorageType())
|
documents := h.filestorage.List(filestorage.PREFIX_DIAGS + "/" + diagid)
|
||||||
|
|
||||||
|
diags_file_types := h.config.GetStringSlice("modules.diags.documents_types")
|
||||||
|
file_types_map := h.config.GetStringMapString("storage.files.file_types")
|
||||||
|
|
||||||
|
h.Renderer.DiagsDisplayDiag(w, r, resp.Diag.ToStorageType(), diags_file_types, file_types_map, documents)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDiagsForm(r *http.Request) (*DiagsForm, error) {
|
func parseDiagsForm(r *http.Request) (*DiagsForm, error) {
|
||||||
|
@ -400,6 +484,8 @@ func (h *ApplicationHandler) DiagUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
diagForm, err := parseDiagsForm(r)
|
diagForm, err := parseDiagsForm(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("")
|
log.Error().Err(err).Msg("")
|
||||||
|
@ -417,7 +503,8 @@ func (h *ApplicationHandler) DiagUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
JsonSchema: diagForm.JsonSchema,
|
JsonSchema: diagForm.JsonSchema,
|
||||||
UiSchema: diagForm.UiSchema,
|
UiSchema: diagForm.UiSchema,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
Diagdate: timestamppb.New(time.Now()),
|
||||||
|
Owners: []string{group.ID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,6 +548,7 @@ func (h *ApplicationHandler) DiagDelete(w http.ResponseWriter, r *http.Request)
|
||||||
UiSchema: resp.Diag.UiSchema,
|
UiSchema: resp.Diag.UiSchema,
|
||||||
Data: resp.Diag.Data,
|
Data: resp.Diag.Data,
|
||||||
Deleted: true,
|
Deleted: true,
|
||||||
|
Diagdate: resp.Diag.Diagdate,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,3 +582,61 @@ func (h *ApplicationHandler) DiagsHistoryDiag(w http.ResponseWriter, r *http.Req
|
||||||
|
|
||||||
h.Renderer.DiagsHistoryDiag(w, r, resp.Diag.ToStorageType())
|
h.Renderer.DiagsHistoryDiag(w, r, resp.Diag.ToStorageType())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// //// ADD DOCUMENTS //////
|
||||||
|
func (h *ApplicationHandler) DiagsDocuments(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
diagID := vars["diagid"]
|
||||||
|
|
||||||
|
//r.ParseForm()
|
||||||
|
r.ParseMultipartForm(100 * 1024 * 1024)
|
||||||
|
|
||||||
|
document_type := r.FormValue("type")
|
||||||
|
document_name := r.FormValue("name")
|
||||||
|
|
||||||
|
file, header, err := r.FormFile("file-upload")
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
fileid := uuid.NewString()
|
||||||
|
|
||||||
|
metadata := map[string]string{
|
||||||
|
"type": document_type,
|
||||||
|
"name": document_name,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.filestorage.Put(file, filestorage.PREFIX_DIAGS, fmt.Sprintf("%s/%s_%s", diagID, fileid, header.Filename), header.Size, metadata); err != nil {
|
||||||
|
log.Error().Err(err).Msg("")
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/diags/%s", diagID), http.StatusFound)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ApplicationHandler) DiagsDocumentDownload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
diagID := vars["diagid"]
|
||||||
|
document := vars["document"]
|
||||||
|
|
||||||
|
file, info, err := h.filestorage.Get(filestorage.PREFIX_DIAGS, fmt.Sprintf("%s/%s", diagID, document))
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("")
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", info.ContentType)
|
||||||
|
if _, err = io.Copy(w, file); err != nil {
|
||||||
|
log.Error().Err(err).Msg("")
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, fmt.Sprintf("/app/diags/%s", diagID), http.StatusFound)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
2
main.go
2
main.go
|
@ -200,6 +200,8 @@ func main() {
|
||||||
application.HandleFunc("/vehicles/bookings/{bookingid}/create-diag", applicationHandler.VehicleBookingsCreateDiag)
|
application.HandleFunc("/vehicles/bookings/{bookingid}/create-diag", applicationHandler.VehicleBookingsCreateDiag)
|
||||||
//////////////////Diags////////////////////////
|
//////////////////Diags////////////////////////
|
||||||
application.HandleFunc("/diags/", applicationHandler.DiagsHome)
|
application.HandleFunc("/diags/", applicationHandler.DiagsHome)
|
||||||
|
application.HandleFunc("/diags/{diagid}/documents", applicationHandler.DiagsDocuments)
|
||||||
|
application.HandleFunc("/diags/{diagid}/documents/{document}", applicationHandler.DiagsDocumentDownload)
|
||||||
application.HandleFunc("/diags/{diagid}", applicationHandler.DiagsDisplayDiag)
|
application.HandleFunc("/diags/{diagid}", applicationHandler.DiagsDisplayDiag)
|
||||||
application.HandleFunc("/diags/{diagid}/update", applicationHandler.DiagUpdate)
|
application.HandleFunc("/diags/{diagid}/update", applicationHandler.DiagUpdate)
|
||||||
application.HandleFunc("/diags/{diagid}/delete", applicationHandler.DiagDelete)
|
application.HandleFunc("/diags/{diagid}/delete", applicationHandler.DiagDelete)
|
||||||
|
|
|
@ -8,11 +8,12 @@ import (
|
||||||
|
|
||||||
const diagsMenu = "diags"
|
const diagsMenu = "diags"
|
||||||
|
|
||||||
func (renderer *Renderer) DiagsHome(w http.ResponseWriter, r *http.Request, diags []diagsstorage.Diag) {
|
func (renderer *Renderer) DiagsHome(w http.ResponseWriter, r *http.Request, diags []diagsstorage.Diag, groups map[string]any) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.diags.list.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.diags.list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, diagsMenu)
|
state := NewState(r, renderer.ThemeConfig, diagsMenu)
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = map[string]any{
|
||||||
"diags": diags,
|
"diags": diags,
|
||||||
|
"groups": groups,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("diags home", w, r, files, state)
|
renderer.Render("diags home", w, r, files, state)
|
||||||
|
@ -28,11 +29,14 @@ func (renderer *Renderer) DiagsHistory(w http.ResponseWriter, r *http.Request, d
|
||||||
renderer.Render("diags history", w, r, files, state)
|
renderer.Render("diags history", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) BeneficiariesCreateDiag(w http.ResponseWriter, r *http.Request, beneficiary string) {
|
func (renderer *Renderer) BeneficiariesCreateDiag(w http.ResponseWriter, r *http.Request, beneficiary string, diags_file_types []string, file_types_map map[string]string, documents any) {
|
||||||
state := NewState(r, renderer.ThemeConfig, diagsMenu)
|
state := NewState(r, renderer.ThemeConfig, diagsMenu)
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.create_diag.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.create_diag.files")
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = map[string]any{
|
||||||
"beneficiary": beneficiary,
|
"beneficiary": beneficiary,
|
||||||
|
"diags_file_types": diags_file_types,
|
||||||
|
"file_types_map": file_types_map,
|
||||||
|
"documents": documents,
|
||||||
}
|
}
|
||||||
renderer.Render("diag create for beneficiary", w, r, files, state)
|
renderer.Render("diag create for beneficiary", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
@ -64,12 +68,15 @@ func (renderer *Renderer) VehicleBookingsCreateDiag(w http.ResponseWriter, r *ht
|
||||||
renderer.Render("diag create for booking", w, r, files, state)
|
renderer.Render("diag create for booking", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) DiagsDisplayDiag(w http.ResponseWriter, r *http.Request, diag any) {
|
func (renderer *Renderer) DiagsDisplayDiag(w http.ResponseWriter, r *http.Request, diag any, diags_file_types []string, file_types_map map[string]string, documents any) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.diags.display_diag.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.diags.display_diag.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, diagsMenu)
|
state := NewState(r, renderer.ThemeConfig, diagsMenu)
|
||||||
|
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = map[string]any{
|
||||||
"diag": diag,
|
"diag": diag,
|
||||||
|
"diags_file_types": diags_file_types,
|
||||||
|
"file_types_map": file_types_map,
|
||||||
|
"documents": documents,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("diags create diag", w, r, files, state)
|
renderer.Render("diags create diag", w, r, files, state)
|
||||||
|
|
|
@ -11,6 +11,7 @@ const (
|
||||||
PREFIX_BENEFICIARIES = "beneficiaries"
|
PREFIX_BENEFICIARIES = "beneficiaries"
|
||||||
PREFIX_BOOKINGS = "fleets_bookings"
|
PREFIX_BOOKINGS = "fleets_bookings"
|
||||||
PREFIX_AGENDA = "event_files"
|
PREFIX_AGENDA = "event_files"
|
||||||
|
PREFIX_DIAGS = "diags"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
|
|
Loading…
Reference in New Issue