Add link stuff #8

Merged
jleicher merged 5 commits from add-link into master 2020-12-04 16:27:43 +01:00
2 changed files with 9 additions and 2 deletions
Showing only changes of commit bdf1722f43 - Show all commits

View File

@ -5,6 +5,7 @@ using HN.Domain;
using MediatR; using MediatR;
namespace HN.Application { namespace HN.Application {
public class AddLinkCommand : IRequest<Guid> public class AddLinkCommand : IRequest<Guid>
{ {
public string Url { get; set; } public string Url { get; set; }
@ -21,11 +22,12 @@ namespace HN.Application {
public async Task<Guid> Handle(AddLinkCommand request, CancellationToken cancellationToken) public async Task<Guid> Handle(AddLinkCommand request, CancellationToken cancellationToken)
{ {
var link = new Link(request.Url); var link = Link.FromUrl(request.Url);
await this._repository.AddAsync(link); await this._repository.AddAsync(link);
return link.Id; return link.Id;
} }
} }
} }

View File

@ -8,11 +8,16 @@ namespace HN.Domain
public string Url { get; } public string Url { get; }
public DateTime CreatedAt { get; } public DateTime CreatedAt { get; }
public Link(string url) private Link(string url)
{ {
this.Id = Guid.NewGuid(); this.Id = Guid.NewGuid();
this.CreatedAt = DateTime.UtcNow; this.CreatedAt = DateTime.UtcNow;
this.Url = url; this.Url = url;
} }
public static Link FromUrl(string url)
{
return new Link(url);
}
} }
} }