diff --git a/CoviDok/BLL/User/Handlers/IDoctorHandler.cs b/CoviDok/BLL/User/Handlers/IDoctorHandler.cs index eb8c1dd..954e80b 100644 --- a/CoviDok/BLL/User/Handlers/IDoctorHandler.cs +++ b/CoviDok/BLL/User/Handlers/IDoctorHandler.cs @@ -10,12 +10,11 @@ namespace CoviDok.BLL.User.Managers { interface IDoctorHandler { - public List GetDoctors(); + public List GetDoctors(string firstName = null, string lastName = null); public Task GetDoctor(int id); public Task UpdateDoctor(int id, Doctor value); public List GetAssistants(int id); public List GetChildren(int id); - public bool DoctorExists(int id); } } diff --git a/CoviDok/BLL/User/Managers/DoctorManager.cs b/CoviDok/BLL/User/Managers/DoctorManager.cs index 90216e6..27c346c 100644 --- a/CoviDok/BLL/User/Managers/DoctorManager.cs +++ b/CoviDok/BLL/User/Managers/DoctorManager.cs @@ -15,12 +15,12 @@ namespace CoviDok.Data.MySQL public class DoctorManager { private readonly IDoctorHandler handler = new MySqlDoctorHandler(); - public async Task> GetDoctors() + public async Task> GetDoctors(string firstName = null, string lastName = null) { List ret = new List(); await Task.Run( () => { - var docs = handler.GetDoctors(); + var docs = handler.GetDoctors(firstName, lastName); foreach (Doctor doctor in docs) { ret.Add(doctor.ToPublic()); diff --git a/CoviDok/Controllers/DoctorController.cs b/CoviDok/Controllers/DoctorController.cs index 9e91507..744b523 100644 --- a/CoviDok/Controllers/DoctorController.cs +++ b/CoviDok/Controllers/DoctorController.cs @@ -28,6 +28,17 @@ namespace CoviDok.Controllers return await doctorHandler.GetDoctors(); } + [HttpGet("byFirstName/{firstName}")] + public async Task>> GetDoctorsByFirstName(string firstName) + { + return await doctorHandler.GetDoctors(firstName: firstName); + } + [HttpGet("byLastName/{lastName}")] + public async Task>> GetDoctorsByLastName(string lastName) + { + return await doctorHandler.GetDoctors(lastName: lastName); + } + [HttpGet("{id}")] public async Task> GetDoctor(int id) { diff --git a/CoviDok/Data/MySQL/MySqlDoctorHandler.cs b/CoviDok/Data/MySQL/MySqlDoctorHandler.cs index 8f52ee1..cef2bf2 100644 --- a/CoviDok/Data/MySQL/MySqlDoctorHandler.cs +++ b/CoviDok/Data/MySQL/MySqlDoctorHandler.cs @@ -33,8 +33,20 @@ namespace CoviDok.Data.MySQL return await context.Doctors.FindAsync(id); } - public List GetDoctors() + public List GetDoctors(string firstName = null, string lastName = null) { + if (firstName != null && lastName != null) + { + return (from d in context.Doctors where d.FirstName.ToLower().Contains(firstName) && d.LastName.ToLower().Contains(lastName.ToLower()) select d).ToList(); + } + if (firstName != null) + { + return (from d in context.Doctors where d.FirstName.ToLower().Contains(firstName) select d).ToList(); + } + if (lastName != null) + { + return (from d in context.Doctors where d.LastName.ToLower().Contains(lastName.ToLower()) select d).ToList(); + } return context.Doctors.ToList(); }