blog admin separation: application & httpApi

pull/4236/head
Yunus Emre Kalkan 5 years ago
parent ec863c2d3c
commit 493bf50037

@ -51,6 +51,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "public-app", "public-app",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Blogging.Admin.Application.Contracts", "src\Volo.Blogging.Admin.Application.Contracts\Volo.Blogging.Admin.Application.Contracts.csproj", "{D8DF4D56-644E-4ADF-9DB9-712DDA62B129}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Blogging.Admin.Application", "src\Volo.Blogging.Admin.Application\Volo.Blogging.Admin.Application.csproj", "{CB5DEBB3-5C2E-48E9-AA42-497575BCC7A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Blogging.Admin.HttpApi", "src\Volo.Blogging.Admin.HttpApi\Volo.Blogging.Admin.HttpApi.csproj", "{59BBAF94-CC8E-4313-9143-F2F5C36A7C45}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -129,6 +133,14 @@ Global
{D8DF4D56-644E-4ADF-9DB9-712DDA62B129}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8DF4D56-644E-4ADF-9DB9-712DDA62B129}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8DF4D56-644E-4ADF-9DB9-712DDA62B129}.Release|Any CPU.Build.0 = Release|Any CPU
{CB5DEBB3-5C2E-48E9-AA42-497575BCC7A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB5DEBB3-5C2E-48E9-AA42-497575BCC7A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB5DEBB3-5C2E-48E9-AA42-497575BCC7A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB5DEBB3-5C2E-48E9-AA42-497575BCC7A4}.Release|Any CPU.Build.0 = Release|Any CPU
{59BBAF94-CC8E-4313-9143-F2F5C36A7C45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59BBAF94-CC8E-4313-9143-F2F5C36A7C45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59BBAF94-CC8E-4313-9143-F2F5C36A7C45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59BBAF94-CC8E-4313-9143-F2F5C36A7C45}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -155,6 +167,8 @@ Global
{03328648-6DE6-43C1-9A27-64771A73FAAD} = {1314C122-18F0-4C6B-895F-27645B6121FF}
{A4DBA051-7FB9-4AD7-B9B7-6810B2268122} = {1314C122-18F0-4C6B-895F-27645B6121FF}
{D8DF4D56-644E-4ADF-9DB9-712DDA62B129} = {BE2A423C-271E-469A-AD90-5640DEBEE9C1}
{CB5DEBB3-5C2E-48E9-AA42-497575BCC7A4} = {BE2A423C-271E-469A-AD90-5640DEBEE9C1}
{59BBAF94-CC8E-4313-9143-F2F5C36A7C45} = {BE2A423C-271E-469A-AD90-5640DEBEE9C1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F2BAE819-78D4-407A-9201-22473B2850B0}

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\configureawait.props" />
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Blogging.Admin.Application</AssemblyName>
<PackageId>Volo.Blogging.Admin.Application</PackageId>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<ProjectReference Include="..\Volo.Blogging.Admin.Application.Contracts\Volo.Blogging.Admin.Application.Contracts.csproj" />
<ProjectReference Include="..\Volo.Blogging.Domain\Volo.Blogging.Domain.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Caching\Volo.Abp.Caching.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,14 @@
using Volo.Abp.Application.Services;
using Volo.Blogging.Localization;
namespace Volo.Blogging.Admin
{
public abstract class BloggingAdminAppServiceBase : ApplicationService
{
protected BloggingAdminAppServiceBase()
{
ObjectMapperContext = typeof(BloggingAdminApplicationModule);
LocalizationResource = typeof(BloggingResource);
}
}
}

@ -0,0 +1,14 @@
using AutoMapper;
using Volo.Blogging.Admin.Blogs;
using Volo.Blogging.Blogs;
namespace Volo.Blogging.Admin
{
public class BloggingAdminApplicationAutoMapperProfile : Profile
{
public BloggingAdminApplicationAutoMapperProfile()
{
CreateMap<Blog, BlogDto>();
}
}
}

@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.Modularity;
using Volo.Blogging.Comments;
using Volo.Blogging.Posts;
namespace Volo.Blogging.Admin
{
[DependsOn(
typeof(BloggingDomainModule),
typeof(BloggingAdminApplicationContractsModule),
typeof(AbpCachingModule),
typeof(AbpAutoMapperModule))]
public class BloggingAdminApplicationModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAutoMapperObjectMapper<BloggingAdminApplicationModule>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddProfile<BloggingAdminApplicationAutoMapperProfile>(validate: true);
});
}
}
}

