diff --git a/apps/backend/from_bkp.go b/apps/backend/from_bkp.go deleted file mode 100644 index fa130be..0000000 --- a/apps/backend/from_bkp.go +++ /dev/null @@ -1,277 +0,0 @@ -package main - -import ( - "backend/parser" - "backend/typesdefs" - "backend/utils" - "encoding/xml" - "fmt" - "io" - "os" - "slices" - "strconv" - "strings" - "sync" - "time" -) - -func From_Backup() typesdefs.XmlBkp { - //open the bkp.xml file - xmlFile, err := os.Open("bkp.xml") - if err != nil { - fmt.Println(err) - } - defer xmlFile.Close() - - byteValue, err := io.ReadAll(xmlFile) - if err != nil { - fmt.Println(err) - } - var miogest typesdefs.XmlBkp - xml.Unmarshal(byteValue, &miogest) - return miogest - -} - -func ParseUpdateBkp(m *MiogestHandler) typesdefs.AnnunciParsed { - - miogest := From_Backup() - - var AnnunciArray typesdefs.AnnunciParsed - extractedData := make(chan typesdefs.AnnuncioParsed) - defaultCaratteristiche := m.GetCaratteristiche() - defaultCategorie := m.GetCategorie() - - var wg sync.WaitGroup - wg.Add(len(miogest.Annunci.Record)) - - for i := 0; i < len(miogest.Annunci.Record); i++ { - go func(i int) { - defer wg.Done() - extractData_bkp(miogest.Annunci.Record[i], extractedData, defaultCaratteristiche, defaultCategorie) - }(i) - } - - go func() { - wg.Wait() - close(extractedData) - }() - - for result := range extractedData { - AnnunciArray.Annuncio = append(AnnunciArray.Annuncio, result) - } - - return AnnunciArray -} - -func extractData_bkp(annuncio typesdefs.AnnuncioBKP, extractedData chan typesdefs.AnnuncioParsed, defaultCaratteristiche typesdefs.ListaCaratteristiche, defaultCategorie []typesdefs.Categoria) { - - var tmp typesdefs.AnnuncioParsed = typesdefs.AnnuncioParsed{} - - codice := utils.RemoveWhitespace(utils.GetStringValue(annuncio.Codice)) - tmp.Codice = codice - tmp.Email = nil - if annuncio.Proprietario != nil && annuncio.Proprietario.Cliente != nil && annuncio.Proprietario.Cliente.Nome != nil { - tmp.Locatore = annuncio.Proprietario.Cliente.Nome - } - tmp.Numero = nil - if annuncio.Proprietario != nil && annuncio.Proprietario.Cliente != nil && annuncio.Proprietario.Cliente.Nome != nil { - tmp.Idlocatore = annuncio.Proprietario.Cliente.ID - } - - upperIndirizzo := utils.MakeUppercase(utils.GetStringValue(annuncio.Indirizzo)) - tmp.Indirizzo = &upperIndirizzo - tmp.Civico = annuncio.Civico - upperComune := utils.MakeUppercase(utils.GetStringValue(annuncio.Comune)) - tmp.Comune = &upperComune - tmp.Cap = annuncio.Cap - tmp.Provincia = annuncio.Provincia - tmp.Regione = annuncio.Regione - tmp.Lat = utils.CommaToDot(annuncio.Lat) - tmp.Lon = utils.CommaToDot(annuncio.Lon) - tmp.Indirizzo_secondario = nil - tmp.Civico_secondario = nil - tmp.Lat_secondario = nil - tmp.Lon_secondario = nil - - var tipo = tipologiaParser(*annuncio.Tipo) - tmp.Tipo = &tipo - - tmpanno := utils.GetStringValue(annuncio.Anno) - if tmpanno != "0" && tmpanno != "" { - tmp.Anno = &tmpanno - } - tmp.Prezzo = parser.ParsePrezzo(annuncio.Prezzo) - tmp.Consegna = parser.ParseConsegna(annuncio.Consegna) - tmp.Classe = annuncio.Classe - - if annuncio.Categorie != nil && annuncio.Categorie.Categoria != nil { - resultArray := make([]string, 0) - cats := *annuncio.Categorie.Categoria - for _, cat := range cats { - for _, catdef := range defaultCategorie { - if cat.ID == catdef.Id { - resultArray = append(resultArray, catdef.Nome) - } - } - } - if tmp.Categorie == nil { - tmp.Categorie = &[]string{} - } - *tmp.Categorie = resultArray - } - - if annuncio.Mq != nil { - replaced := strings.ReplaceAll(*annuncio.Mq, ",", ".") - if s, err := strconv.ParseFloat(replaced, 64); err == nil { - tmp.Mq = &s - } - - } - - tmp.Piano = annuncio.Piano - tmp.Piano_palazzo = annuncio.PianoPalazzo - tmp.Unita_condominio = annuncio.UnitaImmobiliari - tmp.Numero_vani = annuncio.NumeroVani - tmp.Numero_camere = annuncio.NumeroCamere - tmp.Numero_bagni = annuncio.NumeroBagni - tmp.Numero_balconi = annuncio.NumeroBalconi - tmp.Numero_terrazzi = annuncio.NumeroTerrazzi - tmp.Numero_box = annuncio.NumeroBox - tmp.Numero_postiauto = annuncio.NumeroPostiauto - tmpstato := utils.GetStringValue(annuncio.Stato) - var tmpstatoString string - if tmpstato == "1" { - tmpstatoString = "Attivo" - } - if tmpstato == "2" { - tmpstatoString = "Trattativa" - } else { - tmpstatoString = "Sospeso" - } - tmp.Stato = &tmpstatoString - home := false - tmp.Homepage = &home - - layout := "20060102150405" - if annuncio.Inserito != nil { - t, err := time.Parse(layout, *annuncio.Inserito) - if err != nil { - tmp.Creato_il = nil - } else { - tmp.Creato_il = &t - } - } - - tmp.Modificato_il = nil - - var itlingua string = "it" - var enlingua string = "en" - var tmpTitoloIt *string = nil - var tmpTitoloEn *string = nil - var tmpDescIt *string = nil - var tmpDescEn *string = nil - - if annuncio.Descrizioni != nil { - for _, desc := range *annuncio.Descrizioni.Descrizione { - - if desc.Lingua != nil { - if *desc.Lingua == itlingua { - tmpTitoloIt = desc.Titolo - tmpDescIt = desc.Testo - } - if *desc.Lingua == enlingua { - tmpTitoloEn = desc.Titolo - tmpDescEn = desc.Testo - } - } - - } - } - - tmp.Titolo_it = tmpTitoloIt - tmp.Titolo_en = tmpTitoloEn - tmp.Desc_it = tmpDescIt - tmp.Desc_en = tmpDescEn - w := false - tmp.Web = &w - - tmp.External_videos = nil - - if annuncio.Accessori != nil && annuncio.Accessori.Accessorio != nil { - tmpAcc := make([]string, 0) - for _, acc := range *annuncio.Accessori.Accessorio { - if acc.Nome != nil { - tmpAcc = append(tmpAcc, *acc.Nome) - } - } - if tmp.Accessori == nil { - tmp.Accessori = &[]string{} - } - *tmp.Accessori = tmpAcc - } - - tmpCaratteristiche := make(map[string]interface{}) - - if annuncio.Schede != nil && annuncio.Schede.Scheda != nil { - for _, scheda := range *annuncio.Schede.Scheda { - if scheda.Valore != nil { - var cossriponding_name *string = nil - for _, def := range defaultCaratteristiche.Caratteristiche { - if scheda.ID == def.Id { - cossriponding_name = &def.Tagxml - } - } - if cossriponding_name != nil { - tmpCaratteristiche[*cossriponding_name] = *scheda.Valore - } - } - } - } - - for _, def := range defaultCaratteristiche.Caratteristiche { - - if _, ok := tmpCaratteristiche[def.Tagxml]; !ok { - tmpCaratteristiche[def.Tagxml] = nil - } - - } - tmp.Caratteristiche = &tmpCaratteristiche - - tmp.External_videos = nil - - extractedData <- tmp - -} - -func TestTipologieBkp() { - - bkp := From_Backup() - var tipologie []string - for _, r := range bkp.Annunci.Record { - if r.Tipo != nil { - if !slices.Contains(tipologie, *r.Tipo) { - tipologie = append(tipologie, *r.Tipo) - } - } - } - fmt.Println(strings.Join(tipologie, ",")) - -} - -func tipologiaParser(tipo string) string { - var result string - switch tipo { - case "Affitto Residenziale", "Affitto Turistico": - result = "Transitorio" - case "Vendita Residenziale", "Vendita Commerciale": - result = "Vendita" - case "Affitto Commerciale", "Affitto": - result = "Stabile" - case "Cessione Commerciale", "Cessione": - result = "Cessione" - default: - result = "Errore" - } - return result -} diff --git a/apps/backend/public/views/backup-upload.html b/apps/backend/public/views/backup-upload.html deleted file mode 100644 index 40f8bfd..0000000 --- a/apps/backend/public/views/backup-upload.html +++ /dev/null @@ -1,59 +0,0 @@ -{{define "backup-upload"}} - - - -
- -File %s uploaded successfully.
", file.Filename)) - }) - e.GET("/bkp", func(c echo.Context) error { - data := From_Backup() - return c.JSONPretty(http.StatusOK, data, " ") - }) - e.GET("/parsebkp", func(c echo.Context) error { - var data = ParseUpdateBkp(s.miogest) - return c.JSONPretty(http.StatusOK, data, " ") - }) - e.GET("/setbkp", func(c echo.Context) error { - var data = ParseUpdateBkp(s.miogest) - err := queries.SetFromBkp(data) - if err != nil { - return c.String(http.StatusInternalServerError, err.Error()) - } - return c.String(http.StatusOK, "Setted") - }) - */ - //IMAGE ROUTES e.GET("/initcwebp", func(c echo.Context) error { Conversion("test.jpg") diff --git a/apps/backend/typesdefs/models.go b/apps/backend/typesdefs/models.go index 9df0d6e..b6529be 100644 --- a/apps/backend/typesdefs/models.go +++ b/apps/backend/typesdefs/models.go @@ -5,84 +5,6 @@ import ( "time" ) -type XmlBkp struct { - Annunci struct { - Record []AnnuncioBKP `xml:"record"` - } `xml:"annunci"` -} - -type AnnuncioBKP struct { - Codice *string `xml:"codice"` - Proprietario *struct { - Cliente *struct { - ID *string `xml:"id"` - Nome *string `xml:"nome"` - } `xml:"cliente"` - } `xml:"proprietario"` - Nazione *string `xml:"nazione"` - Regione *string `xml:"regione"` - Provincia *string `xml:"provincia"` - Comune *string `xml:"comune"` - Cap *string `xml:"cap"` - Indirizzo *string `xml:"indirizzo"` - Civico *string `xml:"civico"` - Lat *string `xml:"lat"` - Lon *string `xml:"lon"` - Tipo *string `xml:"tipo"` - Categorie *struct { - Categoria *[]struct { - ID string `xml:"id"` - Nome string `xml:"nome"` - } `xml:"categoria"` - } `xml:"categorie"` - Prezzo *string `xml:"prezzo"` - Piani *string `xml:"piani"` - Anno *string `xml:"anno"` - Consegna *string `xml:"consegna"` - Classe *string `xml:"classe"` - Mq *string `xml:"mq"` - Piano *string `xml:"piano"` - PianoPalazzo *string `xml:"piano_palazzo"` - UnitaImmobiliari *string `xml:"unita_immobiliari"` - NumeroVani *string `xml:"numero_vani"` - NumeroCamere *string `xml:"numero_camere"` - NumeroLetti *string `xml:"numero_letti"` - NumeroBagni *string `xml:"numero_bagni"` - NumeroBalconi *string `xml:"numero_balconi"` - NumeroTerrazzi *string `xml:"numero_terrazzi"` - NumeroBox *string `xml:"numero_box"` - NumeroPostiauto *string `xml:"numero_postiauto"` - Schede *struct { - Scheda *[]struct { - ID string `xml:"id"` - Nome string `xml:"nome"` - Valore *string `xml:"valore"` - } `xml:"scheda"` - } `xml:"schede"` - Accessori *struct { - Accessorio *[]struct { - ID string `xml:"id"` - Nome *string `xml:"nome"` - } `xml:"accessorio"` - } `xml:"accessori"` - Web *string `xml:"web"` - Descrizioni *struct { - Descrizione *[]struct { - Lingua *string `xml:"lingua"` - Titolo *string `xml:"titolo"` - Testo *string `xml:"testo"` - } `xml:"descrizione"` - } `xml:"descrizioni"` - Allegati *struct { - Foto *[]struct { - Nome *string `xml:"nome"` - URL *string `xml:"url"` - } `xml:"foto"` - } `xml:"allegati"` - Inserito *string `xml:"inserito"` - Stato *string `xml:"stato"` -} - type AnnunciXML struct { Annuncio []AnnuncioXML `xml:"Annuncio"` }