using Microsoft.AspNetCore.Mvc; using BoredCareers.Services.DatabaseService; using BoredCareers.Entities; using System.Web.Http; namespace BoredCareers.Controllers { [ApiController] [Route("api/joblisting")] public class JobListingController : MistoxControllerBase { public JobListingController(DatabaseService db) : base(db) {} [HttpGet("{JobListingID}")] public async Task GetJobListing([FromRoute] int JobListingID) { var jobListing = await _databaseService.GetJobListing(JobListingID); if (jobListing != null) { return Ok(jobListing); } return NotFound("Job listing not found"); } [HttpGet] public async Task GetJobListings(int Page = 1, int PageQuantity = 25) { JobListing[] jobListings = await _databaseService.GetJobListingPage(Page, PageQuantity); return Ok(jobListings); } [HttpPost] public async Task SetJobListing([FromBody] JobListing JobListing) { if (isLoggedIn()) { if (await isLoggedInUserEmployeeOf(JobListing.CompanyID)) { await _databaseService.SetJobListing(JobListing); return Ok(); } return NotFound("You are not an employee of company"); } return NotFound("Not logged in"); } [HttpDelete] public async Task DeleteJobListing(int JobListingID) { if (isLoggedIn()) { JobListing? jobListing = await _databaseService.GetJobListing(JobListingID); if (jobListing != null) { if (await isLoggedInUserEmployeeOf(JobListingID)) { await _databaseService.DeleteJobListing(JobListingID); return Ok(); } return NotFound("You are not an employee of company"); } return NotFound("Job listing doesn't exist already"); } return NotFound("Not logged in"); } } }