diff --git a/Controllers/MatchesController.cs b/Controllers/MatchesController.cs index f5eca1a..e66380a 100644 --- a/Controllers/MatchesController.cs +++ b/Controllers/MatchesController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.SignalR.Infrastructure; using LiveGameFeed.Hubs; using LiveGameFeed.Data.Abstract; using LiveGameFeed.Models; +using AutoMapper; namespace LiveGameFeed.Controllers { @@ -24,18 +25,21 @@ namespace LiveGameFeed.Controllers // GET api/values [HttpGet] - public IEnumerable Get() + public IEnumerable Get() { IEnumerable _matches = _matchRepository.GetAll(); + IEnumerable _matchesVM = Mapper.Map, IEnumerable>(_matches); - return _matches; + return _matchesVM; } // GET api/values/5 [HttpGet("{id}")] - public Match Get(int id) + public MatchViewModel Get(int id) { - return _matchRepository.GetSingle(id); + Match _match = _matchRepository.GetSingle(id); + MatchViewModel _matchVM = Mapper.Map(_match); + return _matchVM; } // POST api/values diff --git a/Mappings/AutoMapperConfiguration.cs b/Mappings/AutoMapperConfiguration.cs new file mode 100644 index 0000000..6738f44 --- /dev/null +++ b/Mappings/AutoMapperConfiguration.cs @@ -0,0 +1,15 @@ +using AutoMapper; + +namespace LiveGameFeed.Mappings +{ + public class AutoMapperConfiguration + { + public static void Configure() + { + Mapper.Initialize(x => + { + x.AddProfile(); + }); + } + } +} diff --git a/Mappings/DomainToViewModelMappingProfile.cs b/Mappings/DomainToViewModelMappingProfile.cs new file mode 100644 index 0000000..5c64e14 --- /dev/null +++ b/Mappings/DomainToViewModelMappingProfile.cs @@ -0,0 +1,14 @@ +using AutoMapper; +using LiveGameFeed.Models; + +namespace LiveGameFeed.Mappings +{ + public class DomainToViewModelMappingProfile : Profile + { + protected override void Configure() + { + Mapper.CreateMap(); + Mapper.CreateMap(); + } + } +} diff --git a/Models/FeedViewModel.cs b/Models/FeedViewModel.cs new file mode 100644 index 0000000..edd21e8 --- /dev/null +++ b/Models/FeedViewModel.cs @@ -0,0 +1,12 @@ +using System; + +namespace LiveGameFeed.Models +{ + public class FeedViewModel : IEntityBase + { + public int Id { get; set; } + public string Description { get; set; } + public DateTime CreatedAt { get; set; } + public int MatchId { get; set; } + } +} diff --git a/Models/MatchViewModel.cs b/Models/MatchViewModel.cs new file mode 100644 index 0000000..8bff433 --- /dev/null +++ b/Models/MatchViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace LiveGameFeed.Models +{ + public class MatchViewModel : IEntityBase + { + public int Id { get; set; } + public string Host { get; set; } + public string Guest { get; set; } + public int HostScore { get; set; } + public int GuestScore { get; set; } + public DateTime MatchDate { get; set; } + public string League { get; set; } + } +} diff --git a/Startup.cs b/Startup.cs index 9cfcac0..1769767 100644 --- a/Startup.cs +++ b/Startup.cs @@ -11,6 +11,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using LiveGameFeed.Mappings; namespace LiveGameFeed { @@ -36,6 +37,9 @@ namespace LiveGameFeed // Repositories services.AddScoped(); services.AddScoped(); + + // Automapper Configuration + AutoMapperConfiguration.Configure(); // Add framework services. services.AddMvc(); diff --git a/app/home/home.component.html b/app/home/home.component.html index c8598bb..daed21d 100644 --- a/app/home/home.component.html +++ b/app/home/home.component.html @@ -19,7 +19,7 @@ diff --git a/project.json b/project.json index 4b5f676..c4bb6ab 100644 --- a/project.json +++ b/project.json @@ -1,5 +1,6 @@ { "dependencies": { + "AutoMapper.Data": "1.0.0-beta1", "Microsoft.NETCore.App": { "version": "1.0.0-*", "type": "platform"