@ -0,0 +1,64 @@
using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Blogging.Blogs;
namespace Volo.Blogging.Admin.Blogs
{
public class BlogManagementAppService : BloggingAdminAppServiceBase, IBlogManagementAppService
{
private readonly IBlogRepository _blogRepository;
public BlogManagementAppService(IBlogRepository blogRepository)
{
_blogRepository = blogRepository;
}
public async Task<ListResultDto<BlogDto>> GetListAsync()
{
var blogs = await _blogRepository.GetListAsync();
return new ListResultDto<BlogDto>(
ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs)
);
}
public async Task<BlogDto> GetAsync(Guid id)
{
var blog = await _blogRepository.GetAsync(id);
return ObjectMapper.Map<Blog, BlogDto>(blog);
}
[Authorize(BloggingAdminPermissions.Blogs.Create)]
public async Task<BlogDto> Create(CreateBlogDto input)
{
var newBlog = await _blogRepository.InsertAsync(new Blog(GuidGenerator.Create(), input.Name, input.ShortName)
{
Description = input.Description
});
return ObjectMapper.Map<Blog, BlogDto>(newBlog);
}
[Authorize(BloggingAdminPermissions.Blogs.Update)]
public async Task<BlogDto> Update(Guid id, UpdateBlogDto input)
{
var blog = await _blogRepository.GetAsync(id);
blog.SetName(input.Name);
blog.SetShortName(input.ShortName);
blog.Description = input.Description;
return ObjectMapper.Map<Blog, BlogDto>(blog);
}
[Authorize(BloggingAdminPermissions.Blogs.Delete)]
public async Task Delete(Guid id)
{
await _blogRepository.DeleteAsync(id);
}
}
}

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\configureawait.props" />
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Volo.Blogging.Admin.HttpApi</AssemblyName>
<PackageId>Volo.Blogging.Admin.HttpApi</PackageId>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Blogging.Admin.Application.Contracts\Volo.Blogging.Admin.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,56 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Blogging.Admin.Blogs;
namespace Volo.Blogging.Admin
{
[RemoteService(Name = BloggingAdminRemoteServiceConsts.RemoteServiceName)]
[Area("bloggingAdmin")]
[Route("api/blogging/blogs/admin")]
public class BlogManagementController : AbpController, IBlogManagementAppService
{
private readonly IBlogManagementAppService _blogManagementAppService;
public BlogManagementController(IBlogManagementAppService blogManagementAppService)
{
_blogManagementAppService = blogManagementAppService;
}
[HttpGet]
public async Task<ListResultDto<BlogDto>> GetListAsync()
{
return await _blogManagementAppService.GetListAsync();
}
[HttpGet]
[Route("{id}")]
public async Task<BlogDto> GetAsync(Guid id)
{
return await _blogManagementAppService.GetAsync(id);
}
[HttpPost]
public async Task<BlogDto> Create(CreateBlogDto input)
{
return await _blogManagementAppService.Create(input);
}
[HttpPut]
[Route("{id}")]
public async Task<BlogDto> Update(Guid id, UpdateBlogDto input)
{
return await _blogManagementAppService.Update(id, input);
}
[HttpDelete]
[Route("{id}")]
public async Task Delete(Guid id)
{
await _blogManagementAppService.Delete(id);
}
}
}

@ -0,0 +1,33 @@
using Localization.Resources.AbpUi;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Blogging.Localization;
using Microsoft.Extensions.DependencyInjection;
namespace Volo.Blogging.Admin
{
[DependsOn(
typeof(BloggingAdminApplicationContractsModule),
typeof(AbpAspNetCoreMvcModule))]
public class BloggingAdminHttpApiModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<IMvcBuilder>(mvcBuilder =>
{
mvcBuilder.AddApplicationPartIfNotExists(typeof(BloggingAdminHttpApiModule).Assembly);
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Get<BloggingResource>()
.AddBaseTypes(typeof(AbpUiResource));
});
}
}
}

@ -44,34 +44,5 @@ namespace Volo.Blogging.Blogs
return ObjectMapper.Map<Blog, BlogDto>(blog);
}
[Authorize(BloggingPermissions.Blogs.Create)]
public async Task<BlogDto> Create(CreateBlogDto input)
{
var newBlog = await _blogRepository.InsertAsync(new Blog(GuidGenerator.Create(), input.Name, input.ShortName)
{
Description = input.Description
});
return ObjectMapper.Map<Blog, BlogDto>(newBlog);
}
[Authorize(BloggingPermissions.Blogs.Update)]
public async Task<BlogDto> Update(Guid id, UpdateBlogDto input)
{
var blog = await _blogRepository.GetAsync(id);
blog.SetName(input.Name);
blog.SetShortName(input.ShortName);
blog.Description = input.Description;
return ObjectMapper.Map<Blog, BlogDto>(blog);
}
[Authorize(BloggingPermissions.Blogs.Delete)]
public async Task Delete(Guid id)
{
await _blogRepository.DeleteAsync(id);
}
}
}

@ -40,25 +40,5 @@ namespace Volo.Blogging
{
return await _blogAppService.GetAsync(id);
}
[HttpPost]
public async Task<BlogDto> Create(CreateBlogDto input)
{
return await _blogAppService.Create(input);
}
[HttpPut]
[Route("{id}")]
public async Task<BlogDto> Update(Guid id, UpdateBlogDto input)
{
return await _blogAppService.Update(id, input);
}
[HttpDelete]
[Route("{id}")]
public async Task Delete(Guid id)
{
await _blogAppService.Delete(id);
}
}
}

Loading…
Cancel
Save