This commit is contained in:
2025-02-07 01:46:22 +08:00
commit d6f607590b
18 changed files with 905 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
using AceJobAgency.Data;
using AceJobAgency.Entities;
using Microsoft.AspNetCore.Mvc;
namespace AceJobAgency.Controllers
{
[ApiController]
[Route("[controller]")]
public class UserController(DataContext context, IConfiguration configuration) : Controller
{
[HttpPost]
public async Task<IActionResult> Register(User user)
{
var userExists = context.Users.Any(u => u.Email == user.Email);
if (userExists)
{
return BadRequest("User with the same email already exists.");
}
string passwordHash = BCrypt.Net.BCrypt.HashPassword(user.Password);
user.Password = passwordHash;
user.Id = Guid.NewGuid().ToString();
await context.Users.AddAsync(user);
await context.SaveChangesAsync();
return Ok();
}
}
}

View File

@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace AceJobAgency.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}