From 6e61cfaa658cc5b12a92f2b7d1d7938c05969aba Mon Sep 17 00:00:00 2001 From: Miguel Teheran Date: Thu, 11 Jan 2024 20:21:21 -0500 Subject: [PATCH 1/2] updating documentation --- api/wwwroot/index.html | 547 +++++++++++++++++++++++------------------ 1 file changed, 307 insertions(+), 240 deletions(-) diff --git a/api/wwwroot/index.html b/api/wwwroot/index.html index c95ac95..37c606a 100644 --- a/api/wwwroot/index.html +++ b/api/wwwroot/index.html @@ -74,48 +74,54 @@
-
-

Api Colombia

-
+          
+

Api Colombia

+
     View Repository
 
     https://github.com/Mteheran/api-colombia
@@ -123,45 +129,44 @@ 

Api Colombia

View Swagger https://api-colombia.com/swagger/index.html -
-

- API Colombia is a public RESTful API that enable users to obtain a variety of public information about the country "Colombia". -

-

Project Support Features

-

-

    -
  • - Minimal API's endpoints to get information about : -
  • -
      -
    1. General information about the country.
    2. -
    3. Departments/States.
    4. -
    5. Region.
    6. -
    7. Cities.
    8. -
    9. Presidents.
    10. -
    11. Tourist attractions.
    12. -
    -
  • Swagger documentation.
  • -
  • Does not requiere authentications.
  • -
  • You can obtain the pageList endpoints that return -
    the paged information. -
    add to the end of each endpoint /pagedList -

    - example: -
    - /api/{version}/city/pagedList -

    -
  • -
-

-
-
-

Get info Colombia

-
+                
+

+ API Colombia is a public RESTful API that enable users to obtain a variety of public information about the country "Colombia". +

+

Project Support Features

+

+

    +
  • + Minimal API's endpoints to get information about : +
  • +
      +
    1. General information about the country.
    2. +
    3. Departments/States.
    4. +
    5. Region.
    6. +
    7. Cities.
    8. +
    9. Presidents.
    10. +
    11. Tourist attractions.
    12. +
    +
  • Swagger documentation.
  • +
  • Does not requiere authentications.
  • +
  • + You can obtain the pageList endpoints that return +
    the paged information. +
    add to the end of each endpoint /pagedList +

    + example: +
    + /api/{version}/city/pagedList +

    +
  • +
+

+
+
+

Get info Colombia

+
       Get info Colombia
-      
+              
   {
   "id": 1,
   "name": "Colombia",
@@ -201,28 +206,24 @@ 

Get info Colombia

"presidents": null }
-
-

- Get the information of Colombia -
- /api/{version}/country/Colombia -

+
+

+ Get the information of Colombia +
+ /api/{version}/country/Colombia +

-
-

Get departament

-
+          
+

Get departament

+
       Get departament
   
-

- Get the list of all the departments in Colombia
- /api/{version}/Department -

-
-

+              

+ Get the list of all the departments in Colombia
+ /api/{version}/Department +

+
+

   {
   "id": 9,
   "name": "Caquetá",
@@ -245,20 +246,18 @@ 

Get departament

"cities": null }
-
-
-

Get Region

-
+          
+
+

Get Region

+
       Get Region
   
-

- Get the list of all regions in Colombia
- /api/{version}/Region -

-
-

+              

+ Get the list of all regions in Colombia
+ /api/{version}/Region +

+
+

 {
 "id": 1,
 "name": "Caribe",
@@ -266,22 +265,20 @@ 

Get Region

"departments": null }
-
-
-

Get touristic attraction

-
+          
+
+

Get touristic attraction

+
       Get touristic attraction
   
-                  
-

- Get the list of all the touristic attractions in Colombia -
- /api/{version}/TouristicAttraction -

-
-
 
+                  
+

+ Get the list of all the touristic attractions in Colombia +
+ /api/{version}/TouristicAttraction +

