diff --git a/CoviDok/BLL/User/Handlers/IChildHandler.cs b/CoviDok/BLL/User/Handlers/IChildHandler.cs index 79f811d..053bd8d 100644 --- a/CoviDok/BLL/User/Handlers/IChildHandler.cs +++ b/CoviDok/BLL/User/Handlers/IChildHandler.cs @@ -13,5 +13,6 @@ namespace CoviDok.BLL.User.Managers public Task GetChild(int id); public Task UpdateChild(int id, Child newData); public Task AddChild(Child newChild); + public List GetChildren(int parentID); } } diff --git a/CoviDok/BLL/User/Managers/ChildManager.cs b/CoviDok/BLL/User/Managers/ChildManager.cs index 05be2cc..e50e1d1 100644 --- a/CoviDok/BLL/User/Managers/ChildManager.cs +++ b/CoviDok/BLL/User/Managers/ChildManager.cs @@ -26,6 +26,16 @@ namespace CoviDok.Data.MySQL throw new UnauthorizedAccessException(); } } + + public List ChildrenOfParent(int parentID) + { + List ret = new List(); + foreach (Child child in handler.GetChildren(parentID)) + { + ret.Add(child.ToPublic()); + } + return ret; + } public async Task UpdateChild(Session s, int id, PublicChild newData) { diff --git a/CoviDok/Controllers/ChildController.cs b/CoviDok/Controllers/ChildController.cs index 72228ee..03ec51c 100644 --- a/CoviDok/Controllers/ChildController.cs +++ b/CoviDok/Controllers/ChildController.cs @@ -66,6 +66,14 @@ namespace CoviDok.Controllers } } + [HttpPost("parent")] + public async Task>> GetChildrenOfParent(AuthGet auth) + { + Session s = await Handler.GetSession(auth.SessionID); + if (s == null) return Unauthorized(); + return ChildManager.ChildrenOfParent(s.ID); + } + // POST: api/Child // To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. diff --git a/CoviDok/Data/MySQL/MySqlChildHandler.cs b/CoviDok/Data/MySQL/MySqlChildHandler.cs index f9f0d80..c55b473 100644 --- a/CoviDok/Data/MySQL/MySqlChildHandler.cs +++ b/CoviDok/Data/MySQL/MySqlChildHandler.cs @@ -23,6 +23,11 @@ namespace CoviDok.Data.MySQL return await context.Children.FindAsync(id); } + public List GetChildren(int parentID) + { + return (from c in context.Children where c.ParentId == parentID select c).ToList(); + } + public async Task UpdateChild(int id, Child newData) { Child child = new Child { Id = id };