Add Job Listing Skills

This commit is contained in:
2025-08-01 21:32:56 -07:00
parent 5480af64f6
commit 2c4292da07
5 changed files with 107 additions and 4 deletions
+9
View File
@@ -167,3 +167,12 @@ CREATE TABLE IF NOT EXISTS `JobListing` (
PRIMARY KEY (`ID`), PRIMARY KEY (`ID`),
FOREIGN KEY (`CompanyID`) REFERENCES `Company`(`ID`) ON DELETE CASCADE FOREIGN KEY (`CompanyID`) REFERENCES `Company`(`ID`) ON DELETE CASCADE
) AUTO_INCREMENT=1; ) 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;
+8
View File
@@ -11,7 +11,15 @@ export class JobListing {
public jobType: string = ""; public jobType: string = "";
public remote: boolean = false; public remote: boolean = false;
public description: string = ""; public description: string = "";
public skills: JobListingSkills[] = [];
public createdTime: Date = new Date(); public createdTime: Date = new Date();
public modifiedTime: Date = new Date(); public modifiedTime: Date = new Date();
public isDeleted: boolean = false; public isDeleted: boolean = false;
} }
export class JobListingSkills {
public id: number | null = null;
public jobListingID: number = 0;
public name: string = "";
public Description: string = "";
}
+8
View File
@@ -13,9 +13,17 @@ namespace BoredCareers.Entities {
public string JobType { get; set; } = ""; public string JobType { get; set; } = "";
public bool Remote { get; set; } = false; public bool Remote { get; set; } = false;
public string Description { get; set; } = ""; public string Description { get; set; } = "";
public JobListingSkill[] Skills { get; set; } = [];
public DateTime CreatedTime { get; set; } public DateTime CreatedTime { get; set; }
public DateTime ModifiedTime { get; set; } public DateTime ModifiedTime { get; set; }
public bool IsDeleted { get; set; } = false; 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; } = "";
}
} }
@@ -37,6 +37,7 @@ namespace BoredCareers.Services.DatabaseService {
string _jobtype = reader.GetString("JobType"); string _jobtype = reader.GetString("JobType");
bool _remote = reader.GetBoolean("Remote"); bool _remote = reader.GetBoolean("Remote");
string _description = reader.GetString("Description"); string _description = reader.GetString("Description");
JobListingSkill[] _skills = await GetJobListingSkills(_id);
DateTime _createtime = reader.GetDateTime("CreatedTime"); DateTime _createtime = reader.GetDateTime("CreatedTime");
DateTime _modifiedtime = reader.GetDateTime("ModifiedTime"); DateTime _modifiedtime = reader.GetDateTime("ModifiedTime");
bool _isdeleted = reader.GetBoolean("IsDeleted"); bool _isdeleted = reader.GetBoolean("IsDeleted");
@@ -54,6 +55,7 @@ namespace BoredCareers.Services.DatabaseService {
JobType = _jobtype, JobType = _jobtype,
Remote = _remote, Remote = _remote,
Description = _description, Description = _description,
Skills = _skills,
CreatedTime = _createtime, CreatedTime = _createtime,
ModifiedTime = _modifiedtime, ModifiedTime = _modifiedtime,
IsDeleted = _isdeleted IsDeleted = _isdeleted
@@ -92,6 +94,7 @@ namespace BoredCareers.Services.DatabaseService {
string _jobtype = reader.GetString("JobType"); string _jobtype = reader.GetString("JobType");
bool _remote = reader.GetBoolean("Remote"); bool _remote = reader.GetBoolean("Remote");
string _description = reader.GetString("Description"); string _description = reader.GetString("Description");
JobListingSkill[] _skills = await GetJobListingSkills(_id);
DateTime _createtime = reader.GetDateTime("CreatedTime"); DateTime _createtime = reader.GetDateTime("CreatedTime");
DateTime _modifiedtime = reader.GetDateTime("ModifiedTime"); DateTime _modifiedtime = reader.GetDateTime("ModifiedTime");
bool _isdeleted = reader.GetBoolean("IsDeleted"); bool _isdeleted = reader.GetBoolean("IsDeleted");
@@ -109,6 +112,7 @@ namespace BoredCareers.Services.DatabaseService {
JobType = _jobtype, JobType = _jobtype,
Remote = _remote, Remote = _remote,
Description = _description, Description = _description,
Skills = _skills,
CreatedTime = _createtime, CreatedTime = _createtime,
ModifiedTime = _modifiedtime, ModifiedTime = _modifiedtime,
IsDeleted = _isdeleted IsDeleted = _isdeleted
@@ -147,6 +151,7 @@ namespace BoredCareers.Services.DatabaseService {
string _jobtype = reader.GetString("JobType"); string _jobtype = reader.GetString("JobType");
bool _remote = reader.GetBoolean("Remote"); bool _remote = reader.GetBoolean("Remote");
string _description = reader.GetString("Description"); string _description = reader.GetString("Description");
JobListingSkill[] _skills = await GetJobListingSkills(_id);
DateTime _createtime = reader.GetDateTime("CreatedTime"); DateTime _createtime = reader.GetDateTime("CreatedTime");
DateTime _modifiedtime = reader.GetDateTime("ModifiedTime"); DateTime _modifiedtime = reader.GetDateTime("ModifiedTime");
bool _isdeleted = reader.GetBoolean("IsDeleted"); bool _isdeleted = reader.GetBoolean("IsDeleted");
@@ -164,6 +169,7 @@ namespace BoredCareers.Services.DatabaseService {
JobType = _jobtype, JobType = _jobtype,
Remote = _remote, Remote = _remote,
Description = _description, Description = _description,
Skills = _skills,
CreatedTime = _createtime, CreatedTime = _createtime,
ModifiedTime = _modifiedtime, ModifiedTime = _modifiedtime,
IsDeleted = _isdeleted IsDeleted = _isdeleted
@@ -175,7 +181,7 @@ namespace BoredCareers.Services.DatabaseService {
} }
public async Task SetJobListing( JobListing jobListing ) { public async Task SetJobListing( JobListing jobListing ) {
using( MySqlConnection connection = GetConnection() ) { using (MySqlConnection connection = GetConnection()) {
connection.Open(); connection.Open();
string command = @" string command = @"
@@ -200,7 +206,7 @@ namespace BoredCareers.Services.DatabaseService {
IsDeleted = @IsDeleted; IsDeleted = @IsDeleted;
"; ";
MySqlCommand cmd = new MySqlCommand( command , connection); MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ID", jobListing.ID); cmd.Parameters.AddWithValue("@ID", jobListing.ID);
cmd.Parameters.AddWithValue("@CompanyID", jobListing.CompanyID); cmd.Parameters.AddWithValue("@CompanyID", jobListing.CompanyID);
cmd.Parameters.AddWithValue("@Title", jobListing.Title); cmd.Parameters.AddWithValue("@Title", jobListing.Title);
@@ -218,11 +224,15 @@ namespace BoredCareers.Services.DatabaseService {
cmd.Parameters.AddWithValue("@IsDeleted", jobListing.IsDeleted); cmd.Parameters.AddWithValue("@IsDeleted", jobListing.IsDeleted);
await cmd.ExecuteNonQueryAsync(); await cmd.ExecuteNonQueryAsync();
foreach (JobListingSkill cur in jobListing.Skills) {
await SetJobListingSkills(cur);
}
} }
} }
public async Task DeleteJobListing( int JobListingID ) { public async Task DeleteJobListing( int JobListingID ) {
using( MySqlConnection connection = GetConnection() ) { using (MySqlConnection connection = GetConnection()) {
MySqlCommand cmd; MySqlCommand cmd;
connection.Open(); connection.Open();
@@ -231,7 +241,7 @@ namespace BoredCareers.Services.DatabaseService {
SET IsDeleted = TRUE SET IsDeleted = TRUE
WHERE ID = @ID; WHERE ID = @ID;
"; ";
cmd = new MySqlCommand( command, connection ); cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ID", JobListingID); cmd.Parameters.AddWithValue("@ID", JobListingID);
await cmd.ExecuteNonQueryAsync(); await cmd.ExecuteNonQueryAsync();
@@ -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<JobListingSkill[]> GetJobListingSkills(int JobListingID) {
List<JobListingSkill> joblistingskills = new List<JobListingSkill>();
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();
}
}
}
}