diff --git a/database/mistox.sql b/database/mistox.sql index bd5dcae..e4a488b 100755 --- a/database/mistox.sql +++ b/database/mistox.sql @@ -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; @@ -177,4 +177,21 @@ CREATE TABLE IF NOT EXISTS `JobListingSkill` ( `Description` text DEFAULT NULL, 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; \ No newline at end of file diff --git a/src/Client/src/app/models/Application.ts b/src/Client/src/app/models/Application.ts new file mode 100644 index 0000000..fb3f1bf --- /dev/null +++ b/src/Client/src/app/models/Application.ts @@ -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 = ""; +} \ No newline at end of file diff --git a/src/Server/Controllers/ApplicationController.cs b/src/Server/Controllers/ApplicationController.cs new file mode 100644 index 0000000..0b9f1d6 --- /dev/null +++ b/src/Server/Controllers/ApplicationController.cs @@ -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 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 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 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"); + } + + } + +} diff --git a/src/Server/Entities/Application.cs b/src/Server/Entities/Application.cs new file mode 100644 index 0000000..11b61d2 --- /dev/null +++ b/src/Server/Entities/Application.cs @@ -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; } = ""; + } +} \ No newline at end of file diff --git a/src/Server/Entities/Company.cs b/src/Server/Entities/Company.cs index b9d6b06..c6fbcb8 100644 --- a/src/Server/Entities/Company.cs +++ b/src/Server/Entities/Company.cs @@ -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 diff --git a/src/Server/Services/DatabaseService/Application.cs b/src/Server/Services/DatabaseService/Application.cs new file mode 100644 index 0000000..c412944 --- /dev/null +++ b/src/Server/Services/DatabaseService/Application.cs @@ -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 GetApplcationsFromAccount(int AccountID) { + List applications = new List(); + 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 GetApplicationsFromJobListing(int JobListingID) { + List applications = new List(); + 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 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(); + } + } + + } +}