(feat): init domain objects to model mapping

This commit is contained in:
Maksym Sadovnychyy 2022-08-07 22:06:57 +02:00
parent c48f9ed980
commit 2122f2dc39
9 changed files with 83 additions and 49 deletions

View File

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Core.Abstractions.Models {
public abstract class ModelBase { }
}

View File

@ -5,6 +5,9 @@ using System.Text;
using System.Threading.Tasks;
namespace Core.Abstractions.Models {
public abstract class RequestModel {
public abstract class RequestModel : ModelBase {
}
}

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
namespace Core.Abstractions.Models {
public abstract class ResponseModel {
public abstract class ResponseModel : ModelBase {
}
}

View File

@ -2,10 +2,10 @@
public class HeaderModel {
public string Title { get; set; }
public Dictionary<string, string> HeaderLink { get; set; }
public string? Title { get; set; }
public Dictionary<string, string>? Link { get; set; }
public Dictionary<string, string> Meta { get; set; }
public Dictionary<string, string>? Meta { get; set; }
}

View File

@ -1,15 +1,15 @@
namespace WeatherForecast.Models {
public class LocalizationModel {
public string TimeZone { get; set; }
public string? TimeZone { get; set; }
public string Locale { get; set; }
public string? Locale { get; set; }
public string DateFormat { get; set; }
public string? DateFormat { get; set; }
public string TimeFormat { get; set; }
public string? TimeFormat { get; set; }
public string Currency { get; set; }
public string? Currency { get; set; }
public string CurrencySymobol { get; set; }
public string? CurrencySymbol { get; set; }
}
}

View File

@ -1,27 +1,11 @@
namespace WeatherForecast.Models {
public class MenuItemModel {
public string? Icon { get; set; }
public string? Title { get; private set; }
public string? Target { get; private set; }
public List<MenuItemModel>? ChildItems { get; private set; }
public MenuItemModel(string title, string target) {
Title = title;
Target = target;
}
public MenuItemModel(string title, string target, List<MenuItemModel> childItems) : this(title, target) {
ChildItems = childItems;
}
public MenuItemModel(string icon, string title, string target): this(title, target) {
Icon = icon;
}
public MenuItemModel(string icon, string title, string target, List<MenuItemModel> childItems) : this(icon, title, target) {
ChildItems = childItems;
}
public string? Title { get; set; }
public string? Target { get; set; }
public List<MenuItemModel>? ChildItems { get; set; }
}
}

View File

@ -1,7 +1,10 @@
using Core.Abstractions.Models;
using Core.DomainObjects;
using Core.DomainObjects.Documents;
using WeatherForecast.Models.Pages;
namespace WeatherForecast.Models.Responses {
public class GetContentResponseModel : ResponseModel {
public string SiteName { get; set; }
public string SiteUrl { get; set; }
@ -24,5 +27,51 @@ namespace WeatherForecast.Models.Responses {
public BlogCatalogPageModel BlogCatalog { get; set; }
public BlogItemPageModel Blogitem { get; set; }
public GetContentResponseModel (Content domainObject) {
SiteName = domainObject.SiteName;
SiteUrl = domainObject.SiteUrl;
Header = new HeaderModel {
Title = domainObject.Header.Title,
Link = domainObject.Header.Link,
Meta = domainObject.Header.Meta
};
Localization = new LocalizationModel {
TimeZone = domainObject.Localization.TimeZone,
Locale = domainObject.Localization.Locale,
DateFormat = domainObject.Localization.DateFormat,
TimeFormat = domainObject.Localization.TimeFormat,
Currency = domainObject.Localization.Currency,
CurrencySymbol = domainObject.Localization.CurrencySymbol
};
RouteModel ToRouteModel (Core.DomainObjects.Route route) {
return new RouteModel {
Target = route.Target,
Component = route.Component,
ChildRoutes = route.ChildRoutes?.Select(x => ToRouteModel(x)).ToList()
};
}
Routes = domainObject.Routes.Select(x => ToRouteModel(x)).ToList();
AdminRoutes = domainObject.AdminRoutes.Select(x => ToRouteModel(x)).ToList();
ServiceRoutes = domainObject.ServiceRoutes.Select(x => ToRouteModel(x)).ToList();
MenuItemModel ToMenuItemModel (MenuItem item) {
return new MenuItemModel {
Title = item.Title,
Target = item.Target,
ChildItems = item.ChildItems?.Select(x => ToMenuItemModel(x)).ToList()
};
}
TopMenu = domainObject.TopMenu.Select(x => ToMenuItemModel(x)).ToList();
SideMenu = domainObject.SideMenu.Select(x => ToMenuItemModel(x)).ToList();
}
}
}

View File

@ -1,19 +1,9 @@
namespace WeatherForecast.Models {
public class RouteModel {
public string Target { get; private set; }
public string? Component { get; private set; }
public List<RouteModel>? ChildRoutes { get; private set; }
public string Target { get; set; }
public string? Component { get; set; }
public List<RouteModel>? ChildRoutes { get; set; }
private RouteModel(string target) {
Target = target;
}
public RouteModel(string target, string component) : this(target) {
Component = component;
}
public RouteModel(string target, List<RouteModel> childRoutes) : this(target) {
ChildRoutes = childRoutes;
}
}
}

View File

@ -25,12 +25,10 @@ namespace WeatherForecast.Services {
public (GetContentResponseModel?, IDomainResult) GetContent(Guid siteId, string? locale) {
var (content, result) = _contentDataProvider.Get("b3f39a82-6a1b-46a4-85cc-04c3b4315511".ToGuid());
if (!result.IsSuccess)
if (!result.IsSuccess || content == null)
return (null, result);
// map content to GetContentResponseModel
return IDomainResult.Failed<GetContentResponseModel?>();
return IDomainResult.Success(new GetContentResponseModel(content));
}
}