Skip to content

Commit 70eb956

Browse files
authored
Merge pull request #189 from Lemoncode/Feature/#182-add-reservoirs-by-river-basin
Feature/#182 add reservoirs by river basin
2 parents 6f79615 + f3c7de6 commit 70eb956

20 files changed

Lines changed: 301 additions & 18 deletions

front/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { EmbalsesCuencaPod, getEmbalsesPorCuenca } from "@/pods/embalse-cuenca";
2+
import { cuencas } from "@/core/constants";
3+
import { Metadata } from "next";
4+
import { mapLookupListFromApiToViewModel } from "@/common/mappers";
5+
6+
interface Props {
7+
params: Promise<{ cuenca: string }>;
8+
}
9+
10+
const getCuencaBySlug = (slug: string) => {
11+
return Object.values(cuencas).find((cuenca) => cuenca.slug === slug);
12+
};
13+
14+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
15+
const { cuenca } = await params;
16+
const datosCuenca = getCuencaBySlug(cuenca);
17+
18+
if (!datosCuenca) {
19+
return {};
20+
}
21+
22+
return {
23+
title: `Embalses de ${datosCuenca.nombre}`,
24+
};
25+
}
26+
27+
export default async function EmbalseCuencaListadoPage({
28+
params,
29+
}: Props): Promise<React.JSX.Element> {
30+
const { cuenca } = await params;
31+
const datosCuenca = getCuencaBySlug(cuenca);
32+
33+
const embalsesPorCuencaDesdeApi = await getEmbalsesPorCuenca(
34+
datosCuenca.nombre,
35+
);
36+
const embalsesPorCuenca = mapLookupListFromApiToViewModel(
37+
embalsesPorCuencaDesdeApi,
38+
);
39+
40+
return (
41+
<EmbalsesCuencaPod
42+
nombreCuenca={datosCuenca.nombre}
43+
embalses={embalsesPorCuenca}
44+
/>
45+
);
46+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mapLookupListFromApiToViewModel } from "@/common/mappers";
2+
import { EmbalseCuencaListPod } from "@/pods/embalse-cuenca-list";
3+
import { getRiverBasins } from "@/pods/embalse-cuenca-list/embalse-cuenca-list.repository";
4+
import { Metadata } from "next";
5+
6+
export const metadata: Metadata = {
7+
title: "Embalses por cuencas",
8+
};
9+
export default async function EmbalsesCuencasPage() {
10+
const cuencasAPI = await getRiverBasins();
11+
const cuencaList = mapLookupListFromApiToViewModel(cuencasAPI);
12+
13+
return <EmbalseCuencaListPod cuencaList={cuencaList} />;
14+
}

front/src/common/mappers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./lookup.mappers";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { LookupApi } from "@/common/models";
2+
import { Lookup } from "@content-island/api-client";
3+
4+
export const mapLookupListFromApiToViewModel = (
5+
lookupList: LookupApi[],
6+
): Lookup[] =>
7+
Array.isArray(lookupList) ? lookupList.map(mapLookupFromApiToViewModel) : [];
8+
9+
const mapLookupFromApiToViewModel = (lookup: LookupApi): Lookup => ({
10+
id: lookup._id,
11+
name: lookup.nombre,
12+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { LookupApi } from "./lookup.model";
2+
3+
export interface EmbalsesCuencaListApi {
4+
embalse_id: string;
5+
nombre: string;
6+
slug: string;
7+
cuenca: LookupApi;
8+
}
9+
10+
export interface EmbalsesCuencaList {
11+
id: string;
12+
name: string;
13+
slug?: string;
14+
}

front/src/common/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./lookup.model";
2+
export * from "./cuencas.model";

front/src/common/models/lookup.model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ export interface Lookup {
22
id: string;
33
name: string;
44
}
5+
6+
export interface LookupApi {
7+
_id: string;
8+
nombre: string;
9+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export const cuencas = {
2+
SEGURA: { nombre: "Segura", slug: "segura" },
3+
MINO_SIL: { nombre: "Miño - Sil", slug: "mino-sil" },
4+
EBRO: { nombre: "Ebro", slug: "ebro" },
5+
GUADALQUIVIR: { nombre: "Guadalquivir", slug: "guadalquivir" },
6+
JUCAR: { nombre: "Júcar", slug: "jucar" },
7+
DUERO: { nombre: "Duero", slug: "duero" },
8+
CANTABRICO_ORIENTAL: {
9+
nombre: "Cantábrico Oriental",
10+
slug: "cantabrico-oriental",
11+
},
12+
CUENCA_MEDITERRANEA_ANDALUZA: {
13+
nombre: "Cuenca Mediterránea Andaluza",
14+
slug: "cuenca-mediterranea-andaluza",
15+
},
16+
GUADIANA: { nombre: "Guadiana", slug: "guadiana" },
17+
CANTABRICO_OCCIDENTAL: {
18+
nombre: "Cantábrico Occidental",
19+
slug: "cantabrico-occidental",
20+
},
21+
TINTO_ODIEL_Y_PIEDRAS: {
22+
nombre: "Tinto, Odiel y Piedras",
23+
slug: "tinto-odiel-y-piedras",
24+
},
25+
TAJO: { nombre: "Tajo", slug: "tajo" },
26+
GALICIA_COSTA: { nombre: "Galicia Costa", slug: "galicia-costa" },
27+
GUADALETE_BARBATE: { nombre: "Guadalete-Barbate", slug: "guadalete-barbate" },
28+
CUENCAS_INTERNAS_DEL_PAIS_VASCO: {
29+
nombre: "Cuencas Internas del País Vasco",
30+
slug: "cuencas-internas-del-pais-vasco",
31+
},
32+
CUENCAS_INTERNAS_DE_CATALUNA: {
33+
nombre: "Cuencas Internas de Cataluña",
34+
slug: "cuencas-internas-de-cataluna",
35+
},
36+
} as const;

front/src/core/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./provincias.constants";
2+
export * from "./cuencas.constants";

0 commit comments

Comments
 (0)