Files
Hushian/Presentation/Hushian.WebApi/Controllers/v1/CompanyController.cs

46 lines
1.6 KiB
C#
Raw Normal View History

2025-07-11 20:37:28 +03:30
using Common.Dtos.Company;
using Hushian.Application.Constants;
using Hushian.Application.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Hushian.WebApi.Controllers.v1
{
[Route("api/v1/[controller]")]
[ApiController]
public class CompanyController : ControllerBase
{
private readonly CompanyService _companyService;
public CompanyController(CompanyService companyService)
{
_companyService = companyService;
}
[HttpPost("NewCompany")]
public async Task<ActionResult<int>> NewCompany([FromBody] RegisterCompanyDto request)
{
var response = await _companyService.RegisterCompany(request);
return response.Success ? Ok(response.Value)
: BadRequest(response.Errors);
}
[HttpGet("GetCompany/{CompanyID}")]
public async Task<ActionResult<ReadANDUpdate_CompanyDto>> GetCompany(int CompanyID)
{
var response = await _companyService.GETCompanyinformation(CompanyID);
return response!=null ? Ok(response): NotFound();
}
[HttpPut("UpdateCompany")]
[Authorize(Roles = "Company")]
public async Task<ActionResult> UpdateCompany([FromBody] ReadANDUpdate_CompanyDto model)
{
string CompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
var response = await _companyService.EditCompany(model,Convert.ToInt32(CompanyID));
return response.Success && response.Value ? NoContent()
: BadRequest(response.Errors);
}
}
}