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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,17 +10,14 @@ namespace BoredCareers.Controllers {
|
||||
|
||||
public JobListingController(DatabaseService db) : base(db) {}
|
||||
|
||||
[Route("getlistings")]
|
||||
[Route("getpage")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> GetJobListings([FromForm] int page) {
|
||||
if (isLoggedIn()) {
|
||||
JobListing[] jobListings = await _databaseService.GetJobListingPage(page, 25); // 10 items per page
|
||||
return Ok(jobListings);
|
||||
}
|
||||
return NotFound();
|
||||
JobListing[] jobListings = await _databaseService.GetJobListingPage(page, 25); // 10 items per page
|
||||
return Ok(jobListings);
|
||||
}
|
||||
|
||||
[Route("getlisting")]
|
||||
[Route("get")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> GetJobListing([FromForm] int JobListingID) {
|
||||
JobListing? jobListing = await _databaseService.GetJobListing(JobListingID);
|
||||
@@ -32,16 +29,27 @@ namespace BoredCareers.Controllers {
|
||||
|
||||
[Route("set")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SetJobListing([FromBody] Resume resume) {
|
||||
await Task.Delay(1);
|
||||
return Ok();
|
||||
public async Task<IActionResult> SetJobListing([FromBody] JobListing jobListing) {
|
||||
if (isLoggedIn()) {
|
||||
if (await isLoggedInUserEmployeeOf(jobListing.CompanyID)) {
|
||||
await _databaseService.SetJobListing(jobListing);
|
||||
}
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[Route("delete")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> DeleteJobListing([FromForm] int ResumeID) {
|
||||
await Task.Delay(1);
|
||||
return Ok();
|
||||
public async Task<IActionResult> DeleteJobListing([FromForm] int JobListingID) {
|
||||
if (isLoggedIn()) {
|
||||
JobListing? jobListing = await _databaseService.GetJobListing(JobListingID);
|
||||
if (jobListing != null) {
|
||||
if (await isLoggedInUserEmployeeOf(JobListingID)) {
|
||||
await _databaseService.DeleteJobListing(JobListingID);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,16 @@ namespace BoredCareers.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> isLoggedInUserEmployeeOf(int CompanyID) {
|
||||
Employee[] employees = await _databaseService.GetEmployees(CompanyID);
|
||||
foreach (Employee cur in employees) {
|
||||
if (getLoggedInUserID() == cur.AccountID) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public string Substitue(string message, string subString, string Replacement) {
|
||||
for (int i = 0; i < (message.Length - subString.Length); i++) {
|
||||
if (message.Substring(i, subString.Length) == subString) {
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace BoredCareers.Controllers {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[Route("getfull")]
|
||||
[Route("get")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> GetResume([FromForm] int ResumeID) {
|
||||
Resume? resume = await _databaseService.GetResume(ResumeID);
|
||||
|
||||
Reference in New Issue
Block a user