working #18
+19
-2
@@ -163,9 +163,9 @@ CREATE TABLE IF NOT EXISTS `JobListing` (
|
||||
`JobType` varchar(20) NOT NULL,
|
||||
`Remote` boolean DEFAULT 0,
|
||||
`Description` text NOT NULL,
|
||||
`CreatedTime` datetime Default NULL,
|
||||
`CreatedTime` datetime DEFAULT NULL,
|
||||
`ModifiedTime` datetime DEFAULT NULL,
|
||||
`IsDeleted` boolean Default 0,
|
||||
`IsDeleted` boolean DEFAULT 0,
|
||||
PRIMARY KEY (`ID`),
|
||||
FOREIGN KEY (`CompanyID`) REFERENCES `Company`(`ID`) ON DELETE CASCADE
|
||||
) AUTO_INCREMENT=1;
|
||||
@@ -178,3 +178,20 @@ CREATE TABLE IF NOT EXISTS `JobListingSkill` (
|
||||
PRIMARY KEY (`ID`),
|
||||
FOREIGN KEY (`JobListingID`) REFERENCES `JobListing`(`ID`) ON DELETE CASCADE
|
||||
) AUTO_INCREMENT=1;
|
||||
|
||||
-- Application Section
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `JobApplication` (
|
||||
`ID` int NOT NULL AUTO_INCREMENT,
|
||||
`AccountID` int NOT NULL,
|
||||
`ResumeID` int NOT NULL,
|
||||
`JobListingID` int NOT NULL,
|
||||
`DateApplied` datetime DEFAULT NULL,
|
||||
`ResponseStatus` varchar(50) NOT NULL DEFAULT 'Pending',
|
||||
`HasBeenViewed` boolean DEFAULT 0,
|
||||
`Rating` int DEFAULT NULL,
|
||||
`Notes` text DEFAULT NULL,
|
||||
PRIMARY KEY (`ID`),
|
||||
FOREIGN KEY (`ResumeID`) REFERENCES `Resume`(`ID`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`JobListingID`) REFERENCES `JobListing`(`ID`) ON DELETE CASCADE
|
||||
) AUTO_INCREMENT=1;
|
||||
@@ -0,0 +1,11 @@
|
||||
export class Application {
|
||||
public id: number | null = null;
|
||||
public accountID: number = 0;
|
||||
public resumeID: number = 0;
|
||||
public jobListingID: number = 0;
|
||||
public dateApplied: Date = new Date();
|
||||
public responseStatus: string = "";
|
||||
public hasBeenViewed: boolean = false;
|
||||
public rating: number = 0;
|
||||
public notes: string = "";
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using BoredCareers.Services.DatabaseService;
|
||||
using BoredCareers.Entities;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace BoredCareers.Controllers {
|
||||
[ApiController]
|
||||
[Route("api/application")]
|
||||
public class ApplicationController : MistoxControllerBase {
|
||||
|
||||
public ApplicationController(DatabaseService db) : base(db) {}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetApplication(int ApplicationID) {
|
||||
if (isLoggedIn()) {
|
||||
Application? application = await _databaseService.GetApplication(ApplicationID);
|
||||
if (application != null) {
|
||||
return Ok(application);
|
||||
}
|
||||
return NotFound("Application doesn't exist");
|
||||
}
|
||||
return NotFound("Not logged in");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SetApplication([FromBody] Application application) {
|
||||
if (isLoggedIn()) {
|
||||
if (application.AccountID == getLoggedInUserID()) {
|
||||
await _databaseService.SetApplication(application);
|
||||
return Ok();
|
||||
}
|
||||
return NotFound("Cannot apply for someone else");
|
||||
}
|
||||
return NotFound("Not logged in");
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public async Task<IActionResult> DeleteApplication(int ApplicationID) {
|
||||
if (isLoggedIn()) {
|
||||
Application? app = await _databaseService.GetApplication(ApplicationID);
|
||||
if (app != null) {
|
||||
if (app.AccountID == getLoggedInUserID()) {
|
||||
await _databaseService.DeleteApplication(ApplicationID);
|
||||
return Ok();
|
||||
}
|
||||
return NotFound("You cannot delete an app that isnt yours");
|
||||
}
|
||||
return NotFound("Application doesn't exist");
|
||||
}
|
||||
return NotFound("Not logged in");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace BoredCareers.Entities {
|
||||
public class Application {
|
||||
public int? ID { get; set; } // PK
|
||||
public int AccountID { get; set; } // FK
|
||||
public int ResumeID { get; set; } // FK
|
||||
public int JobListingID { get; set; } // FK
|
||||
public DateTime DateApplied { get; set; }
|
||||
public string ResponseStatus { get; set; } = "";
|
||||
public bool HasBeenViewed { get; set; } = false;
|
||||
public int Rating { get; set; }
|
||||
public string Notes { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ namespace BoredCareers.Entities {
|
||||
public bool EmailVerified { get; set; } = false;
|
||||
public string WebsiteURL { get; set; } = "";
|
||||
public string Logo { get; set; } = "";
|
||||
public int JobsClosedSuccessful { get; set; } = 0;
|
||||
public int JobsAutoClosed { get; set; } = 0;
|
||||
public int JobsClosedSuccessful { get; set; }
|
||||
public int JobsAutoClosed { get; set; }
|
||||
public string Phone { get; set; } = "";
|
||||
public string PostalCode { get; set; } = "";
|
||||
public string Country { get; set; } = ""; // 2 Letter Country Code
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
using BoredCareers.Entities;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace BoredCareers.Services.DatabaseService {
|
||||
public partial class DatabaseService {
|
||||
|
||||
public async Task<Application[]> GetApplcationsFromAccount(int AccountID) {
|
||||
List<Application> applications = new List<Application>();
|
||||
using (MySqlConnection connection = GetConnection()) {
|
||||
await connection.OpenAsync();
|
||||
string command = @"
|
||||
SELECT *
|
||||
FROM JobApplication
|
||||
WHERE AccountID = @AccountID
|
||||
";
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||
cmd.Parameters.AddWithValue("@AccountID", AccountID);
|
||||
|
||||
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
|
||||
while (await reader.ReadAsync()) {
|
||||
int _id = reader.GetInt32("ID");
|
||||
int _accountid = reader.GetInt32("AccountID");
|
||||
int _resumeid = reader.GetInt32("ResumeID");
|
||||
int _joblistingid = reader.GetInt32("JobListingID");
|
||||
DateTime _dateapplied = reader.GetDateTime("DateApplied");
|
||||
string _responsestatus = reader.GetString("ResponseStatus");
|
||||
bool _hasbeenviewed = reader.GetBoolean("HasBeenViewed");
|
||||
int _rating = reader.GetInt32("Rating");
|
||||
string _notes = reader.GetString("Notes");
|
||||
|
||||
applications.Add(new Application() {
|
||||
ID = _id,
|
||||
AccountID = _accountid,
|
||||
ResumeID = _resumeid,
|
||||
JobListingID = _joblistingid,
|
||||
DateApplied = _dateapplied,
|
||||
ResponseStatus = _responsestatus,
|
||||
HasBeenViewed = _hasbeenviewed,
|
||||
Rating = _rating,
|
||||
Notes = _notes
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return applications.ToArray();
|
||||
}
|
||||
|
||||
public async Task<Application[]> GetApplicationsFromJobListing(int JobListingID) {
|
||||
List<Application> applications = new List<Application>();
|
||||
using (MySqlConnection connection = GetConnection()) {
|
||||
await connection.OpenAsync();
|
||||
string command = @"
|
||||
SELECT *
|
||||
FROM JobApplication
|
||||
WHERE JobListingID = @JobListingID
|
||||
";
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||
cmd.Parameters.AddWithValue("@JobListingID", JobListingID);
|
||||
|
||||
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
|
||||
while (await reader.ReadAsync()) {
|
||||
int _id = reader.GetInt32("ID");
|
||||
int _accountid = reader.GetInt32("AccountID");
|
||||
int _resumeid = reader.GetInt32("ResumeID");
|
||||
int _joblistingid = reader.GetInt32("JobListingID");
|
||||
DateTime _dateapplied = reader.GetDateTime("DateApplied");
|
||||
string _responsestatus = reader.GetString("ResponseStatus");
|
||||
bool _hasbeenviewed = reader.GetBoolean("HasBeenViewed");
|
||||
int _rating = reader.GetInt32("Rating");
|
||||
string _notes = reader.GetString("Notes");
|
||||
|
||||
applications.Add(new Application() {
|
||||
ID = _id,
|
||||
AccountID = _accountid,
|
||||
ResumeID = _resumeid,
|
||||
JobListingID = _joblistingid,
|
||||
DateApplied = _dateapplied,
|
||||
ResponseStatus = _responsestatus,
|
||||
HasBeenViewed = _hasbeenviewed,
|
||||
Rating = _rating,
|
||||
Notes = _notes
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return applications.ToArray();
|
||||
}
|
||||
|
||||
public async Task<Application?> GetApplication(int ApplicationID) {
|
||||
Application? application = null;
|
||||
using (MySqlConnection connection = GetConnection()) {
|
||||
await connection.OpenAsync();
|
||||
string command = @"
|
||||
SELECT *
|
||||
FROM JobApplication
|
||||
WHERE ID = @ApplicationID
|
||||
";
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||
cmd.Parameters.AddWithValue("@ApplicationID", ApplicationID);
|
||||
|
||||
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
|
||||
while (await reader.ReadAsync()) {
|
||||
int _id = reader.GetInt32("ID");
|
||||
int _accountid = reader.GetInt32("AccountID");
|
||||
int _resumeid = reader.GetInt32("ResumeID");
|
||||
int _joblistingid = reader.GetInt32("JobListingID");
|
||||
DateTime _dateapplied = reader.GetDateTime("DateApplied");
|
||||
string _responsestatus = reader.GetString("ResponseStatus");
|
||||
bool _hasbeenviewed = reader.GetBoolean("HasBeenViewed");
|
||||
int _rating = reader.GetInt32("Rating");
|
||||
string _notes = reader.GetString("Notes");
|
||||
|
||||
application = new Application() {
|
||||
ID = _id,
|
||||
AccountID = _accountid,
|
||||
ResumeID = _resumeid,
|
||||
JobListingID = _joblistingid,
|
||||
DateApplied = _dateapplied,
|
||||
ResponseStatus = _responsestatus,
|
||||
HasBeenViewed = _hasbeenviewed,
|
||||
Rating = _rating,
|
||||
Notes = _notes
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return application;
|
||||
}
|
||||
|
||||
public async Task SetApplication(Application application) {
|
||||
using (MySqlConnection connection = GetConnection()) {
|
||||
await connection.OpenAsync();
|
||||
string command = @"
|
||||
INSERT INTO JobApplication
|
||||
(ID,AccountID,ResumeID,JobListingID,DateApplied,ResponseStatus,HasBeenViewed,Rating,Notes)
|
||||
VALUES
|
||||
(@ID,@AccountID,@ResumeID,@JobListingID,@DateApplied,@ResponseStatus,@HasBeenViewed,@Rating,@Notes)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
AccountID = @AccountID,
|
||||
ResumeID = @ResumeID,
|
||||
JobListingID = @JobListingID,
|
||||
ResponseStatus = @ResponseStatus,
|
||||
HasBeenViewed = @HasBeenViewed,
|
||||
Rating = @Rating,
|
||||
Notes = @Notes;
|
||||
";
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||
cmd.Parameters.AddWithValue("@ID", application.ID);
|
||||
cmd.Parameters.AddWithValue("@AccountID", application.AccountID);
|
||||
cmd.Parameters.AddWithValue("@ResumeID", application.ResumeID);
|
||||
cmd.Parameters.AddWithValue("@JobListingID", application.JobListingID);
|
||||
cmd.Parameters.AddWithValue("@DateApplied", DateTime.UtcNow);
|
||||
cmd.Parameters.AddWithValue("@ResponseStatus", application.ResponseStatus);
|
||||
cmd.Parameters.AddWithValue("@HasBeenViewed", application.HasBeenViewed);
|
||||
cmd.Parameters.AddWithValue("@Rating", application.Rating);
|
||||
cmd.Parameters.AddWithValue("@Notes", application.Notes);
|
||||
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteApplication(int ApplicationID) {
|
||||
using (MySqlConnection connection = GetConnection()) {
|
||||
MySqlCommand cmd;
|
||||
await connection.OpenAsync();
|
||||
string command = @"
|
||||
DELETE FROM JobApplication WHERE ID = @ID;
|
||||
";
|
||||
cmd = new MySqlCommand(command, connection);
|
||||
cmd.Parameters.AddWithValue("@ID", ApplicationID);
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user