Finalize Services
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using BoredCareers.Services.DatabaseService;
|
||||
using BoredCareers.Entities;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace BoredCareers.Controllers {
|
||||
[ApiController]
|
||||
[Route("api/company/")]
|
||||
public class CompanyController : MistoxControllerBase {
|
||||
|
||||
public CompanyController(DatabaseService db) : base(db) {}
|
||||
|
||||
[Route("get")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> GetCompany([FromForm] int companyID) {
|
||||
if (isLoggedIn()) {
|
||||
Company? company = await _databaseService.GetCompany(companyID);
|
||||
if (company != null) {
|
||||
return Ok(company);
|
||||
}
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[Route("set")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SetCompany([FromBody] Company company) {
|
||||
if (isLoggedIn()) {
|
||||
if (await isLoggedInUserEmployeeOf(company.ID)) {
|
||||
await _databaseService.SetCompany(company);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[Route("delete")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> DeleteCompany([FromForm] int CompanyID) {
|
||||
if (isLoggedIn()) {
|
||||
if (await isLoggedInUserEmployeeOf(CompanyID)) {
|
||||
await _databaseService.DeleteCompany(CompanyID);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user