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"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -120,7 +121,15 @@ func extractData_bkp(annuncio typesdefs.AnnuncioBKP, extractedData chan typesdef
|
|||
*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_palazzo = annuncio.PianoPalazzo
|
||||
tmp.Unita_condominio = annuncio.UnitaImmobiliari
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -367,8 +368,12 @@ func processDatiImmobile(tmp *typesdefs.AnnuncioParsed, annuncio *typesdefs.Annu
|
|||
tmp.Prezzo = parser.ParsePrezzo(annuncio.Prezzo)
|
||||
tmp.Classe = annuncio.Classe
|
||||
if annuncio.Mq != nil {
|
||||
replaced := strings.ReplaceAll(*annuncio.Mq, ",", "")
|
||||
tmp.Mq = &replaced
|
||||
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_palazzo = annuncio.PianiCondominio
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ type AnnuncioParsed struct {
|
|||
Lon *string
|
||||
Lon_secondario *string
|
||||
Modificato_il *time.Time
|
||||
Mq *string
|
||||
Mq *float64
|
||||
Piano_palazzo *string
|
||||
Piano *string
|
||||
Numero_postiauto *string
|
||||
|
|
@ -288,7 +288,7 @@ type AnnunciDB struct {
|
|||
Anno *string
|
||||
Consegna *string
|
||||
Classe *string
|
||||
Mq *string
|
||||
Mq *float64
|
||||
Piano *string
|
||||
Piano_palazzo *int
|
||||
Unita_condominio *int
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ module.exports = {
|
|||
password: "rootpost",
|
||||
port: 5433,
|
||||
},
|
||||
|
||||
typeFilter: (pgType) => !ignoredTables.includes(pgType.name),
|
||||
preDeleteOutputFolder: true,
|
||||
outputPath: "./src/schemas",
|
||||
|
|
@ -18,7 +19,9 @@ module.exports = {
|
|||
customTypeMap: {
|
||||
"pg_catalog.tsvector": "string",
|
||||
"pg_catalog.bpchar": "string",
|
||||
'pg_catalog.numeric': 'number',
|
||||
//"pg_catalog.json": "string",
|
||||
},
|
||||
preRenderHooks: [makeKyselyHook()],
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ export const CardAnnuncio = ({
|
|||
|
||||
<div>
|
||||
<p className="font-medium">
|
||||
{mq ? Number.parseFloat(mq) : 0}{" "}
|
||||
{mq ? Number(mq).toLocaleString("it-IT") : "--"}{" "}
|
||||
<span>
|
||||
m<sup>2</sup>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithMedia }) => {
|
|||
locatore: z.string().nullable(),
|
||||
lon: z.string().nullable(),
|
||||
lon_secondario: z.string().nullable(),
|
||||
mq: z.string().nullable(),
|
||||
mq: z.number().nullable(),
|
||||
numero: z.string().nullable(),
|
||||
numero_bagni: z.number().nullable(),
|
||||
numero_balconi: z.number().nullable(),
|
||||
|
|
@ -1259,7 +1259,9 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithMedia }) => {
|
|||
<FormField
|
||||
control={form.control}
|
||||
name="mq"
|
||||
render={({ field }) => (
|
||||
render={({ field }) => {
|
||||
const { value, onChange, ...rest } = field;
|
||||
return (
|
||||
<FormItem>
|
||||
<div className="flex flex-wrap items-center gap-x-2">
|
||||
<FormLabel htmlFor="mq">Metri Quadri</FormLabel>{" "}
|
||||
|
|
@ -1267,20 +1269,22 @@ export const AnnuncioEditForm = ({ data }: { data: AnnunciWithMedia }) => {
|
|||
</div>
|
||||
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder=""
|
||||
{...field}
|
||||
<NumberInput
|
||||
decimalScale={2}
|
||||
{...rest}
|
||||
decimalSeparator=","
|
||||
defaultValue={value || undefined}
|
||||
fixedDecimalScale
|
||||
id="mq"
|
||||
onChange={(e) =>
|
||||
field.onChange(
|
||||
e.target.value !== "" ? e.target.value : null,
|
||||
)
|
||||
}
|
||||
value={field.value || undefined}
|
||||
min={0}
|
||||
onValueChange={(v) => {
|
||||
onChange(v || null);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
);
|
||||
}}
|
||||
/>
|
||||
|
||||
<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">
|
||||
<Ruler />
|
||||
<span>
|
||||
{data.mq} m<sup>2</sup>
|
||||
{data.mq ? Number(data.mq).toLocaleString("it-IT") : "--"} m
|
||||
<sup>2</sup>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ export default interface AnnunciTable {
|
|||
|
||||
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>;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue