2024-11-13 20:44:01 +01:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of FirmTracker - Server.
|
|
|
|
|
*
|
|
|
|
|
* FirmTracker - Server is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* FirmTracker - Server is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with FirmTracker - Server. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using FirmTracker_Server.nHibernate;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-11-11 22:49:15 +01:00
|
|
|
|
using System;
|
2024-11-13 20:44:01 +01:00
|
|
|
|
using System.Security.Claims;
|
2024-11-11 22:49:15 +01:00
|
|
|
|
|
2024-11-13 20:44:01 +01:00
|
|
|
|
namespace FirmTracker_Server.Controllers
|
2024-11-11 22:49:15 +01:00
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
2024-11-13 20:44:01 +01:00
|
|
|
|
[Authorize]
|
2024-11-11 22:49:15 +01:00
|
|
|
|
public class WorkdayController : ControllerBase
|
|
|
|
|
{
|
2024-11-13 20:44:01 +01:00
|
|
|
|
private readonly WorkdayRepository _workdayCRUD;
|
2024-11-11 22:49:15 +01:00
|
|
|
|
|
2024-11-13 20:44:01 +01:00
|
|
|
|
public WorkdayController()
|
2024-11-11 22:49:15 +01:00
|
|
|
|
{
|
2024-11-13 20:44:01 +01:00
|
|
|
|
_workdayCRUD = new WorkdayRepository(); // Instantiate directly (no DI in this example)
|
2024-11-11 22:49:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 20:44:01 +01:00
|
|
|
|
// Endpoint to start a workday
|
|
|
|
|
[HttpPost("start")]
|
|
|
|
|
[Authorize(Roles = Roles.Admin + "," + Roles.User)]
|
|
|
|
|
public IActionResult StartWorkday()
|
2024-11-11 22:49:15 +01:00
|
|
|
|
{
|
2024-11-13 20:44:01 +01:00
|
|
|
|
try
|
2024-11-11 22:49:15 +01:00
|
|
|
|
{
|
2024-11-13 20:44:01 +01:00
|
|
|
|
var userIdString = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
|
int userId = int.Parse(userIdString);
|
|
|
|
|
_workdayCRUD.StartWorkday(userId);
|
|
|
|
|
return Ok(new { status = "started", userId });
|
2024-11-11 22:49:15 +01:00
|
|
|
|
}
|
2024-11-13 20:44:01 +01:00
|
|
|
|
catch (Exception ex)
|
2024-11-11 22:49:15 +01:00
|
|
|
|
{
|
2024-11-13 20:44:01 +01:00
|
|
|
|
return BadRequest(new { message = "An error occurred while starting the workday.", error = ex.Message });
|
2024-11-11 22:49:15 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-13 20:44:01 +01:00
|
|
|
|
|
|
|
|
|
|
2024-11-11 22:49:15 +01:00
|
|
|
|
}
|
|
|
|
|
}
|