Browse Source

Refactor page app service

pull/6996/head
Ahmet 6 years ago
parent
commit
7929ae0101
  1. 10
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CheckUrlInputDto.cs
  2. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CreatePageInputDto.cs
  3. 18
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CreatePageWithContentInputDto.cs
  4. 9
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/GetPagesInputDto.cs
  5. 17
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/IPageAdminAppService.cs
  6. 17
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/PageWithContentDto.cs
  7. 10
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/UpdatePageContentInputDto.cs
  8. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/UpdatePageInputDto.cs
  9. 66
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Pages/PageAdminAppService.cs
  10. 70
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Page/PageAdminController.cs
  11. 70
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Pages/PageAdminController.cs

10
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CheckUrlInputDto.cs

@ -1,10 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Volo.CmsKit.Admin.Pages
{
public class CheckUrlInputDto
{
[Required]
public string Url { get; set; }
}
}

3
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CreatePageInputDto.cs

@ -11,5 +11,8 @@ namespace Volo.CmsKit.Admin.Pages
public string Url { get; set; }
public string Description { get; set; }
[Required]
public string Content { get; set; }
}
}

18
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CreatePageWithContentInputDto.cs

@ -1,18 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Volo.CmsKit.Admin.Pages
{
public class CreatePageWithContentInputDto
{
[Required]
public string Title { get; set; }
[Required]
public string Url { get; set; }
public string Description { get; set; }
[Required]
public string Content { get; set; }
}
}

9
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/GetPagesInputDto.cs

@ -0,0 +1,9 @@
using Volo.Abp.Application.Dtos;
namespace Volo.CmsKit.Admin.Pages
{
public class GetPagesInputDto : PagedAndSortedResultRequestDto
{
public string Filter { get; set; }
}
}

17
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/IPageAdminAppService.cs

@ -1,22 +1,11 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.CmsKit.Admin.Pages
{
public interface IPageAdminAppService
public interface IPageAdminAppService : ICrudAppService<PageDto, PageDto, Guid, GetPagesInputDto, CreatePageInputDto, UpdatePageInputDto>
{
Task<PageDto> GetAsync(Guid id);
Task<PageDto> CreatePageAsync(CreatePageInputDto input);
Task<PageDto> CreatePageWithContentAsync(CreatePageWithContentInputDto input);
Task<PageDto> UpdatePageAsync(Guid id, UpdatePageInputDto input);
Task<bool> DoesUrlExistAsync(CheckUrlInputDto input);
Task UpdatePageContentAsync(Guid id, UpdatePageContentInputDto input);
Task DeleteAsync(Guid id);
Task<bool> ExistsAsync(string url);
}
}

17
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/PageWithContentDto.cs

@ -1,17 +0,0 @@
using System;
using Volo.Abp.Application.Dtos;
using Volo.CmsKit.Admin.Contents;
namespace Volo.CmsKit.Admin.Pages
{
public class PageWithContentDto : EntityDto<Guid>
{
public string Title { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public ContentDto Content { get; set; }
}
}

10
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/UpdatePageContentInputDto.cs

@ -1,10 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Volo.CmsKit.Admin.Pages
{
public class UpdatePageContentInputDto
{
[Required]
public string Content { get; set; }
}
}

3
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/UpdatePageInputDto.cs

@ -11,5 +11,8 @@ namespace Volo.CmsKit.Admin.Pages
public string Url { get; set; }
public string Description { get; set; }
[Required]
public string Content { get; set; }
}
}

66
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Pages/PageAdminAppService.cs

