refactor: change 'mq' type from string to float64 and update related parsing logic
This commit is contained in:
parent
e9c26d8b42
commit
0ecd7ce30d
8 changed files with 52 additions and 30 deletions
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -120,7 +121,15 @@ func extractData_bkp(annuncio typesdefs.AnnuncioBKP, extractedData chan typesdef
|
||||||
*tmp.Categorie = resultArray
|
*tmp.Categorie = resultArray
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp.Mq = utils.CommaToDot(annuncio.Mq)
|
if annuncio.Mq != nil {
|
||||||
|
replaced := strings.ReplaceAll(*annuncio.Mq, ",", ".")
|
||||||
|
if s, err := strconv.ParseFloat(replaced, 64); err == nil {
|
||||||
|
fmt.Printf("%T, %v\n", s, s)
|
||||||
|
tmp.Mq = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
tmp.Piano = annuncio.Piano
|
tmp.Piano = annuncio.Piano
|
||||||
tmp.Piano_palazzo = annuncio.PianoPalazzo
|
tmp.Piano_palazzo = annuncio.PianoPalazzo
|
||||||
tmp.Unita_condominio = annuncio.UnitaImmobiliari
|
tmp.Unita_condominio = annuncio.UnitaImmobiliari
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -367,8 +368,12 @@ func processDatiImmobile(tmp *typesdefs.AnnuncioParsed, annuncio *typesdefs.Annu
|
||||||
tmp.Prezzo = parser.ParsePrezzo(annuncio.Prezzo)
|
tmp.Prezzo = parser.ParsePrezzo(annuncio.Prezzo)
|
||||||
tmp.Classe = annuncio.Classe
|
tmp.Classe = annuncio.Classe
|
||||||
if annuncio.Mq != nil {
|
if annuncio.Mq != nil {
|
||||||
replaced := strings.ReplaceAll(*annuncio.Mq, ",", "")
|
replaced := strings.ReplaceAll(*annuncio.Mq, ",", ".")
|
||||||
tmp.Mq = &replaced
|
if s, err := strconv.ParseFloat(replaced, 64); err == nil {
|
||||||
|
fmt.Printf("%T, %v\n", s, s)
|
||||||
|
tmp.Mq = &s
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
tmp.Piano = annuncio.Piano
|
tmp.Piano = annuncio.Piano
|
||||||
tmp.Piano_palazzo = annuncio.PianiCondominio
|
tmp.Piano_palazzo = annuncio.PianiCondominio
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ type AnnuncioParsed struct {
|
||||||
Lon *string
|
Lon *string
|
||||||
Lon_secondario *string
|
Lon_secondario *string
|
||||||
Modificato_il *time.Time
|
Modificato_il *time.Time
|
||||||
Mq *string
|
Mq *float64
|
||||||
Piano_palazzo *string
|
Piano_palazzo *string
|
||||||
Piano *string
|
Piano *string
|
||||||
Numero_postiauto *string
|
Numero_postiauto *string
|
||||||
|
|
@ -288,7 +288,7 @@ type AnnunciDB struct {
|
||||||
Anno *string
|
Anno *string
|
||||||
Consegna *string
|
Consegna *string
|
||||||
Classe *string
|
Classe *string
|
||||||
Mq *string
|
Mq *float64
|
||||||
Piano *string
|
Piano *string
|
||||||
Piano_palazzo *int
|
Piano_palazzo *int
|
||||||
Unita_condominio *int
|
Unita_condominio *int
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ module.exports = {
|
||||||
password: "rootpost",
|
password: "rootpost",
|
||||||
port: 5433,
|
port: 5433,
|
||||||
},
|
},
|
||||||
|
|
||||||
typeFilter: (pgType) => !ignoredTables.includes(pgType.name),
|
typeFilter: (pgType) => !ignoredTables.includes(pgType.name),
|
||||||
preDeleteOutputFolder: true,
|
preDeleteOutputFolder: true,
|
||||||
outputPath: "./src/schemas",
|
outputPath: "./src/schemas",
|
||||||
|
|
@ -18,7 +19,9 @@ module.exports = {
|
||||||
customTypeMap: {
|
customTypeMap: {
|
||||||
"pg_catalog.tsvector": "string",
|
"pg_catalog.tsvector": "string",
|
||||||
"pg_catalog.bpchar": "string",
|
"pg_catalog.bpchar": "string",
|
||||||
|
'pg_catalog.numeric': 'number',
|
||||||
//"pg_catalog.json": "string",
|
//"pg_catalog.json": "string",
|
||||||
},
|
},
|
||||||
preRenderHooks: [makeKyselyHook()],
|
preRenderHooks: [makeKyselyHook()],
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -339,7 +339,7 @@ export const CardAnnuncio = ({
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p className="font-medium">
|
<p className="font-medium">
|
||||||
{mq ? Number.parseFloat(mq) : 0}{" "}
|
{mq ? Number(mq).toLocaleString("it-IT") : "--"}{" "}
|
||||||
<span>
|
<span>
|
||||||
m<sup>2</sup>
|
m<sup>2</sup>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithMedia }) => {
|
||||||
locatore: z.string().nullable(),
|
locatore: z.string().nullable(),
|
||||||
lon: z.string().nullable(),
|
lon: z.string().nullable(),
|
||||||
lon_secondario: z.string().nullable(),
|
lon_secondario: z.string().nullable(),
|
||||||
mq: z.string().nullable(),
|
mq: z.number().nullable(),
|
||||||
numero: z.string().nullable(),
|
numero: z.string().nullable(),
|
||||||
numero_bagni: z.number().nullable(),
|
numero_bagni: z.number().nullable(),
|
||||||
numero_balconi: z.number().nullable(),
|
numero_balconi: z.number().nullable(),
|
||||||
|
|
@ -1259,28 +1259,32 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithMedia }) => {
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="mq"
|
name="mq"
|
||||||
render={({ field }) => (
|
render={({ field }) => {
|
||||||
<FormItem>
|
const { value, onChange, ...rest } = field;
|
||||||
<div className="flex flex-wrap items-center gap-x-2">
|
return (
|
||||||
<FormLabel htmlFor="mq">Metri Quadri</FormLabel>{" "}
|
<FormItem>
|
||||||
<FormMessage />
|
<div className="flex flex-wrap items-center gap-x-2">
|
||||||
</div>
|
<FormLabel htmlFor="mq">Metri Quadri</FormLabel>{" "}
|
||||||
|
<FormMessage />
|
||||||
|
</div>
|
||||||
|
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<NumberInput
|
||||||
placeholder=""
|
decimalScale={2}
|
||||||
{...field}
|
{...rest}
|
||||||
id="mq"
|
decimalSeparator=","
|
||||||
onChange={(e) =>
|
defaultValue={value || undefined}
|
||||||
field.onChange(
|
fixedDecimalScale
|
||||||
e.target.value !== "" ? e.target.value : null,
|
id="mq"
|
||||||
)
|
min={0}
|
||||||
}
|
onValueChange={(v) => {
|
||||||
value={field.value || undefined}
|
onChange(v || null);
|
||||||
/>
|
}}
|
||||||
</FormControl>
|
/>
|
||||||
</FormItem>
|
</FormControl>
|
||||||
)}
|
</FormItem>
|
||||||
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
|
|
|
||||||
|
|
@ -487,7 +487,8 @@ const CardInfos = ({ data }: { data: Annunci }) => {
|
||||||
<div className="flex justify-center gap-2 rounded-md bg-primary-foreground p-2 text-primary">
|
<div className="flex justify-center gap-2 rounded-md bg-primary-foreground p-2 text-primary">
|
||||||
<Ruler />
|
<Ruler />
|
||||||
<span>
|
<span>
|
||||||
{data.mq} m<sup>2</sup>
|
{data.mq ? Number(data.mq).toLocaleString("it-IT") : "--"} m
|
||||||
|
<sup>2</sup>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ export default interface AnnunciTable {
|
||||||
|
|
||||||
classe: ColumnType<string | null, string | null, string | null>;
|
classe: ColumnType<string | null, string | null, string | null>;
|
||||||
|
|
||||||
mq: ColumnType<string | null, string | null, string | null>;
|
mq: ColumnType<number | null, number | null, number | null>;
|
||||||
|
|
||||||
piano: ColumnType<string | null, string | null, string | null>;
|
piano: ColumnType<string | null, string | null, string | null>;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue