diff --git a/BL/BL.csproj b/BL/BL.csproj index c2e7a25..d2809be 100644 --- a/BL/BL.csproj +++ b/BL/BL.csproj @@ -43,6 +43,7 @@ + diff --git a/BL/DTOs/PostDTO.cs b/BL/DTOs/PostDTO.cs index 60ef9ec..687edd0 100644 --- a/BL/DTOs/PostDTO.cs +++ b/BL/DTOs/PostDTO.cs @@ -10,6 +10,10 @@ namespace BL.DTOs { public int PostId { get; set; } public string Title { get; set; } + public string Body { get; set; } + public DateTime CreationTime { get; set; } + public string Author { get; set; } + public FoorumDTO Foorum { get; set; } } } diff --git a/BL/Factories/FoorumFactory.cs b/BL/Factories/FoorumFactory.cs index bec3fec..eaab66a 100644 --- a/BL/Factories/FoorumFactory.cs +++ b/BL/Factories/FoorumFactory.cs @@ -8,6 +8,7 @@ namespace BL.Factories { public class FoorumFactory { + private readonly PostFactory _postFactory = new PostFactory(); public FoorumDTO Create(Foorum f, bool withPosts = false) { var dto = new FoorumDTO() @@ -23,9 +24,8 @@ namespace BL.Factories if (withPosts) { - throw new NotImplementedException(); - //dto.Posts = new List(); - //f.Posts.ForEach(p => {dto.Posts.Add();}); + dto.Posts = new List(); + f.Posts.ForEach(p => {dto.Posts.Add(_postFactory.Create(p));}); } return dto; diff --git a/BL/Factories/PostFactory.cs b/BL/Factories/PostFactory.cs new file mode 100644 index 0000000..ebcaba5 --- /dev/null +++ b/BL/Factories/PostFactory.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BL.DTOs; +using DAL.Domain; + +namespace BL.Factories +{ + public class PostFactory + { + + public PostDTO Create(Post p, bool withForum=false) + { + var dto = new PostDTO() + { + PostId = p.PostId, + Title = p.Title, + Author = p.Author, + Body = p.Body, + CreationTime = p.CreationTime, + }; + + if (withForum) + { + throw new NotImplementedException(); + } + + return dto; + } + } +} diff --git a/BL/Services/FoorumService.cs b/BL/Services/FoorumService.cs index aed0e40..c327086 100644 --- a/BL/Services/FoorumService.cs +++ b/BL/Services/FoorumService.cs @@ -1,13 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; using BL.DTOs; using BL.Factories; using BL.Interfaces; -using DAL.Domain; using DAL.Interfaces; namespace BL.Services @@ -41,7 +36,8 @@ namespace BL.Services public FoorumDTO Get(int id) { - throw new NotImplementedException(); + var f =_foorumRepository.GetById(id); + return _factory.Create(f, withPosts:true); } public IEnumerable GetAll() diff --git a/WebApi/Controllers/FoorumController.cs b/WebApi/Controllers/FoorumController.cs index 514bd73..e8141a7 100644 --- a/WebApi/Controllers/FoorumController.cs +++ b/WebApi/Controllers/FoorumController.cs @@ -23,9 +23,14 @@ namespace WebApi.Controllers } // GET api//5 - public string Get(int id) + public IHttpActionResult Get(int id) { - return "value"; + var f = _foorumService.Get(id); + if (f == null) + { + return NotFound(); + } + return Ok(f); } // POST api/ diff --git a/WebApi/index.html b/WebApi/index.html index 5e879ae..63acecc 100644 --- a/WebApi/index.html +++ b/WebApi/index.html @@ -1,5 +1,6 @@

api

foorum +
@@ -7,6 +8,15 @@