@ -1,12 +1,20 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Contents;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Pages;
using Volo.CmsKit.Permissions;
namespace Volo.CmsKit.Admin.Pages
{
[RequiresGlobalFeature(typeof(PagesFeature))]
[Authorize(CmsKitAdminPermissions.Pages.Default)]
public class PageAdminAppService : CmsKitAdminAppServiceBase, IPageAdminAppService
{
protected readonly IPageRepository PageRepository;
@ -25,18 +33,28 @@ namespace Volo.CmsKit.Admin.Pages
return ObjectMapper.Map<Page, PageDto>(page);
}
public virtual async Task<PageDto> CreatePageAsync(CreatePageInputDto input)
public virtual async Task<PagedResultDto<PageDto>> GetListAsync(GetPagesInputDto input)
{
var page = await CreatePageAsync(input.Title, input.Url, input.Description);
await PageRepository.InsertAsync(page);
return ObjectMapper.Map<Page, PageDto>(page);
var count = await PageRepository.GetCountAsync(input.Filter);
var pages = await PageRepository.GetListAsync(
input.Filter,
input.MaxResultCount,
input.SkipCount,
input.Sorting
);
return new PagedResultDto<PageDto>(
count,
ObjectMapper.Map<List<Page>, List<PageDto>>(pages)
);
}
public virtual async Task<PageDto> CreatePageWithContentAsync(CreatePageWithContentInputDto input)
[Authorize(CmsKitAdminPermissions.Pages.Create)]
public virtual async Task<PageDto> CreateAsync(CreatePageInputDto input)
{
var page = await CreatePageAsync(input.Title, input.Url, input.Description);
await CheckPageUrlAsync(input.Url);
var page = new Page(GuidGenerator.Create(), input.Title, input.Url, input.Description, CurrentTenant?.Id);
await PageRepository.InsertAsync(page);
@ -52,7 +70,8 @@ namespace Volo.CmsKit.Admin.Pages
return ObjectMapper.Map<Page, PageDto>(page);
}
public virtual async Task<PageDto> UpdatePageAsync(Guid id, UpdatePageInputDto input)
[Authorize(CmsKitAdminPermissions.Pages.Update)]
public virtual async Task<PageDto> UpdateAsync(Guid id, UpdatePageInputDto input)
{
var page = await PageRepository.GetAsync(id);
@ -67,39 +86,30 @@ namespace Volo.CmsKit.Admin.Pages
await PageRepository.UpdateAsync(page);
return ObjectMapper.Map<Page, PageDto>(page);
}
var content = await ContentRepository.GetAsync(nameof(Page), page.Id.ToString());
public virtual Task<bool> DoesUrlExistAsync(CheckUrlInputDto input)
{
return PageRepository.DoesExistAsync(input.Url);
}
content.SetValue(input.Content);
public virtual async Task UpdatePageContentAsync(Guid id, UpdatePageContentInputDto input)
{
var pageContent = await ContentRepository.GetAsync(nameof(Page), id.ToString());
await ContentRepository.UpdateAsync(content);
pageContent.SetValue(input.Content);
return ObjectMapper.Map<Page, PageDto>(page);
}
await ContentRepository.UpdateAsync(pageContent);
public virtual Task<bool> ExistsAsync(string url)
{
return PageRepository.ExistsAsync(url);
}
[Authorize(CmsKitAdminPermissions.Pages.Delete)]
public virtual async Task DeleteAsync(Guid id)
{
await ContentRepository.DeleteAsync(nameof(Page), id.ToString(), CurrentTenant?.Id, CancellationToken.None);
await PageRepository.DeleteAsync(id, cancellationToken: CancellationToken.None);
}
protected virtual async Task<Page> CreatePageAsync(string title, string url, string description)
{
await CheckPageUrlAsync(url);
return new Page(GuidGenerator.Create(), title, url, description, CurrentTenant?.Id);
}
protected virtual async Task CheckPageUrlAsync(string url)
{
if (await PageRepository.DoesExistAsync(url))
if (await PageRepository.ExistsAsync(url))
{
throw new UserFriendlyException("Url exist");
}

70
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Page/PageAdminController.cs

@ -1,70 +0,0 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.CmsKit.Admin.Pages;
namespace Volo.CmsKit.Admin.Page
{
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)]
[Area("cms-kit")]
[Route("api/cms-kit-admin/pages")]
public class PageAdminController : CmsKitAdminController, IPageAdminAppService
{
protected readonly IPageAdminAppService PageAdminAppService;
public PageAdminController(IPageAdminAppService pageAdminAppService)
{
PageAdminAppService = pageAdminAppService;
}
[HttpGet]
[Route("{id}")]
public virtual Task<PageDto> GetAsync(Guid id)
{
return PageAdminAppService.GetAsync(id);
}
[HttpPost]
[Route("create")]
public virtual Task<PageDto> CreatePageAsync(CreatePageInputDto input)
{
return PageAdminAppService.CreatePageAsync(input);
}
[HttpPost]
[Route("create-with-content")]
public virtual Task<PageDto> CreatePageWithContentAsync(CreatePageWithContentInputDto input)
{
return PageAdminAppService.CreatePageWithContentAsync(input);
}
[HttpPut]
[Route("{id}")]
public virtual Task<PageDto> UpdatePageAsync(Guid id, UpdatePageInputDto input)
{
return PageAdminAppService.UpdatePageAsync(id, input);
}
[HttpPost]
[Route("does-url-exist")]
public virtual Task<bool> DoesUrlExistAsync(CheckUrlInputDto input)
{
return PageAdminAppService.DoesUrlExistAsync(input);
}
[HttpPut]
[Route("update-content/{id}")]
public virtual Task UpdatePageContentAsync(Guid id, UpdatePageContentInputDto input)
{
return PageAdminAppService.UpdatePageContentAsync(id, input);
}
[HttpDelete]
[Route("{id}")]
public virtual Task DeleteAsync(Guid id)
{
return PageAdminAppService.DeleteAsync(id);
}
}
}

70
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Pages/PageAdminController.cs

@ -0,0 +1,70 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Permissions;
namespace Volo.CmsKit.Admin.Pages
{
[RequiresGlobalFeature(typeof(PagesFeature))]
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)]
[Area("cms-kit")]
[Authorize(CmsKitAdminPermissions.Pages.Default)]
[Route("api/cms-kit-admin/pages")]
public class PageAdminController : CmsKitAdminController, IPageAdminAppService
{
protected readonly IPageAdminAppService PageAdminAppService;
public PageAdminController(IPageAdminAppService pageAdminAppService)
{
PageAdminAppService = pageAdminAppService;
}
[HttpGet]
[Route("{id}")]
public virtual Task<PageDto> GetAsync(Guid id)
{
return PageAdminAppService.GetAsync(id);
}
[HttpGet]
public virtual Task<PagedResultDto<PageDto>> GetListAsync(GetPagesInputDto input)
{
return PageAdminAppService.GetListAsync(input);
}
[HttpPost]
[Authorize(CmsKitAdminPermissions.Pages.Create)]
public virtual Task<PageDto> CreateAsync(CreatePageInputDto input)
{
return PageAdminAppService.CreateAsync(input);
}
[HttpPost]
[Authorize(CmsKitAdminPermissions.Pages.Update)]
[Route("{id}")]
public virtual Task<PageDto> UpdateAsync(Guid id, UpdatePageInputDto input)
{
return PageAdminAppService.UpdateAsync(id, input);
}
[HttpDelete]
[Authorize(CmsKitAdminPermissions.Pages.Delete)]
[Route("{id}")]
public virtual Task DeleteAsync(Guid id)
{
return PageAdminAppService.DeleteAsync(id);
}
[HttpGet]
[Route("exists/{url}")]
public virtual Task<bool> ExistsAsync(string url)
{
return PageAdminAppService.ExistsAsync(url);
}
}
}
Loading…
Cancel
Save