Skip to content

Commit

Permalink
adjustments - session with mira
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangroese committed Jun 19, 2023
1 parent c5dadf5 commit 7bc4a0d
Show file tree
Hide file tree
Showing 24 changed files with 10,075 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,74 @@
using Microsoft.AspNetCore.Mvc;
using Orso.Arpa.Application.Interfaces;
using Orso.Arpa.Domain.Roles;
using Orso.Arpa.Application.MessageApplication;
using Orso.Arpa.Application.NewsApplication;

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

public MessagesController(IMessageService messageService)
public NewsController(INewsService newsService)
{
_messageService = messageService;
_newsService = newsService;
}

// Gets a message by id
[Authorize(Roles = RoleNames.Performer)]
[HttpGet("{id}")]
[Authorize(Roles = RoleNames.PerformerOrStaff)]
[HttpGet("{id:guid}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
public async Task<ActionResult<MessageDto>> GetById([FromRoute] Guid id)
public async Task<ActionResult<NewsDto>> GetById([FromRoute] Guid id)
{
return await _messageService.GetByIdAsync(id);
return await _newsService.GetByIdAsync(id);
}

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

// Creates a new message
[Authorize(Roles = RoleNames.Staff)]
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<MessageDto>> Post([FromBody] MessageCreateDto createDto)
public async Task<ActionResult<NewsDto>> Post([FromBody] NewsCreateDto createDto)
{
MessageDto createdDto = await _messageService.CreateAsync(createDto);
NewsDto createdDto = await _newsService.CreateAsync(createDto);

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

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

return NoContent();

}

//Deletes existing message by id
[Authorize(Roles = RoleNames.Staff)]
[HttpDelete("{id}")]
[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 _messageService.DeleteAsync(id);
await _newsService.DeleteAsync(id);

return NoContent();
}
Expand Down
16 changes: 0 additions & 16 deletions Orso.Arpa.Application/Interfaces/IMessageService.cs

This file was deleted.

19 changes: 19 additions & 0 deletions Orso.Arpa.Application/Interfaces/INewsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Orso.Arpa.Application.NewsApplication;

namespace Orso.Arpa.Application.Interfaces
{
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);
}
}
53 changes: 0 additions & 53 deletions Orso.Arpa.Application/MessageApplication/MessageCreateDto.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Orso.Arpa.Application/MessageApplication/MessageDto.cs

This file was deleted.

63 changes: 0 additions & 63 deletions Orso.Arpa.Application/MessageApplication/MessageModifyDto.cs

This file was deleted.

39 changes: 39 additions & 0 deletions Orso.Arpa.Application/NewsApplication/NewsCreateDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using AutoMapper;
using FluentValidation;
using Orso.Arpa.Application.Extensions;
using Orso.Arpa.Application.General;
using static Orso.Arpa.Domain.Logic.News.Create;

namespace Orso.Arpa.Application.NewsApplication
{

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

public class NewsCreateDtoMappingProfile : Profile
{
public NewsCreateDtoMappingProfile()
{
CreateMap<NewsCreateDto, Command>();
}
}

public class NewsCreateDtoValidator : AbstractValidator<NewsCreateDto>
{
public NewsCreateDtoValidator()
{
RuleFor(c => c.NewsText)
.Cascade(CascadeMode.Stop)
.NotEmpty()
.FreeText(1000);
RuleFor(c => c.Url)
.ValidUri(1000);

}
}
}
22 changes: 22 additions & 0 deletions Orso.Arpa.Application/NewsApplication/NewsDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using AutoMapper;
using Orso.Arpa.Application.General;
using Orso.Arpa.Domain.Entities;

namespace Orso.Arpa.Application.NewsApplication
{
public class NewsDto : BaseEntityDto
{
public string NewsText { get; set; }
public string Url { get; set; }
public bool Show { get; set; }
}

public class NewsDtoMappingProfile : Profile
{
public NewsDtoMappingProfile()
{
CreateMap<News, NewsDto>()
.IncludeBase<BaseEntity, BaseEntityDto>();
}
}
}
56 changes: 56 additions & 0 deletions Orso.Arpa.Application/NewsApplication/NewsModifyDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using AutoMapper;
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using Orso.Arpa.Application.Extensions;
using Orso.Arpa.Application.General;
using static Orso.Arpa.Domain.Logic.News.Modify;

namespace Orso.Arpa.Application.NewsApplication
{
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 NewsModifyDtoMappingProfile : Profile
{
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));
}
}
public class NewsModifyDtoValidator : IdFromRouteDtoValidator<NewsModifyDto, NewsModifyBodyDto>
{
public NewsModifyDtoValidator()
{
RuleFor(d => d.Body)
.SetValidator(new NewsModifyBodyDtoValidator());
}
}

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

RuleFor(c => c.Url)
.ValidUri(1000);
}
}
}
Loading

0 comments on commit 7bc4a0d

Please sign in to comment.