Added phone entity in the sample application.

pull/96/head
Halil İbrahim Kalkan 8 years ago
parent e105079311
commit 5bc7862095

@ -209,17 +209,16 @@ namespace Volo.Abp.AspNetCore.Mvc
private void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) private void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration)
{ {
var verb = configuration?.UseConventionalHttpVerbs == true
? HttpVerbHelper.GetConventionalVerbForMethodName(action.ActionName)
: HttpVerbHelper.DefaultHttpVerb;
var abpServiceSelectorModel = new SelectorModel var abpServiceSelectorModel = new SelectorModel
{ {
AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action) AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, verb),
ActionConstraints = { new HttpMethodActionConstraint(new[] { verb }) }
}; };
var verb = configuration?.UseConventionalHttpVerbs == true
? HttpVerbHelper.GetConventionalVerbForMethodName(action.ActionName)
: HttpVerbHelper.DefaultHttpVerb;
abpServiceSelectorModel.ActionConstraints.Add(new HttpMethodActionConstraint(new[] { verb }));
action.Selectors.Add(abpServiceSelectorModel); action.Selectors.Add(abpServiceSelectorModel);
} }
@ -227,13 +226,11 @@ namespace Volo.Abp.AspNetCore.Mvc
{ {
foreach (var selector in action.Selectors) foreach (var selector in action.Selectors)
{ {
//TODO: Revise this?
var method = selector.ActionConstraints.OfType<HttpMethodActionConstraint>().FirstOrDefault()?.HttpMethods?.FirstOrDefault();
if (selector.AttributeRouteModel == null) if (selector.AttributeRouteModel == null)
{ {
selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel( selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, method);
moduleName,
controllerName,
action
);
} }
} }
} }
@ -250,13 +247,17 @@ namespace Volo.Abp.AspNetCore.Mvc
return _configuration.Value.ControllerAssemblySettings.GetSettingOrNull(controllerType); return _configuration.Value.ControllerAssemblySettings.GetSettingOrNull(controllerType);
} }
private static AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action) private static AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string verb)
{ {
return new AttributeRouteModel( //TODO: Implement via interfaces!
new RouteAttribute(
$"api/services/{moduleName}/{controllerName}/{action.ActionName}" var url = $"api/services/{moduleName}/{controllerName}";
) if (!verb.IsIn("POST"))
); {
url += $"/{action.ActionName}";
}
return new AttributeRouteModel(new RouteAttribute(url));
} }
private static void RemoveEmptySelectors(IList<SelectorModel> selectors) private static void RemoveEmptySelectors(IList<SelectorModel> selectors)

