Add SQL for getting jobs under company
This commit is contained in:
@@ -19,6 +19,18 @@ namespace BoredCareers.Controllers {
|
|||||||
return NotFound("Job listing not found");
|
return NotFound("Job listing not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("company")]
|
||||||
|
public async Task<IActionResult> 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]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetJobListings(int Page = 1, int PageQuantity = 25) {
|
public async Task<IActionResult> GetJobListings(int Page = 1, int PageQuantity = 25) {
|
||||||
JobListing[] jobListings = await _databaseService.GetJobListingPage(Page, PageQuantity);
|
JobListing[] jobListings = await _databaseService.GetJobListingPage(Page, PageQuantity);
|
||||||
|
|||||||
@@ -64,6 +64,61 @@ namespace BoredCareers.Services.DatabaseService {
|
|||||||
return joblistings.ToArray();
|
return joblistings.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<JobListing[]> GetJobListingFromCompany(int CompanyID) {
|
||||||
|
List<JobListing> joblistings = new List<JobListing>(); ;
|
||||||
|
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<JobListing?> GetJobListing(int JobListingID) {
|
public async Task<JobListing?> GetJobListing(int JobListingID) {
|
||||||
JobListing? joblisting = null;
|
JobListing? joblisting = null;
|
||||||
using (MySqlConnection connection = GetConnection()) {
|
using (MySqlConnection connection = GetConnection()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user