From 35018d921bb9d6ed799c5127d88eae24bc1b90e1 Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Mon, 4 Aug 2025 16:27:41 -0700 Subject: [PATCH] Thread on the server better --- .../Services/DatabaseService/Company.cs | 8 +- .../Services/DatabaseService/Employee.cs | 13 ++- .../Services/DatabaseService/JobListing.cs | 84 +++++++++++++++++-- .../DatabaseService/JobListingSkill.cs | 5 +- 4 files changed, 85 insertions(+), 25 deletions(-) diff --git a/src/Server/Services/DatabaseService/Company.cs b/src/Server/Services/DatabaseService/Company.cs index 504e481..f8efbda 100644 --- a/src/Server/Services/DatabaseService/Company.cs +++ b/src/Server/Services/DatabaseService/Company.cs @@ -10,7 +10,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetCompany( int CompanyID ) { Company? company = null; using( MySqlConnection connection = GetConnection() ) { - connection.Open(); + await connection.OpenAsync(); string command = @" SELECT * FROM Company @@ -22,7 +22,6 @@ namespace BoredCareers.Services.DatabaseService { using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { while( await reader.ReadAsync() ) { - if( reader == null ) { break; } int _id = reader.GetInt32("ID"); string _name = reader.GetString("Name"); string _email = reader.GetString("Email"); @@ -58,8 +57,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task SetCompany( Company company ) { using (MySqlConnection connection = GetConnection()) { - connection.Open(); - + await connection.OpenAsync(); string command = @" INSERT INTO Company (ID,Name,Email,EmailVerified,WebsiteURL,Logo,Phone,PostalCode,Country,StateOrRegion,City,Description) @@ -104,7 +102,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task DeleteCompany( int CompanyID ) { using( MySqlConnection connection = GetConnection() ) { MySqlCommand cmd; - connection.Open(); + await connection.OpenAsync(); string command = @" DELETE FROM Company WHERE ID = @ID; diff --git a/src/Server/Services/DatabaseService/Employee.cs b/src/Server/Services/DatabaseService/Employee.cs index 143a5b0..b3e926b 100644 --- a/src/Server/Services/DatabaseService/Employee.cs +++ b/src/Server/Services/DatabaseService/Employee.cs @@ -10,7 +10,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetEmployee( int EmployeeID ) { Employee? employee = null; using( MySqlConnection connection = GetConnection() ) { - connection.Open(); + await connection.OpenAsync(); string command = @" SELECT * FROM Employee @@ -23,7 +23,6 @@ namespace BoredCareers.Services.DatabaseService { using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { while( await reader.ReadAsync() ) { - if( reader == null ) { break; } int _id = reader.GetInt32("ID"); int _accountid = reader.GetInt32("AccountID"); int _companyid = reader.GetInt32("CompanyID"); @@ -66,7 +65,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetEmployeesFromCompany(int CompanyID) { List employees = new List(); using (MySqlConnection connection = GetConnection()) { - connection.Open(); + await connection.OpenAsync(); string command = @" SELECT * FROM Employee @@ -79,7 +78,6 @@ namespace BoredCareers.Services.DatabaseService { using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { - if (reader == null) { break; } int _id = reader.GetInt32("ID"); int _accountid = reader.GetInt32("AccountID"); int _companyid = reader.GetInt32("CompanyID"); @@ -122,7 +120,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetEmployeesFromAccount(int AccountID) { List employees = new List(); using (MySqlConnection connection = GetConnection()) { - connection.Open(); + await connection.OpenAsync(); string command = @" SELECT * FROM Employee @@ -135,7 +133,6 @@ namespace BoredCareers.Services.DatabaseService { using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { - if (reader == null) { break; } int _id = reader.GetInt32("ID"); int _accountid = reader.GetInt32("AccountID"); int _companyid = reader.GetInt32("CompanyID"); @@ -177,7 +174,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task SetEmployee(Employee employee) { using (MySqlConnection connection = GetConnection()) { - connection.Open(); + await connection.OpenAsync(); string command = @" INSERT INTO Employee @@ -201,7 +198,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task DeleteEmployee( int EmployeeID ) { using( MySqlConnection connection = GetConnection() ) { MySqlCommand cmd; - connection.Open(); + await connection.OpenAsync(); string command = @" DELETE FROM Employee WHERE ID = @ID; diff --git a/src/Server/Services/DatabaseService/JobListing.cs b/src/Server/Services/DatabaseService/JobListing.cs index b654062..065088c 100644 --- a/src/Server/Services/DatabaseService/JobListing.cs +++ b/src/Server/Services/DatabaseService/JobListing.cs @@ -9,7 +9,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetJobListingPage(int PageNumber, int CountPerPage) { List joblistings = new List(); using (MySqlConnection connection = GetConnection()) { - connection.Open(); + await connection.OpenAsync(); string command = @" SELECT * FROM JobListing @@ -24,7 +24,6 @@ namespace BoredCareers.Services.DatabaseService { 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"); @@ -69,7 +68,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetJobListingFromCompany(int CompanyID) { List joblistings = new List(); ; using (MySqlConnection connection = GetConnection()) { - connection.Open(); + await connection.OpenAsync(); string command = @" SELECT * FROM JobListing @@ -81,7 +80,6 @@ namespace BoredCareers.Services.DatabaseService { 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"); @@ -126,7 +124,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetJobListing(int JobListingID) { JobListing? joblisting = null; using (MySqlConnection connection = GetConnection()) { - connection.Open(); + await connection.OpenAsync(); string command = @" SELECT * FROM JobListing @@ -138,7 +136,6 @@ namespace BoredCareers.Services.DatabaseService { 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"); @@ -180,9 +177,78 @@ namespace BoredCareers.Services.DatabaseService { return joblisting; } - public async Task SetJobListing( JobListing jobListing ) { + public async Task GetJobListingsPastExipre() { + List joblistings = new List(); using (MySqlConnection connection = GetConnection()) { - connection.Open(); + await connection.OpenAsync(); + string command = @" + SELECT * + FROM JobListing + WHERE IsDeleted = FALSE + AND CreatedTime < NOW() - INTERVAL 1 MONTH; + "; + MySqlCommand cmd = new MySqlCommand(command, connection); + + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + 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"); + JobListingSkill[] _skills = await GetJobListingSkills(_id); + 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, + Skills = _skills, + CreatedTime = _createtime, + ModifiedTime = _modifiedtime, + IsDeleted = _isdeleted + }); + } + } + } + return joblistings.ToArray(); + } + + public async Task DeleteJobListingsPastExipre() { + using (MySqlConnection connection = GetConnection()) { + await connection.OpenAsync(); + string command = @" + UPDATE JobListing + SET IsDeleted = TRUE + WHERE IsDeleted = FALSE + AND CreatedTime < NOW() - INTERVAL 1 MONTH; + "; + MySqlCommand cmd = new MySqlCommand(command, connection); + await cmd.ExecuteNonQueryAsync(); + } + } + + public async Task SetJobListing(JobListing jobListing) { + using (MySqlConnection connection = GetConnection()) { + await connection.OpenAsync(); string command = @" INSERT INTO JobListing @@ -234,7 +300,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task DeleteJobListing( int JobListingID ) { using (MySqlConnection connection = GetConnection()) { MySqlCommand cmd; - connection.Open(); + await connection.OpenAsync(); string command = @" UPDATE JobListing diff --git a/src/Server/Services/DatabaseService/JobListingSkill.cs b/src/Server/Services/DatabaseService/JobListingSkill.cs index 0d022c7..953bc0b 100644 --- a/src/Server/Services/DatabaseService/JobListingSkill.cs +++ b/src/Server/Services/DatabaseService/JobListingSkill.cs @@ -9,7 +9,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetJobListingSkills(int JobListingID) { List joblistingskills = new List(); using (MySqlConnection connection = GetConnection()) { - connection.Open(); + await connection.OpenAsync(); string command = @" SELECT * FROM JobListingSkill @@ -41,8 +41,7 @@ namespace BoredCareers.Services.DatabaseService { public async Task SetJobListingSkills( JobListingSkill jobListingSkill ) { using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - + await connection.OpenAsync(); string command = @" INSERT INTO JobListing (ID,JobListingID,Name,Description)