Skip to content

Commit

Permalink
renaming text to content and added title (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangroese committed Jun 23, 2023
1 parent 8882059 commit 5ae7832
Show file tree
Hide file tree
Showing 16 changed files with 10,115 additions and 401 deletions.
127 changes: 64 additions & 63 deletions Orso.Arpa.Api/Controllers/NewsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,81 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Orso.Arpa.Application.Interfaces;
using Orso.Arpa.Domain.Roles;
using Orso.Arpa.Application.NewsApplication;
using Orso.Arpa.Domain.Roles;

namespace Orso.Arpa.Api.Controllers
{
public class NewsController : BaseController
{
private readonly INewsService _newsService;

public NewsController(INewsService newsService)
{
_newsService = newsService;
}
namespace Orso.Arpa.Api.Controllers;

[Authorize(Roles = RoleNames.PerformerOrStaff)]
[HttpGet("{id:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
public async Task<ActionResult<NewsDto>> GetById([FromRoute] Guid id)
{
return await _newsService.GetByIdAsync(id);
}
public class NewsController : BaseController
{
private readonly INewsService _newsService;

[Authorize(Roles = RoleNames.PerformerOrStaff)]
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<IEnumerable<NewsDto>>> Get(
[FromQuery] int? limit,
[FromQuery] int? offset,
[FromQuery] bool includeHidden)
{
return Ok(await _newsService.GetAsync(limit, offset, includeHidden));
}
public NewsController(INewsService newsService)
{
_newsService = newsService;
}

[Authorize(Roles = RoleNames.Staff)]
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<NewsDto>> Post([FromBody] NewsCreateDto createDto)
{
NewsDto createdDto = await _newsService.CreateAsync(createDto);
[Authorize(Roles = RoleNames.PerformerOrStaff)]
[HttpGet("{id:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
public async Task<ActionResult<NewsDto>> GetById([FromRoute] Guid id)
{
return await _newsService.GetByIdAsync(id);
}

return CreatedAtAction(nameof(GetById), new{ id = createdDto.Id }, createdDto);
}
/// <summary>
/// Gets all news
/// </summary>
/// <returns>All news</returns>
/// <response code="200"></response>
[Authorize(Roles = RoleNames.PerformerOrStaff)]
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<IEnumerable<NewsDto>>> Get(
[FromQuery] int? limit,
[FromQuery] int? offset,
[FromQuery] bool includeHidden)
{
return Ok(await _newsService.GetAsync(limit, offset, includeHidden));
}

[Authorize(Roles = RoleNames.Staff)]
[HttpPut("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails),
StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> Put(NewsModifyDto modifyDto)
{
await _newsService.ModifyAsync(modifyDto);
[Authorize(Roles = RoleNames.Staff)]
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails),
StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<NewsDto>> Post([FromBody] NewsCreateDto createDto)
{
NewsDto createdDto = await _newsService.CreateAsync(createDto);

return NoContent();
return CreatedAtAction(nameof(GetById), new { id = createdDto.Id }, createdDto);
}

}
[Authorize(Roles = RoleNames.Staff)]
[HttpPut("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails),
StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> Put(NewsModifyDto modifyDto)
{
await _newsService.ModifyAsync(modifyDto);

[Authorize(Roles = RoleNames.Staff)]
[HttpDelete("{id:guid}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails),
StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult> Delete([FromRoute] Guid id)
{
await _newsService.DeleteAsync(id);
return NoContent();
}

return NoContent();
}
[Authorize(Roles = RoleNames.Staff)]
[HttpDelete("{id:guid}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails),
StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult> Delete([FromRoute] Guid id)
{
await _newsService.DeleteAsync(id);

return NoContent();
}

}

25 changes: 13 additions & 12 deletions Orso.Arpa.Application/Interfaces/INewsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
using System.Threading.Tasks;
using Orso.Arpa.Application.NewsApplication;

namespace Orso.Arpa.Application.Interfaces
namespace Orso.Arpa.Application.Interfaces;

public interface INewsService
{
public interface INewsService
{
Task<NewsDto> CreateAsync(NewsCreateDto createDto);
Task<IEnumerable<NewsDto>> GetAsync(
int? limit,
int? offset,
bool includeHidden);
Task<NewsDto> GetByIdAsync(Guid id);
Task ModifyAsync(NewsModifyDto modifyDto);
Task DeleteAsync(Guid id);
}
Task<NewsDto> CreateAsync(NewsCreateDto createDto);

Task<IEnumerable<NewsDto>> GetAsync(
int? limit,
int? offset,
bool includeHidden);

Task<NewsDto> GetByIdAsync(Guid id);
Task ModifyAsync(NewsModifyDto modifyDto);
Task DeleteAsync(Guid id);
}
47 changes: 25 additions & 22 deletions Orso.Arpa.Application/NewsApplication/NewsCreateDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@
using Orso.Arpa.Application.Extensions;
using static Orso.Arpa.Domain.Logic.News.Create;

namespace Orso.Arpa.Application.NewsApplication
namespace Orso.Arpa.Application.NewsApplication;

public class NewsCreateDto
{
public string Title { get; set; }
public string Content { get; set; }
public string Url { get; set; }
public bool Show { get; set; }
}

public class NewsCreateDto
public class NewsCreateDtoMappingProfile : Profile
{
public NewsCreateDtoMappingProfile()
{
public string NewsText { get; set; }
public string Url { get; set; }
public bool Show { get; set; }
_ = CreateMap<NewsCreateDto, Command>();
}
}

public class NewsCreateDtoMappingProfile : Profile
public class NewsCreateDtoValidator : AbstractValidator<NewsCreateDto>
{
public NewsCreateDtoValidator()
{
public NewsCreateDtoMappingProfile()
{
_ = CreateMap<NewsCreateDto, Command>();
}
}
_ = RuleFor(c => c.Title)
.NotEmpty()
.FreeText(200);

public class NewsCreateDtoValidator : AbstractValidator<NewsCreateDto>
{
public NewsCreateDtoValidator()
{
_ = RuleFor(c => c.NewsText)
.NotEmpty()
.FreeText(1000);
_ = RuleFor(c => c.Url)
.ValidUri(1000)
.When(dto => !string.IsNullOrEmpty(dto.Url));
_ = RuleFor(c => c.Content)
.NotEmpty()
.FreeText(1000);

}
_ = RuleFor(c => c.Url)
.ValidUri(1000)
.When(dto => !string.IsNullOrEmpty(dto.Url));
}
}
26 changes: 13 additions & 13 deletions Orso.Arpa.Application/NewsApplication/NewsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
using Orso.Arpa.Application.General;
using Orso.Arpa.Domain.Entities;

namespace Orso.Arpa.Application.NewsApplication
namespace Orso.Arpa.Application.NewsApplication;

public class NewsDto : BaseEntityDto
{
public class NewsDto : BaseEntityDto
{
public string NewsText { get; set; }
public string Url { get; set; }
public bool Show { get; set; }
}
public string Title { get; set; }
public string Content { get; set; }
public string Url { get; set; }
public bool Show { get; set; }
}

public class NewsDtoMappingProfile : Profile
public class NewsDtoMappingProfile : Profile
{
public NewsDtoMappingProfile()
{
public NewsDtoMappingProfile()
{
CreateMap<News, NewsDto>()
.IncludeBase<BaseEntity, BaseEntityDto>();
}
CreateMap<News, NewsDto>()
.IncludeBase<BaseEntity, BaseEntityDto>();
}
}
79 changes: 42 additions & 37 deletions Orso.Arpa.Application/NewsApplication/NewsModifyDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,56 @@
using Orso.Arpa.Application.General;
using static Orso.Arpa.Domain.Logic.News.Modify;

namespace Orso.Arpa.Application.NewsApplication
namespace Orso.Arpa.Application.NewsApplication;

public class NewsModifyDto : IdFromRouteDto<NewsModifyBodyDto>
{
public class NewsModifyDto : IdFromRouteDto<NewsModifyBodyDto>
{
}
}

public class NewsModifyBodyDto
{
public string NewsText { get; set; }
public string Url { get; set; }
public bool Show { get; set; }
}
public class NewsModifyBodyDto
{
public string Title { get; set; }
public string Content { get; set; }
public string Url { get; set; }
public bool Show { get; set; }
}

public class NewsModifyDtoMappingProfile : Profile
public class NewsModifyDtoMappingProfile : Profile
{
public NewsModifyDtoMappingProfile()
{
public NewsModifyDtoMappingProfile()
{
_ = CreateMap<NewsModifyDto, Command>()
.ForMember(dest => dest.NewsText,
opt => opt.MapFrom(src => src.Body.NewsText))
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => src.Body.Url))
.ForMember(dest => dest.Show, opt => opt.MapFrom(src => src.Body.Show))
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id));
}
_ = CreateMap<NewsModifyDto, Command>()
.ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Body.Title))
.ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Body.Content))
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => src.Body.Url))
.ForMember(dest => dest.Show, opt => opt.MapFrom(src => src.Body.Show))
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id));
}
public class NewsModifyDtoValidator : IdFromRouteDtoValidator<NewsModifyDto, NewsModifyBodyDto>
}

public class NewsModifyDtoValidator : IdFromRouteDtoValidator<NewsModifyDto, NewsModifyBodyDto>
{
public NewsModifyDtoValidator()
{
public NewsModifyDtoValidator()
{
_ = RuleFor(d => d.Body)
.SetValidator(new NewsModifyBodyDtoValidator());
}
_ = RuleFor(d => d.Body)
.SetValidator(new NewsModifyBodyDtoValidator());
}
}

public class NewsModifyBodyDtoValidator : AbstractValidator<NewsModifyBodyDto>
public class NewsModifyBodyDtoValidator : AbstractValidator<NewsModifyBodyDto>
{
public NewsModifyBodyDtoValidator()
{
public NewsModifyBodyDtoValidator()
{
_ = RuleFor(c => c.NewsText)
.NotEmpty()
.FreeText(1000);

_ = RuleFor(c => c.Url)
.ValidUri(1000)
.When(dto => !string.IsNullOrEmpty(dto.Url));
}
_ = RuleFor(c => c.Title)
.NotEmpty()
.FreeText(200);

_ = RuleFor(c => c.Content)
.NotEmpty()
.FreeText(1000);

_ = RuleFor(c => c.Url)
.ValidUri(1000)
.When(dto => !string.IsNullOrEmpty(dto.Url));
}
}
Loading

0 comments on commit 5ae7832

Please sign in to comment.