@ -2,11 +2,9 @@ using System.Collections.Generic;
namespace Volo.Abp.Application.Dtos namespace Volo.Abp.Application.Dtos
{ {
public class ListResultDto<T> public class ListResultDto<T> : IListResult<T>
{ {
/// <summary> /// <inheritdoc />
/// List of items.
/// </summary>
public IReadOnlyList<T> Items public IReadOnlyList<T> Items
{ {
get { return _items ?? (_items = new List<T>()); } get { return _items ?? (_items = new List<T>()); }

@ -10,9 +10,7 @@ namespace Volo.Abp.Application.Dtos
[Serializable] [Serializable]
public class PagedResultDto<T> : ListResultDto<T>, IPagedResult<T> public class PagedResultDto<T> : ListResultDto<T>, IPagedResult<T>
{ {
/// <summary> /// <inheritdoc />
/// Total count of Items.
/// </summary>
public int TotalCount { get; set; } public int TotalCount { get; set; }
/// <summary> /// <summary>

@ -69,7 +69,7 @@ namespace Volo.Abp.AspNetCore.Mvc
//Ideally should be [POST] /api/app/person //Ideally should be [POST] /api/app/person
var response = await Client.PostAsync( var response = await Client.PostAsync(
"/api/services/app/person/Create", "/api/services/app/person",
new StringContent(postData, Encoding.UTF8, "application/json") new StringContent(postData, Encoding.UTF8, "application/json")
); );

@ -0,0 +1,9 @@
using Volo.Abp.TestApp.Domain;
namespace Volo.Abp.TestApp.Application
{
public class GetPersonPhonesFilter
{
public PhoneType? Type { get; set; }
}
}

@ -1,8 +1,12 @@
using Volo.Abp.Application.Services; using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Volo.Abp.TestApp.Application namespace Volo.Abp.TestApp.Application
{ {
public interface IPersonAppService : IAsyncCrudAppService<PersonDto> public interface IPersonAppService : IAsyncCrudAppService<PersonDto>
{ {
Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter);
} }
} }

@ -1,4 +1,8 @@
using Volo.Abp.TestApp.Domain; using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.TestApp.Domain;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
@ -9,6 +13,16 @@ namespace Volo.Abp.TestApp.Application
public PersonAppService(IQueryableRepository<Person> repository) public PersonAppService(IQueryableRepository<Person> repository)
: base(repository) : base(repository)
{ {
}
public async Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter input)
{
var person = await GetEntityByIdAsync(id);
return new ListResultDto<PhoneDto>(
ObjectMapper.Map<Collection<Phone>, Collection<PhoneDto>>(person.Phones)
);
} }
} }
} }

@ -0,0 +1,12 @@
using Volo.Abp.Application.Dtos;
using Volo.Abp.TestApp.Domain;
namespace Volo.Abp.TestApp.Application
{
public class PhoneDto : EntityDto<long>
{
public string Number { get; set; }
public PhoneType Type { get; set; }
}
}

@ -1,13 +1,16 @@
using System; using System;
using System.Collections.ObjectModel;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain namespace Volo.Abp.TestApp.Domain
{ {
public class Person : AggregateRoot public class Person : AggregateRoot
{ {
public string Name { get; set; } public virtual string Name { get; set; }
public int Age { get; set; } public virtual int Age { get; set; }
public virtual Collection<Phone> Phones { get; set; }
private Person() private Person()
{ {
@ -19,6 +22,8 @@ namespace Volo.Abp.TestApp.Domain
Id = id; Id = id;
Name = name; Name = name;
Age = age; Age = age;
Phones = new Collection<Phone>();
} }
} }
} }

@ -0,0 +1,22 @@
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
{
public class Phone : Entity<long>
{
public virtual string Number { get; set; }
public virtual PhoneType Type { get; set; }
private Phone()
{
}
public Phone(string number, PhoneType type = PhoneType.Mobile)
{
Number = number;
Type = type;
}
}
}

@ -0,0 +1,9 @@
namespace Volo.Abp.TestApp.Domain
{
public enum PhoneType
{
Mobile,
Home,
Office
}
}

@ -24,16 +24,17 @@ namespace Volo.Abp.TestApp
{ {
services.Configure<AbpAutoMapperOptions>(options => services.Configure<AbpAutoMapperOptions>(options =>
{ {
options.Configurators.Add((IAbpAutoMapperConfigurationContext ctx) => options.Configurators.Add(ctx =>
{ {
ctx.MapperConfiguration.CreateMap<Person, PersonDto>().ReverseMap(); ctx.MapperConfiguration.CreateMap<Person, PersonDto>().ReverseMap();
ctx.MapperConfiguration.CreateMap<Phone, PhoneDto>().ReverseMap();
}); });
}); });
} }
private static void SeedTestData(ApplicationInitializationContext context) private static void SeedTestData(ApplicationInitializationContext context)
{ {
using (IServiceScope scope = context.ServiceProvider.CreateScope()) using (var scope = context.ServiceProvider.CreateScope())
{ {
scope.ServiceProvider scope.ServiceProvider
.GetRequiredService<TestDataBuilder>() .GetRequiredService<TestDataBuilder>()

Loading…
Cancel
Save