feat: update type references to use typedefs in multiple files
This commit is contained in:
parent
a7cec21ab6
commit
3e854270f0
4 changed files with 20 additions and 16 deletions
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/dbhelpers"
|
"backend/dbhelpers"
|
||||||
|
"backend/typedefs"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
@ -61,16 +62,16 @@ func (h *DbHandler) GetActiveAnnunci() []string {
|
||||||
return annunci
|
return annunci
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *DbHandler) GetAllAnnunci() []AnnunciDB {
|
func (h *DbHandler) GetAllAnnunci() []typedefs.AnnunciDB {
|
||||||
//var annuncio AnnunciDB
|
//var annuncio AnnunciDB
|
||||||
var annunci []AnnunciDB
|
var annunci []typedefs.AnnunciDB
|
||||||
|
|
||||||
pgxscan.Select(h.Ctx, h.Dbpool, &annunci, "SELECT * FROM public.annunci")
|
pgxscan.Select(h.Ctx, h.Dbpool, &annunci, "SELECT * FROM public.annunci")
|
||||||
return annunci
|
return annunci
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *DbHandler) InsertAnnunciInDB(annunci AnnunciParsed) {
|
func (h *DbHandler) InsertAnnunciInDB(annunci typedefs.AnnunciParsed) {
|
||||||
|
|
||||||
//SET ALL WEB TO FALSE
|
//SET ALL WEB TO FALSE
|
||||||
_, err := h.Dbpool.Exec(h.Ctx, "UPDATE public.annunci SET web = false")
|
_, err := h.Dbpool.Exec(h.Ctx, "UPDATE public.annunci SET web = false")
|
||||||
|
|
@ -243,7 +244,7 @@ func (h *DbHandler) ClearRecords() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *DbHandler) SetFromBkp(annunci AnnunciParsed) {
|
func (h *DbHandler) SetFromBkp(annunci typedefs.AnnunciParsed) {
|
||||||
h.ClearRecords()
|
h.ClearRecords()
|
||||||
|
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"backend/typedefs"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -10,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func From_Backup() XmlBkp {
|
func From_Backup() typedefs.XmlBkp {
|
||||||
//open the bkp.xml file
|
//open the bkp.xml file
|
||||||
xmlFile, err := os.Open("bkp.xml")
|
xmlFile, err := os.Open("bkp.xml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -22,18 +23,18 @@ func From_Backup() XmlBkp {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
var miogest XmlBkp
|
var miogest typedefs.XmlBkp
|
||||||
xml.Unmarshal(byteValue, &miogest)
|
xml.Unmarshal(byteValue, &miogest)
|
||||||
return miogest
|
return miogest
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseUpdateBkp() AnnunciParsed {
|
func ParseUpdateBkp() typedefs.AnnunciParsed {
|
||||||
|
|
||||||
miogest := From_Backup()
|
miogest := From_Backup()
|
||||||
|
|
||||||
var AnnunciArray AnnunciParsed
|
var AnnunciArray typedefs.AnnunciParsed
|
||||||
extractedData := make(chan AnnuncioParsed)
|
extractedData := make(chan typedefs.AnnuncioParsed)
|
||||||
defaultCaratteristiche := Miogest.GetCaratteristiche()
|
defaultCaratteristiche := Miogest.GetCaratteristiche()
|
||||||
defaultCategorie := Miogest.GetCategorie()
|
defaultCategorie := Miogest.GetCategorie()
|
||||||
|
|
||||||
|
|
@ -59,9 +60,9 @@ func ParseUpdateBkp() AnnunciParsed {
|
||||||
return AnnunciArray
|
return AnnunciArray
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractData_bkp(annuncio AnnuncioBKP, extractedData chan AnnuncioParsed, defaultCaratteristiche ListaCaratteristiche, defaultCategorie []Categoria) {
|
func extractData_bkp(annuncio typedefs.AnnuncioBKP, extractedData chan typedefs.AnnuncioParsed, defaultCaratteristiche typedefs.ListaCaratteristiche, defaultCategorie []typedefs.Categoria) {
|
||||||
|
|
||||||
var tmp AnnuncioParsed = AnnuncioParsed{}
|
var tmp typedefs.AnnuncioParsed = typedefs.AnnuncioParsed{}
|
||||||
|
|
||||||
codice := RemoveWhitespace(GetStringValue(annuncio.Codice))
|
codice := RemoveWhitespace(GetStringValue(annuncio.Codice))
|
||||||
tmp.Codice = codice
|
tmp.Codice = codice
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"backend/typedefs"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -17,9 +18,9 @@ func NewImageRefManager() *ImageRefManager {
|
||||||
return &ImageRefManager{}
|
return &ImageRefManager{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImageRefManager) GetImagesRef() ([]MiogestImagesRef_Table, error) {
|
func (i *ImageRefManager) GetImagesRef() ([]typedefs.MiogestImagesRef_Table, error) {
|
||||||
|
|
||||||
var images []MiogestImagesRef_Table
|
var images []typedefs.MiogestImagesRef_Table
|
||||||
|
|
||||||
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &images, "SELECT * FROM public.miogest_images_ref")
|
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &images, "SELECT * FROM public.miogest_images_ref")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -29,7 +30,7 @@ func (i *ImageRefManager) GetImagesRef() ([]MiogestImagesRef_Table, error) {
|
||||||
return images, nil
|
return images, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImageRefManager) InsertImagesRef(annunci *AnnunciXML) error {
|
func (i *ImageRefManager) InsertImagesRef(annunci *typedefs.AnnunciXML) error {
|
||||||
|
|
||||||
batch := &pgx.Batch{}
|
batch := &pgx.Batch{}
|
||||||
|
|
||||||
|
|
@ -48,7 +49,7 @@ func (i *ImageRefManager) InsertImagesRef(annunci *AnnunciXML) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImageRefManager) FindIsUpdate(annunci *AnnunciXML) ([]string, error) {
|
func (i *ImageRefManager) FindIsUpdate(annunci *typedefs.AnnunciXML) ([]string, error) {
|
||||||
r, err := i.GetImagesRef()
|
r, err := i.GetImagesRef()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"backend/typedefs"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -85,7 +86,7 @@ func RemoveFromDb(ref string) error {
|
||||||
|
|
||||||
func RemoveExpired() error {
|
func RemoveExpired() error {
|
||||||
//get all expired files
|
//get all expired files
|
||||||
var items_db []Storageindex
|
var items_db []typedefs.Storageindex
|
||||||
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &items_db, "SELECT * FROM public.storageindex WHERE expires_at is not null and expires_at < NOW()")
|
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &items_db, "SELECT * FROM public.storageindex WHERE expires_at is not null and expires_at < NOW()")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get expired items: %w", err)
|
return fmt.Errorf("failed to get expired items: %w", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue