diff --git a/src/Server/Controllers/JobListingController.cs b/src/Server/Controllers/JobListingController.cs index a6c36a6..63a6941 100644 --- a/src/Server/Controllers/JobListingController.cs +++ b/src/Server/Controllers/JobListingController.cs @@ -19,6 +19,18 @@ namespace BoredCareers.Controllers { return NotFound("Job listing not found"); } + [HttpGet("company")] + public async Task GetCompanysJobListings([FromQuery] int CompanyID) { + if (isLoggedIn()) { + if (await isLoggedInUserEmployeeOf(CompanyID)) { + JobListing[] jobListings = await _databaseService.GetJobListingFromCompany(CompanyID); + return Ok(jobListings); + } + return NotFound("You are not an employee of company"); + } + return NotFound("Not logged in"); + } + [HttpGet] public async Task GetJobListings(int Page = 1, int PageQuantity = 25) { JobListing[] jobListings = await _databaseService.GetJobListingPage(Page, PageQuantity); diff --git a/src/Server/Services/DatabaseService/JobListing.cs b/src/Server/Services/DatabaseService/JobListing.cs index 1b99c8b..434fde9 100644 --- a/src/Server/Services/DatabaseService/JobListing.cs +++ b/src/Server/Services/DatabaseService/JobListing.cs @@ -64,6 +64,61 @@ namespace BoredCareers.Services.DatabaseService { return joblistings.ToArray(); } + public async Task GetJobListingFromCompany(int CompanyID) { + List joblistings = new List(); ; + using (MySqlConnection connection = GetConnection()) { + connection.Open(); + string command = @" + SELECT * + FROM JobListing + WHERE CompanyID = @CompanyID; + "; + + MySqlCommand cmd = new MySqlCommand(command, connection); + cmd.Parameters.AddWithValue("@CompanyID", CompanyID); + + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + if (reader == null) { break; } + int _id = reader.GetInt32("ID"); + int _companyid = reader.GetInt32("CompanyID"); + string _title = reader.GetString("Title"); + string _postalcode = reader.GetString("PostalCode"); + string _country = reader.GetString("Country"); + string _state = reader.GetString("StateOrRegion"); + string _city = reader.GetString("City"); + int _salarymin = reader.GetInt32("SalaryMin"); + int _salarymax = reader.GetInt32("SalaryMax"); + string _jobtype = reader.GetString("JobType"); + bool _remote = reader.GetBoolean("Remote"); + string _description = reader.GetString("Description"); + DateTime _createtime = reader.GetDateTime("CreatedTime"); + DateTime _modifiedtime = reader.GetDateTime("ModifiedTime"); + bool _isdeleted = reader.GetBoolean("IsDeleted"); + + joblistings.Add(new JobListing() { + ID = _id, + CompanyID = _companyid, + Title = _title, + PostalCode = _postalcode, + Country = _country, + StateOrRegion = _state, + City = _city, + SalaryMin = _salarymin, + SalaryMax = _salarymax, + JobType = _jobtype, + Remote = _remote, + Description = _description, + CreatedTime = _createtime, + ModifiedTime = _modifiedtime, + IsDeleted = _isdeleted + }); + } + } + } + return joblistings.ToArray(); + } + public async Task GetJobListing(int JobListingID) { JobListing? joblisting = null; using (MySqlConnection connection = GetConnection()) {