Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Use dedicated edit dto #253

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,16 @@ public async Task<ActionResult<LinkDto>> Create([FromBody] LinkCreateDto newLink
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult> Update(Guid linkId, [FromBody] LinkDto updatedLink)
public async Task<ActionResult> Update(Guid linkId, [FromBody] LinkEditDto updatedLink)
{
if (!ModelState.IsValid)
return BadRequest();

using var scope =
_logger.BeginScope("Updating a link with id {linkId} with {newLink}", linkId, updatedLink);
var link = _mapper.Map<Link>(updatedLink);
link.Id = linkId;
link.CreatingUserId = User.GetIdAsGuid();
if (!TryValidateModel(link))
{
return BadRequest();
}
try
{
await _repository.UpdateLinkAsync(link, User.GetIdAsGuid()).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public LinkMappingProfile()
{
CreateMap<Link, LinkDto>();
CreateMap<LinkCreateDto, Link>();
CreateMap<LinkEditDto, Link>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using Rinkudesu.Services.Links.Models;

namespace Rinkudesu.Services.Links.DataTransferObjects.V1
{
/// <summary>
/// Data transfer object to send and receive <see cref="Link"/> objects
/// </summary>
[ExcludeFromCodeCoverage]
public class LinkEditDto
{
/// <summary>
/// URL the link is pointing to
/// </summary>
[DataType(DataType.Url)]
[MaxLength(200)]
[SuppressMessage("Design", "CA1056:URI-like properties should not be strings")]
public string LinkUrl { get; set; } = null!;
/// <summary>
/// Title of the link
/// </summary>
[MaxLength(250)]
public string Title { get; set; } = null!;
/// <summary>
/// Description of the link
/// </summary>
[MaxLength(1000)]
public string? Description { get; set; }
/// <summary>
/// Privacy configuration of the link
/// </summary>
public Link.LinkPrivacyOptions PrivacyOptions { get; set; }

/// <summary>
/// Verifies whether <see cref="LinkUrl"/> is a valid absolute url.
/// </summary>
public bool IsLinkUrlValid() => Uri.TryCreate(LinkUrl, UriKind.Absolute, out _);
}
}