+
+
 
 {
 "id": 1,
 "name": "Museo del oro",
@@ -307,20 +304,18 @@ 

Get touristic attraction

-

Get president

-
+              

Get president

+
       Get Presidents
   
-                  
-

- Get the list of all the presidents in Colombia -
- /api/{version}/President -

-
-

+                  
+

+ Get the list of all the presidents in Colombia +
+ /api/{version}/President +

+
+

 {
 "id": 1,
 "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/63/Jos%C3%A9_Mar%C3%ADa_Campo_Serrano_1.jpg/500px-Jos%C3%A9_Mar%C3%ADa_Campo_Serrano_1.jpg",
@@ -350,20 +345,18 @@ 

Get president

-

GET Natural Area

-
+              

GET Natural Area

+
       GET Natural Area
   
-                  
-

- This endpoint returns a list of natural areas in Colombia -
- /api/{version}/NaturalArea -

-
-

+                  
+

+ This endpoint returns a list of natural areas in Colombia +
+ /api/{version}/NaturalArea +

+
+

 { "id": 1, 
 "areaGroupId": 6, 
 "categoryNaturalAreaId": 7, 
@@ -403,20 +396,18 @@ 

GET Natural Area

-

GET Category Natural Area

-
+              

GET Category Natural Area

+
       GET Category Natural Area
   
-                  
-

- This endpoint returns a list of category natural areas in Colombia -
- /api/{version}/CategoryNaturalArea -

-
-

+                  
+

+ This endpoint returns a list of category natural areas in Colombia +
+ /api/{version}/CategoryNaturalArea +

+
+

 {
   "id": 1,
   "name": "Área Natural Única",
@@ -436,20 +427,18 @@ 

GET Category Natural Area

-

GET Map

-
+              

GET Map

+
       GET Map
   
-                  
-

- This endpoint returns a list of Map -
- /api/{version}/Map -

-
-

+                  
+

+ This endpoint returns a list of Map +
+ /api/{version}/Map +

+
+

 {
 "id": 2,
 "name": "Mapa Oficial Político Administrativo de Colombia",
@@ -468,20 +457,18 @@ 

GET Map

-

GET Invasive Specie

-
+              

GET Invasive Specie

+
       GET Invasive Specie
   
-                  
-

- This endpoint returns a list of Invasive Specie -
- /api/{version}/Invasivespecie -

-
-

+                  
+

+ This endpoint returns a list of Invasive Specie +
+ /api/{version}/Invasivespecie +

+
+

 {
   "id": 1,
   "name": "Acacia negra, gris",
@@ -496,20 +483,18 @@ 

GET Invasive Specie

-

GET Native Community

-
+              

GET Native Community

+
       GET Native Community
   
-                  
-

- This endpoint returns a list of Native Community -
- /api/{version}/NativeCommunity -

-
-

+                  
+

+ This endpoint returns a list of Native Community +
+ /api/{version}/NativeCommunity +

+
+

 {
   "id": 1,
   "name": "Achagua Piapoco",
@@ -520,64 +505,146 @@ 

GET Native Community

-
-

Contributors

-

Thanks goes to these wonderful people

-
-
+
+

GET Airport

+
+      GET Airport
+  
+                  
+

+ This endpoint returns a list of Airports +
+ /api/{version}/Airport +

+
+

+    {
+    "id": 1,
+    "name": "Aeropuerto Internacional El Edén",
+    "iataCode": "AXM",
+    "oaciCode": "SKAR",
+    "type": "Internacional",
+    "deparmentId": 25,
+    "department": {
+    "id": 25,
+    "name": "Quindío",
+    "description": "Quindío, también llamado El Quindío, es uno de los treinta y dos departamentos que, junto con Bogotá, Distrito Capital, forman la República de Colombia. Su capital es Armenia. Está ubicado en el centro-oeste del país, en la región andina, limitando al norte con Risaralda, al este con Tolima y al oeste con Valle del Cauca. Con 1845 km² es el segundo departamento menos extenso —por delante de San Andrés y Providencia— y con 306 hab/km², el tercero más densamente poblado, por detrás de San Andrés y Providencia y Atlántico. Pertenece al eje cafetero y a la región paisa",
+    "cityCapitalId": 885,
+    "municipalities": 12,
+    "surface": 1845,
+    "population": 569569,
+    "phonePrefix": "6",
+    "countryId": 1,
+    "cityCapital": null,
+    "country": null,
+    "cities": null,
+    "regionId": 5,
+    "region": null,
+    "naturalAreas": null,
+    "maps": null,
+    "indigenousReservations": null,
+    "airports": [
+    null
+    ]
+    },
+    "cityId": 885,
+    "city": {
+    "id": 885,
+    "name": "Armenia",
+    "description": "Armenia es un municipio colombiano, capital del departamento del Quindío y núcleo económico de su área metropolitana. Es una de las principales ciudades del eje cafetero colombiano, la región paisa y el Paisaje Cultural Cafetero.4​ Fundada en 1889 durante la colonización antioqueña, basó su economía en la agricultura",
+    "surface": 121,
+    "population": 316926,
+    "postalCode": "630001",
+    "departmentId": 25,
+    "department": null,
+    "touristAttractions": null,
+    "presidents": null,
+    "indigenousReservations": null,
+    "airports": [
+    null
+    ]
+    },
+    "latitude": -75.7659806671205,
+    "longitude": 4.4532428642135
+    }
+
+            
+
+
+

GET Constitution Article

+
+      GET Constitution Article
+  
+                  
+

+ This endpoint returns a list of Article in the constitution +
+ /api/{version}/constitutionarticle +

+
+

+    {
+    "id": 1,
+    "titleNumber": 1,
+    "title": "DE LOS PRINCIPIOS FUNDAMENTALES",
+    "chapterNumber": 1,
+    "chapter": "DE LOS PRINCIPIOS FUNDAMENTALES",
+    "articleNumber": 1,
+    "content": "Colombia es un Estado social de derecho, organizado en forma de República unitaria, descentralizada, con autonomía de sus entidades territoriales, democrática, participativa y pluralista, fundada en el respeto de la dignidad humana, en el trabajo y la solidaridad de las personas que la integran y en la prevalencia del interés general."
+    }
+
+
+
+
+

Contributors

+

Thanks goes to these wonderful people

+
+
- Rina Plata - + Rina Plata +
Rina Plata
-
-
+
+
- Mario Botero - + Mario Botero +
Mario Botero
-
-
+
+
- Miguel Teheran - + Miguel Teheran +
Miguel Teheran
-
-
- - Veronica Guaman - +
+
+ + Veronica Guaman +
Vero Guaman
-
-
- - Veronica Guaman - -
Alejandro Herreño
-
-
- - Lili Valencia - -
Lili Valencia
-
+
+
+ + Veronica Guaman + +
Alejandro Herreño
+
+
+ + Lili Valencia + +
Lili Valencia
+
+
-
+
+
-
-
From 35d27e05586903db77ebd4e3d1ac36dc48284587 Mon Sep 17 00:00:00 2001 From: Miguel Teheran Date: Mon, 4 Mar 2024 20:52:03 -0500 Subject: [PATCH 2/2] adding radio entity --- api/DBContext.cs | 2 + api/Data/Configs/RadioConfig.cs | 23 + .../20240305014735_radio.Designer.cs | 830 ++++++++++++++++++ api/Migrations/20240305014735_radio.cs | 49 ++ api/Migrations/DBContextModelSnapshot.cs | 50 ++ api/Models/City.cs | 1 + api/Models/Radio.cs | 14 + api/Program.cs | 1 - api/Routes/RadioRoutes.cs | 118 +++ api/Utils/Messages.cs | 14 + api/Utils/Util.cs | 1 + api/api.csproj | 12 +- 12 files changed, 1108 insertions(+), 7 deletions(-) create mode 100644 api/Data/Configs/RadioConfig.cs create mode 100644 api/Migrations/20240305014735_radio.Designer.cs create mode 100644 api/Migrations/20240305014735_radio.cs create mode 100644 api/Models/Radio.cs create mode 100644 api/Routes/RadioRoutes.cs diff --git a/api/DBContext.cs b/api/DBContext.cs index 313d1b7..78449f6 100644 --- a/api/DBContext.cs +++ b/api/DBContext.cs @@ -19,6 +19,7 @@ public class DBContext : DbContext public DbSet IndigenousReservations { get; set; } public DbSet Airports { get; set; } public DbSet ConstitutionArticles { get; set; } + public DbSet Radios { get; set; } public DBContext(DbContextOptions options) : base(options) { @@ -41,6 +42,7 @@ protected override void OnModelCreating(ModelBuilder builder) builder.ApplyConfiguration(new IndigenousReservationConfig()); builder.ApplyConfiguration(new AirportConfig()); builder.ApplyConfiguration(new ConstitutionArticleConfig()); + builder.ApplyConfiguration(new RadioConfig()); base.OnModelCreating(builder); } diff --git a/api/Data/Configs/RadioConfig.cs b/api/Data/Configs/RadioConfig.cs new file mode 100644 index 0000000..98dface --- /dev/null +++ b/api/Data/Configs/RadioConfig.cs @@ -0,0 +1,23 @@ +using api.Models; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore; + +namespace api.Data.Configs +{ + public class RadioConfig : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder radio) + { + radio.ToTable("Radio"); + radio.HasKey(p => p.Id); + radio.Property(p => p.Id).ValueGeneratedOnAdd(); + radio.Property(p => p.Name).IsRequired().HasMaxLength(150); + radio.Property(p => p.Frequency).IsRequired().HasMaxLength(10000); + radio.Property(p => p.Url).IsRequired(false); + radio.Property(p => p.Streamers).IsRequired(false); + radio.Property(p => p.CityId); + radio.HasOne(p => p.City).WithMany(p => p.Radios).HasForeignKey(p => p.CityId); + + } + } +} diff --git a/api/Migrations/20240305014735_radio.Designer.cs b/api/Migrations/20240305014735_radio.Designer.cs new file mode 100644 index 0000000..11a61ae --- /dev/null +++ b/api/Migrations/20240305014735_radio.Designer.cs @@ -0,0 +1,830 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using api; + +#nullable disable + +namespace api.Migrations +{ + [DbContext(typeof(DBContext))] + [Migration("20240305014735_radio")] + partial class radio + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.7") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("api.Models.Airport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CityId") + .HasColumnType("integer"); + + b.Property("DeparmentId") + .HasColumnType("integer"); + + b.Property("IataCode") + .IsRequired() + .HasColumnType("text"); + + b.Property("Latitude") + .HasColumnType("double precision"); + + b.Property("Longitude") + .HasColumnType("double precision"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("OaciCode") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CityId"); + + b.HasIndex("DeparmentId"); + + b.ToTable("Airport", (string)null); + }); + + modelBuilder.Entity("api.Models.CategoryNaturalArea", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.HasKey("Id"); + + b.ToTable("CategoryNaturalArea", (string)null); + }); + + modelBuilder.Entity("api.Models.City", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DepartmentId") + .HasColumnType("integer"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("Population") + .HasColumnType("real"); + + b.Property("PostalCode") + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("Surface") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("DepartmentId"); + + b.ToTable("City", (string)null); + }); + + modelBuilder.Entity("api.Models.ConstitutionArticle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ArticleNumber") + .HasColumnType("integer"); + + b.Property("Chapter") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("ChapterNumber") + .HasColumnType("integer"); + + b.Property("Content") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("TitleNumber") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("ConstitutionArticle", (string)null); + }); + + modelBuilder.Entity("api.Models.Country", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AircraftPrefix") + .HasMaxLength(5) + .HasColumnType("character varying(5)"); + + b.Property("Borders") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("Currency") + .HasMaxLength(15) + .HasColumnType("character varying(15)"); + + b.Property("CurrencyCode") + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("CurrencySymbol") + .HasMaxLength(2) + .HasColumnType("character varying(2)"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Flags") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("ISOCode") + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("InternetDomain") + .HasColumnType("text"); + + b.Property("Languages") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("PhonePrefix") + .HasMaxLength(5) + .HasColumnType("character varying(5)"); + + b.Property("Population") + .HasColumnType("real"); + + b.Property("RadioPrefix") + .HasMaxLength(5) + .HasColumnType("character varying(5)"); + + b.Property("Region") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("StateCapital") + .HasColumnType("text"); + + b.Property("SubRegion") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Surface") + .HasColumnType("real"); + + b.Property("TimeZone") + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.HasKey("Id"); + + b.ToTable("Country", (string)null); + }); + + modelBuilder.Entity("api.Models.Department", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CityCapitalId") + .HasColumnType("integer"); + + b.Property("CityCapitalId1") + .HasColumnType("integer"); + + b.Property("CountryId") + .HasColumnType("integer"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Municipalities") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("PhonePrefix") + .HasMaxLength(5) + .HasColumnType("character varying(5)"); + + b.Property("Population") + .HasColumnType("real"); + + b.Property("RegionId") + .HasColumnType("integer"); + + b.Property("Surface") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("CityCapitalId1"); + + b.HasIndex("CountryId"); + + b.HasIndex("RegionId"); + + b.ToTable("Department", (string)null); + }); + + modelBuilder.Entity("api.Models.IndigenousReservation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AdministrativeActDate") + .HasColumnType("timestamp with time zone"); + + b.Property("AdministrativeActNumber") + .HasColumnType("integer"); + + b.Property("AdministrativeActType") + .HasColumnType("text"); + + b.Property("CityId") + .HasColumnType("integer"); + + b.Property("Code") + .HasColumnType("text"); + + b.Property("DeparmentId") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("NativeCommunityId") + .HasColumnType("integer"); + + b.Property("ProcedureType") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CityId"); + + b.HasIndex("DeparmentId"); + + b.HasIndex("NativeCommunityId"); + + b.ToTable("IndigenousReservation", (string)null); + }); + + modelBuilder.Entity("api.Models.InvasiveSpecie", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CommonNames") + .HasColumnType("text"); + + b.Property("Impact") + .IsRequired() + .HasColumnType("text"); + + b.Property("Manage") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("RiskLevel") + .HasColumnType("integer"); + + b.Property("ScientificName") + .HasColumnType("text"); + + b.Property("UrlImage") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("InvasiveSpecie", (string)null); + }); + + modelBuilder.Entity("api.Models.Map", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DepartmentId") + .HasColumnType("integer"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.Property("UrlImages") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("UrlSource") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("DepartmentId"); + + b.ToTable("Map", (string)null); + }); + + modelBuilder.Entity("api.Models.NativeCommunity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Images") + .HasColumnType("text[]"); + + b.Property("Languages") + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.HasKey("Id"); + + b.ToTable("NativeCommunity", (string)null); + }); + + modelBuilder.Entity("api.Models.NaturalArea", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AreaGroupId") + .HasColumnType("integer"); + + b.Property("CategoryNaturalAreaId") + .HasColumnType("integer"); + + b.Property("DaneCode") + .HasColumnType("integer"); + + b.Property("DepartmentId") + .HasColumnType("integer"); + + b.Property("LandArea") + .HasColumnType("double precision"); + + b.Property("MaritimeArea") + .HasColumnType("double precision"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryNaturalAreaId"); + + b.HasIndex("DepartmentId"); + + b.ToTable("NaturalArea", (string)null); + }); + + modelBuilder.Entity("api.Models.President", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CityId") + .HasColumnType("integer"); + + b.Property("CountryId") + .HasColumnType("integer"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("EndPeriodDate") + .HasColumnType("date"); + + b.Property("Image") + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("PoliticalParty") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartPeriodDate") + .HasColumnType("date"); + + b.HasKey("Id"); + + b.HasIndex("CityId"); + + b.HasIndex("CountryId"); + + b.ToTable("President", (string)null); + }); + + modelBuilder.Entity("api.Models.Radio", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Band") + .IsRequired() + .HasColumnType("text"); + + b.Property("CityId") + .HasColumnType("integer"); + + b.Property("Frequency") + .HasMaxLength(10000) + .HasColumnType("double precision"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("Streamers") + .HasColumnType("text[]"); + + b.Property("Url") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CityId"); + + b.ToTable("Radio", (string)null); + }); + + modelBuilder.Entity("api.Models.Region", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.HasKey("Id"); + + b.ToTable("Region", (string)null); + }); + + modelBuilder.Entity("api.Models.TouristAttraction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CityId") + .HasColumnType("integer"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Images") + .HasColumnType("text[]"); + + b.Property("Latitude") + .HasColumnType("text"); + + b.Property("Longitude") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.HasKey("Id"); + + b.HasIndex("CityId"); + + b.ToTable("TouristAttraction", (string)null); + }); + + modelBuilder.Entity("api.Models.Airport", b => + { + b.HasOne("api.Models.City", "City") + .WithMany("Airports") + .HasForeignKey("CityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("api.Models.Department", "Department") + .WithMany("Airports") + .HasForeignKey("DeparmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("City"); + + b.Navigation("Department"); + }); + + modelBuilder.Entity("api.Models.City", b => + { + b.HasOne("api.Models.Department", "Department") + .WithMany("Cities") + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Department"); + }); + + modelBuilder.Entity("api.Models.Department", b => + { + b.HasOne("api.Models.City", "CityCapital") + .WithMany() + .HasForeignKey("CityCapitalId1") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("api.Models.Country", "Country") + .WithMany("Departments") + .HasForeignKey("CountryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("api.Models.Region", "Region") + .WithMany("Departments") + .HasForeignKey("RegionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CityCapital"); + + b.Navigation("Country"); + + b.Navigation("Region"); + }); + + modelBuilder.Entity("api.Models.IndigenousReservation", b => + { + b.HasOne("api.Models.City", "City") + .WithMany("IndigenousReservations") + .HasForeignKey("CityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("api.Models.Department", "Department") + .WithMany("IndigenousReservations") + .HasForeignKey("DeparmentId"); + + b.HasOne("api.Models.NativeCommunity", "NativeCommunity") + .WithMany("IndigenousReservations") + .HasForeignKey("NativeCommunityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("City"); + + b.Navigation("Department"); + + b.Navigation("NativeCommunity"); + }); + + modelBuilder.Entity("api.Models.Map", b => + { + b.HasOne("api.Models.Department", "Department") + .WithMany("Maps") + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Department"); + }); + + modelBuilder.Entity("api.Models.NaturalArea", b => + { + b.HasOne("api.Models.CategoryNaturalArea", "CategoryNaturalArea") + .WithMany("NaturalAreas") + .HasForeignKey("CategoryNaturalAreaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("api.Models.Department", "Department") + .WithMany("NaturalAreas") + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CategoryNaturalArea"); + + b.Navigation("Department"); + }); + + modelBuilder.Entity("api.Models.President", b => + { + b.HasOne("api.Models.City", "City") + .WithMany("Presidents") + .HasForeignKey("CityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("api.Models.Country", null) + .WithMany("Presidents") + .HasForeignKey("CountryId"); + + b.Navigation("City"); + }); + + modelBuilder.Entity("api.Models.Radio", b => + { + b.HasOne("api.Models.City", "City") + .WithMany("Radios") + .HasForeignKey("CityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("City"); + }); + + modelBuilder.Entity("api.Models.TouristAttraction", b => + { + b.HasOne("api.Models.City", "City") + .WithMany("TouristAttractions") + .HasForeignKey("CityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("City"); + }); + + modelBuilder.Entity("api.Models.CategoryNaturalArea", b => + { + b.Navigation("NaturalAreas"); + }); + + modelBuilder.Entity("api.Models.City", b => + { + b.Navigation("Airports"); + + b.Navigation("IndigenousReservations"); + + b.Navigation("Presidents"); + + b.Navigation("Radios"); + + b.Navigation("TouristAttractions"); + }); + + modelBuilder.Entity("api.Models.Country", b => + { + b.Navigation("Departments"); + + b.Navigation("Presidents"); + }); + + modelBuilder.Entity("api.Models.Department", b => + { + b.Navigation("Airports"); + + b.Navigation("Cities"); + + b.Navigation("IndigenousReservations"); + + b.Navigation("Maps"); + + b.Navigation("NaturalAreas"); + }); + + modelBuilder.Entity("api.Models.NativeCommunity", b => + { + b.Navigation("IndigenousReservations"); + }); + + modelBuilder.Entity("api.Models.Region", b => + { + b.Navigation("Departments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/api/Migrations/20240305014735_radio.cs b/api/Migrations/20240305014735_radio.cs new file mode 100644 index 0000000..d425c35 --- /dev/null +++ b/api/Migrations/20240305014735_radio.cs @@ -0,0 +1,49 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace api.Migrations +{ + public partial class radio : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Radio", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "character varying(150)", maxLength: 150, nullable: false), + Frequency = table.Column(type: "double precision", maxLength: 10000, nullable: false), + Band = table.Column(type: "text", nullable: false), + CityId = table.Column(type: "integer", nullable: false), + Url = table.Column(type: "text", nullable: true), + Streamers = table.Column(type: "text[]", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Radio", x => x.Id); + table.ForeignKey( + name: "FK_Radio_City_CityId", + column: x => x.CityId, + principalTable: "City", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Radio_CityId", + table: "Radio", + column: "CityId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Radio"); + } + } +} diff --git a/api/Migrations/DBContextModelSnapshot.cs b/api/Migrations/DBContextModelSnapshot.cs index 2f72499..7d1f8be 100644 --- a/api/Migrations/DBContextModelSnapshot.cs +++ b/api/Migrations/DBContextModelSnapshot.cs @@ -533,6 +533,43 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("President", (string)null); }); + modelBuilder.Entity("api.Models.Radio", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Band") + .IsRequired() + .HasColumnType("text"); + + b.Property("CityId") + .HasColumnType("integer"); + + b.Property("Frequency") + .HasMaxLength(10000) + .HasColumnType("double precision"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("Streamers") + .HasColumnType("text[]"); + + b.Property("Url") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CityId"); + + b.ToTable("Radio", (string)null); + }); + modelBuilder.Entity("api.Models.Region", b => { b.Property("Id") @@ -716,6 +753,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("City"); }); + modelBuilder.Entity("api.Models.Radio", b => + { + b.HasOne("api.Models.City", "City") + .WithMany("Radios") + .HasForeignKey("CityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("City"); + }); + modelBuilder.Entity("api.Models.TouristAttraction", b => { b.HasOne("api.Models.City", "City") @@ -740,6 +788,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Presidents"); + b.Navigation("Radios"); + b.Navigation("TouristAttractions"); }); diff --git a/api/Models/City.cs b/api/Models/City.cs index f7c5af1..3394107 100644 --- a/api/Models/City.cs +++ b/api/Models/City.cs @@ -14,6 +14,7 @@ public class City public virtual ICollection Presidents { get; set; } public virtual ICollection IndigenousReservations { get; set; } public virtual ICollection Airports { get; set; } + public virtual ICollection Radios { get; set; } } } diff --git a/api/Models/Radio.cs b/api/Models/Radio.cs new file mode 100644 index 0000000..b9327f5 --- /dev/null +++ b/api/Models/Radio.cs @@ -0,0 +1,14 @@ +namespace api.Models +{ + public class Radio + { + public int Id { get; set; } + public string Name { get; set; } + public double Frequency { get; set; } + public string Band { get; set; } + public int CityId { get; set; } + public virtual City City { get; set; } + public Uri Url { get; set; } + public string[] Streamers { get; set;} + } +} diff --git a/api/Program.cs b/api/Program.cs index 9d9f1ea..7a3365c 100644 --- a/api/Program.cs +++ b/api/Program.cs @@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Http.Json; using api.Utils; using System.Net; -using api.Data.Configs; var builder = WebApplication.CreateBuilder(args); diff --git a/api/Routes/RadioRoutes.cs b/api/Routes/RadioRoutes.cs new file mode 100644 index 0000000..248c6a2 --- /dev/null +++ b/api/Routes/RadioRoutes.cs @@ -0,0 +1,118 @@ +using api.Models; +using api.Utils; +using Microsoft.EntityFrameworkCore; +using Swashbuckle.AspNetCore.Annotations; +using RadioMetadataMessages = api.Utils.Messages.EndpointMetadata.RadioEndpoint; + +namespace api.Routes +{ + public static class RadioRoutes + { + public static void RegisterRadioRoutesAPI(WebApplication app) + { + const string API_RADIO_COMPLETE = $"{Util.API_ROUTE}{Util.API_VERSION}{Util.RADIO}"; + app.MapGet(API_RADIO_COMPLETE, (DBContext db) => + { + var listRadios = db.Radios + .Include(p => p.City).ToList(); + return Results.Ok(listRadios); + }) + .Produces?>(200) + .WithMetadata(new SwaggerOperationAttribute( + summary: RadioMetadataMessages.MESSAGE_RADIO_LIST_SUMMARY, + description: RadioMetadataMessages.MESSAGE_RADIO_LIST_DESCRIPTION + )); + + app.MapGet($"{API_RADIO_COMPLETE}/{{id}}", async (int id, DBContext db) => + { + if (id <= 0) + { + return Results.BadRequest(); + } + + var city = await db.Radios + .Include(p => p.City).SingleOrDefaultAsync(p => p.Id == id); + if (city is null) + { + return Results.NotFound(); + } + + return Results.Ok(city); + }) + .Produces(200) + .WithMetadata(new SwaggerOperationAttribute( + summary: RadioMetadataMessages.MESSAGE_RADIO_BYID_SUMMARY, + description: RadioMetadataMessages.MESSAGE_RADIO_BYID_DESCRIPTION + )); + + app.MapGet($"{API_RADIO_COMPLETE}/name/{{name}}", (string name, DBContext db) => + { + var city = db.Radios + .Include(p => p.City).Where(x => x.Name.ToUpper().Equals(name.Trim().ToUpper())).ToList(); + if (city is null) + { + return Results.NotFound(); + } + + return Results.Ok(city); + }) + .Produces?>(200) + .WithMetadata(new SwaggerOperationAttribute( + summary: RadioMetadataMessages.MESSAGE_RADIO_BYNAME_SUMMARY, + description: RadioMetadataMessages.MESSAGE_RADIO_BYNAME_DESCRIPTION + )); + + app.MapGet($"{API_RADIO_COMPLETE}/search/{{keyword}}", (string keyword, DBContext db) => + { + string wellFormedKeyword = keyword.Trim().ToUpper().Normalize(); + var dbRadios = db.Radios + .Include(p => p.City).ToList(); + var Radios = Functions.FilterObjectListPropertiesByKeyword(dbRadios, wellFormedKeyword); + + if (!Radios.Any()) + { + return Results.NotFound(); + } + + return Results.Ok(Radios); + }) + .Produces>(200) + .WithMetadata(new SwaggerOperationAttribute( + summary: RadioMetadataMessages.MESSAGE_RADIO_SEARCH_SUMMARY, + description: RadioMetadataMessages.MESSAGE_RADIO_SEARCH_DESCRIPTION + )); + + + app.MapGet($"{API_RADIO_COMPLETE}/pagedList", async ([AsParameters] PaginationModel pagination, DBContext db) => + { + if (pagination.Page <= 0 || pagination.PageSize <= 0) + { + return Results.BadRequest(); + } + + var Radios = db.Radios + .Include(p => p.City).Skip((pagination.Page - 1) * pagination.PageSize).Take(pagination.PageSize); + if (!await Radios?.AnyAsync()) + { + return Results.NotFound(); + } + + var paginationResponse = new PaginationResponseModel + { + Page = pagination.Page, + PageSize = pagination.PageSize, + TotalRecords = await Radios.CountAsync(), + Data = await Radios.ToListAsync() + }; + + return Results.Ok(paginationResponse); + }) + .Produces>(200) + .WithMetadata(new SwaggerOperationAttribute( + summary: RadioMetadataMessages.MESSAGE_RADIO_PAGEDLIST_SUMMARY, + description: RadioMetadataMessages.MESSAGE_RADIO_PAGEDLIST_DESCRIPTION + )); + } + } +} + diff --git a/api/Utils/Messages.cs b/api/Utils/Messages.cs index 5ec6bd7..8c01e52 100644 --- a/api/Utils/Messages.cs +++ b/api/Utils/Messages.cs @@ -185,6 +185,20 @@ public struct ConstitutionArticleEndpoint public const string MESSAGE_CONSTITUTION_ARTICLE_BYCHAPTER_DESCRIPTION = "This endpoint returns a list of Constitution Articles by the chapter number p´rovided "; } + + public struct RadioEndpoint + { + public const string MESSAGE_RADIO_LIST_SUMMARY = "List of Radios in Colombia"; + public const string MESSAGE_RADIO_LIST_DESCRIPTION = "This endpoint returns the radios in colombia including general info like name, url, frequency, etc..."; + public const string MESSAGE_RADIO_BYID_SUMMARY = "Radios information by Id"; + public const string MESSAGE_RADIO_BYID_DESCRIPTION = "This endpoint returns the information for the radio with the provided id"; + public const string MESSAGE_RADIO_BYNAME_SUMMARY = "Radios information by name"; + public const string MESSAGE_RADIO_BYNAME_DESCRIPTION = "This endpoint returns the information for the radio with the provided name"; + public const string MESSAGE_RADIO_SEARCH_SUMMARY = "Search Radios by keyword "; + public const string MESSAGE_RADIO_SEARCH_DESCRIPTION = "This endpoint returns a list of Radios any of the following fields(Name, Frequency, URL, Streamers) match the provided keyword "; + public const string MESSAGE_RADIO_PAGEDLIST_SUMMARY = "List of Radios using pagination - api/v1/radio/pagedList?page=1&pagesize=10"; + public const string MESSAGE_RADIO_PAGEDLIST_DESCRIPTION = "This endpoint returns a list of Radios using pagination including page, pagesize, total records and data, example api/v1/radio/pagedList?page=1&pagesize=10"; + } } } } diff --git a/api/Utils/Util.cs b/api/Utils/Util.cs index 4194770..5bca745 100644 --- a/api/Utils/Util.cs +++ b/api/Utils/Util.cs @@ -16,6 +16,7 @@ public static class Util public const string INDIGENOUS_RESERVATION_ROUTE = "IndigenousReservation"; public const string AIRPORT = "Airport"; public const string CONSTITUTION_ARTICLE = "ConstitutionArticle"; + public const string RADIO = "Radio"; public const string API_ROUTE = "api/"; public const string API_VERSION = "v1/"; diff --git a/api/api.csproj b/api/api.csproj index 842ee77..9906808 100644 --- a/api/api.csproj +++ b/api/api.csproj @@ -7,18 +7,18 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + +