Skip to content

Commit

Permalink
Add user controller
Browse files Browse the repository at this point in the history
  • Loading branch information
arbems committed Sep 3, 2023
1 parent b5b53bc commit 034be8a
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Backend/Controllers/AboutController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ public string Get()
{
return _localizer["About Title"];
}

[HttpGet("GetResource")]
public IActionResult GetResource()
{
//error 404 not found
return NotFound(_localizer["Resource not found"].Value);
}
}
}
22 changes: 22 additions & 0 deletions src/Backend/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Backend.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Backend.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class UserController : ControllerBase
{
[HttpPost]
public IActionResult Post([FromBody] User user)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

return Ok();
}
}
}
15 changes: 15 additions & 0 deletions src/Backend/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;

namespace Backend.Models
{
public class User
{
[Required(ErrorMessage = "The Name field is required.")]
[StringLength(50, ErrorMessage = "The Name field cannot be more than 50 characters.")]
public string Name { get; set; }

[Required(ErrorMessage = "The Email field is required.")]
[EmailAddress(ErrorMessage = "The Email field does not have a valid format.")]
public string Email { get; set; }
}
}
14 changes: 10 additions & 4 deletions src/Backend/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using Backend;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Localization.Routing;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
builder.Services.AddControllers()
.AddDataAnnotationsLocalization(options => {
options.DataAnnotationLocalizerProvider = (type, factory) =>
factory.Create(typeof(SharedResource));
});

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Expand All @@ -21,11 +27,11 @@
.AddSupportedUICultures(SupportedCultures)
.RequestCultureProviders = new List<IRequestCultureProvider>
{
//new AcceptLanguageHeaderRequestCultureProvider(),
new AcceptLanguageHeaderRequestCultureProvider(),
//new QueryStringRequestCultureProvider(),
//new CookieRequestCultureProvider(),
//new RouteDataRequestCultureProvider(),
new CustomRequestCultureProvider(async context =>
/*new CustomRequestCultureProvider(async context =>
{
// Aquí debes implementar tu lógica para determinar la cultura basada en el contexto de la solicitud.
// Puedes leer cookies, cabeceras, etc. para decidir la cultura.
Expand All @@ -34,7 +40,7 @@
string culture = "es-ES";
return new ProviderCultureResult(culture);
})
})*/
};
});

Expand Down
3 changes: 3 additions & 0 deletions src/Backend/Resources/Controllers/AboutController.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<data name="About Title" xml:space="preserve">
<value>About us</value>
</data>
<data name="Resource not found" xml:space="preserve">
<value>Resource not found</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Backend/Resources/Controllers/AboutController.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<data name="About Title" xml:space="preserve">
<value>About us</value>
</data>
<data name="Resource not found" xml:space="preserve">
<value>Resource not found</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Backend/Resources/Controllers/AboutController.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<data name="About Title" xml:space="preserve">
<value>Sobre nosotros</value>
</data>
<data name="Resource not found" xml:space="preserve">
<value>Recurso no encontrado</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Backend/Resources/Controllers/AboutController.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@
<data name="About Title" xml:space="preserve">
<value>Sobre nosotros</value>
</data>
<data name="Resource not found" xml:space="preserve">
<value>Recurso no encontrado</value>
</data>
</root>
12 changes: 12 additions & 0 deletions src/Backend/Resources/SharedResource.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="The Email field does not have a valid format." xml:space="preserve">
<value>The Email field does not have a valid format.</value>
</data>
<data name="The Email field is required." xml:space="preserve">
<value>The Email field is required.</value>
</data>
<data name="The Name field cannot be more than 50 characters." xml:space="preserve">
<value>The Name field cannot be more than 50 characters.</value>
</data>
<data name="The Name field is required." xml:space="preserve">
<value>The Name field is required.</value>
</data>
<data name="Your application description page." xml:space="preserve">
<value>Your application description page.</value>
</data>
Expand Down
12 changes: 12 additions & 0 deletions src/Backend/Resources/SharedResource.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="The Email field does not have a valid format." xml:space="preserve">
<value>The Email field does not have a valid format.</value>
</data>
<data name="The Email field is required." xml:space="preserve">
<value>The Email field is required.</value>
</data>
<data name="The Name field cannot be more than 50 characters." xml:space="preserve">
<value>The Name field cannot be more than 50 characters.</value>
</data>
<data name="The Name field is required." xml:space="preserve">
<value>The Name field is required.</value>
</data>
<data name="Your application description page." xml:space="preserve">
<value>Your application description page.</value>
</data>
Expand Down
12 changes: 12 additions & 0 deletions src/Backend/Resources/SharedResource.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="The Email field does not have a valid format." xml:space="preserve">
<value>El campo Email no tiene un formato válido.</value>
</data>
<data name="The Email field is required." xml:space="preserve">
<value>El campo Email es obligatorio.</value>
</data>
<data name="The Name field cannot be more than 50 characters." xml:space="preserve">
<value>El campo Nombre no puede tener más de 50 caracteres.</value>
</data>
<data name="The Name field is required." xml:space="preserve">
<value>El campo Nombre es obligatorio.</value>
</data>
<data name="Your application description page." xml:space="preserve">
<value>La página de descripción de su aplicación.</value>
</data>
Expand Down
12 changes: 12 additions & 0 deletions src/Backend/Resources/SharedResource.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="The Email field does not have a valid format." xml:space="preserve">
<value>El campo Email no tiene un formato válido.</value>
</data>
<data name="The Email field is required." xml:space="preserve">
<value>El campo Email es obligatorio.</value>
</data>
<data name="The Name field cannot be more than 50 characters." xml:space="preserve">
<value>El campo Nombre no puede tener más de 50 caracteres.</value>
</data>
<data name="The Name field is required." xml:space="preserve">
<value>El campo Nombre es obligatorio.</value>
</data>
<data name="Your application description page." xml:space="preserve">
<value>La página de descripción de su aplicación.</value>
</data>
Expand Down

0 comments on commit 034be8a

Please sign in to comment.