From 2c4292da07a66d06f23a0cba10784cdbd21bbe2b Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Fri, 1 Aug 2025 21:32:56 -0700 Subject: [PATCH] Add Job Listing Skills --- database/mistox.sql | 9 +++ src/Client/src/app/models/JobListing.ts | 8 +++ src/Server/Entities/JobListing.cs | 8 +++ .../Services/DatabaseService/JobListing.cs | 18 +++-- .../DatabaseService/JobListingSkill.cs | 68 +++++++++++++++++++ 5 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 src/Server/Services/DatabaseService/JobListingSkill.cs diff --git a/database/mistox.sql b/database/mistox.sql index da44b17..b7a19a1 100755 --- a/database/mistox.sql +++ b/database/mistox.sql @@ -166,4 +166,13 @@ CREATE TABLE IF NOT EXISTS `JobListing` ( `IsDeleted` boolean Default 0, PRIMARY KEY (`ID`), FOREIGN KEY (`CompanyID`) REFERENCES `Company`(`ID`) ON DELETE CASCADE +) AUTO_INCREMENT=1; + +CREATE TABLE IF NOT EXISTS `JobListingSkill` ( + `ID` int NOT NULL AUTO_INCREMENT, + `JobListingID` int NOT NULL, + `Name` varchar(150) NOT NULL, + `Description` text DEFAULT NULL, + PRIMARY KEY (`ID`), + 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/JobListing.ts b/src/Client/src/app/models/JobListing.ts index 52fb396..ffd34e3 100644 --- a/src/Client/src/app/models/JobListing.ts +++ b/src/Client/src/app/models/JobListing.ts @@ -11,7 +11,15 @@ export class JobListing { public jobType: string = ""; public remote: boolean = false; public description: string = ""; + public skills: JobListingSkills[] = []; public createdTime: Date = new Date(); public modifiedTime: Date = new Date(); public isDeleted: boolean = false; +} + +export class JobListingSkills { + public id: number | null = null; + public jobListingID: number = 0; + public name: string = ""; + public Description: string = ""; } \ No newline at end of file diff --git a/src/Server/Entities/JobListing.cs b/src/Server/Entities/JobListing.cs index f4fdc5f..92089e0 100644 --- a/src/Server/Entities/JobListing.cs +++ b/src/Server/Entities/JobListing.cs @@ -13,9 +13,17 @@ namespace BoredCareers.Entities { public string JobType { get; set; } = ""; public bool Remote { get; set; } = false; public string Description { get; set; } = ""; + public JobListingSkill[] Skills { get; set; } = []; public DateTime CreatedTime { get; set; } public DateTime ModifiedTime { get; set; } public bool IsDeleted { get; set; } = false; } + public class JobListingSkill { + public int? ID { get; set; } // PK + public int JobListingID { get; set; } // FK + public string Name { get; set; } = ""; + public string Description { get; set; } = ""; + } + } \ No newline at end of file diff --git a/src/Server/Services/DatabaseService/JobListing.cs b/src/Server/Services/DatabaseService/JobListing.cs index 434fde9..b654062 100644 --- a/src/Server/Services/DatabaseService/JobListing.cs +++ b/src/Server/Services/DatabaseService/JobListing.cs @@ -37,6 +37,7 @@ namespace BoredCareers.Services.DatabaseService { string _jobtype = reader.GetString("JobType"); bool _remote = reader.GetBoolean("Remote"); string _description = reader.GetString("Description"); + JobListingSkill[] _skills = await GetJobListingSkills(_id); DateTime _createtime = reader.GetDateTime("CreatedTime"); DateTime _modifiedtime = reader.GetDateTime("ModifiedTime"); bool _isdeleted = reader.GetBoolean("IsDeleted"); @@ -54,6 +55,7 @@ namespace BoredCareers.Services.DatabaseService { JobType = _jobtype, Remote = _remote, Description = _description, + Skills = _skills, CreatedTime = _createtime, ModifiedTime = _modifiedtime, IsDeleted = _isdeleted @@ -92,6 +94,7 @@ namespace BoredCareers.Services.DatabaseService { string _jobtype = reader.GetString("JobType"); bool _remote = reader.GetBoolean("Remote"); string _description = reader.GetString("Description"); + JobListingSkill[] _skills = await GetJobListingSkills(_id); DateTime _createtime = reader.GetDateTime("CreatedTime"); DateTime _modifiedtime = reader.GetDateTime("ModifiedTime"); bool _isdeleted = reader.GetBoolean("IsDeleted"); @@ -109,6 +112,7 @@ namespace BoredCareers.Services.DatabaseService { JobType = _jobtype, Remote = _remote, Description = _description, + Skills = _skills, CreatedTime = _createtime, ModifiedTime = _modifiedtime, IsDeleted = _isdeleted @@ -147,6 +151,7 @@ namespace BoredCareers.Services.DatabaseService { string _jobtype = reader.GetString("JobType"); bool _remote = reader.GetBoolean("Remote"); string _description = reader.GetString("Description"); + JobListingSkill[] _skills = await GetJobListingSkills(_id); DateTime _createtime = reader.GetDateTime("CreatedTime"); DateTime _modifiedtime = reader.GetDateTime("ModifiedTime"); bool _isdeleted = reader.GetBoolean("IsDeleted"); @@ -164,6 +169,7 @@ namespace BoredCareers.Services.DatabaseService { JobType = _jobtype, Remote = _remote, Description = _description, + Skills = _skills, CreatedTime = _createtime, ModifiedTime = _modifiedtime, IsDeleted = _isdeleted @@ -175,7 +181,7 @@ namespace BoredCareers.Services.DatabaseService { } public async Task SetJobListing( JobListing jobListing ) { - using( MySqlConnection connection = GetConnection() ) { + using (MySqlConnection connection = GetConnection()) { connection.Open(); string command = @" @@ -200,7 +206,7 @@ namespace BoredCareers.Services.DatabaseService { IsDeleted = @IsDeleted; "; - MySqlCommand cmd = new MySqlCommand( command , connection); + MySqlCommand cmd = new MySqlCommand(command, connection); cmd.Parameters.AddWithValue("@ID", jobListing.ID); cmd.Parameters.AddWithValue("@CompanyID", jobListing.CompanyID); cmd.Parameters.AddWithValue("@Title", jobListing.Title); @@ -218,11 +224,15 @@ namespace BoredCareers.Services.DatabaseService { cmd.Parameters.AddWithValue("@IsDeleted", jobListing.IsDeleted); await cmd.ExecuteNonQueryAsync(); + + foreach (JobListingSkill cur in jobListing.Skills) { + await SetJobListingSkills(cur); + } } } public async Task DeleteJobListing( int JobListingID ) { - using( MySqlConnection connection = GetConnection() ) { + using (MySqlConnection connection = GetConnection()) { MySqlCommand cmd; connection.Open(); @@ -231,7 +241,7 @@ namespace BoredCareers.Services.DatabaseService { SET IsDeleted = TRUE WHERE ID = @ID; "; - cmd = new MySqlCommand( command, connection ); + cmd = new MySqlCommand(command, connection); cmd.Parameters.AddWithValue("@ID", JobListingID); await cmd.ExecuteNonQueryAsync(); diff --git a/src/Server/Services/DatabaseService/JobListingSkill.cs b/src/Server/Services/DatabaseService/JobListingSkill.cs new file mode 100644 index 0000000..0d022c7 --- /dev/null +++ b/src/Server/Services/DatabaseService/JobListingSkill.cs @@ -0,0 +1,68 @@ +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 GetJobListingSkills(int JobListingID) { + List joblistingskills = new List(); + using (MySqlConnection connection = GetConnection()) { + connection.Open(); + string command = @" + SELECT * + FROM JobListingSkill + WHERE JobListingID = @JobListingID; + "; + + MySqlCommand cmd = new MySqlCommand(command, connection); + cmd.Parameters.AddWithValue("@JobListingID", JobListingID); + + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + if (reader == null) { break; } + int _id = reader.GetInt32("ID"); + int _joblistingid = reader.GetInt32("JobListingID"); + string _name = reader.GetString("Name"); + string _description = reader.GetString("Description"); + + joblistingskills.Add(new JobListingSkill() { + ID = _id, + JobListingID = _joblistingid, + Name = _name, + Description = _description + }); + } + } + } + return joblistingskills.ToArray(); + } + + public async Task SetJobListingSkills( JobListingSkill jobListingSkill ) { + using( MySqlConnection connection = GetConnection() ) { + connection.Open(); + + string command = @" + INSERT INTO JobListing + (ID,JobListingID,Name,Description) + VALUES + (@ID,@JobListingID,@Name,@Description) + ON DUPLICATE KEY UPDATE + JobListingID = @JobListingID, + Name = @Name, + Description = @Description; + "; + + MySqlCommand cmd = new MySqlCommand( command , connection); + cmd.Parameters.AddWithValue("@ID", jobListingSkill.ID); + cmd.Parameters.AddWithValue("@JobListingID", jobListingSkill.JobListingID); + cmd.Parameters.AddWithValue("@Name", jobListingSkill.Name); + cmd.Parameters.AddWithValue("@Description", jobListingSkill.Description); + + await cmd.ExecuteNonQueryAsync(); + } + } + + } +}