-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateMovieHandler.cs
More file actions
50 lines (44 loc) · 1.57 KB
/
Copy pathCreateMovieHandler.cs
File metadata and controls
50 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using SmartMovieCatalog.Application.Abstractions.Persistence;
using SmartMovieCatalog.Application.Abstractions.Time;
using SmartMovieCatalog.Domain.Movies;
namespace SmartMovieCatalog.Application.Features.Movies;
public sealed class CreateMovieHandler
{
private readonly IMovieRepository _movieRepository;
private readonly IClock _clock;
public CreateMovieHandler(IMovieRepository movieRepository, IClock clock)
{
_movieRepository = movieRepository;
_clock = clock;
}
public async Task<CreatedMovie> Handle(CreateMovieCommand command, CancellationToken cancellationToken)
{
Movie movie = Movie.Create(
MovieId.New(),
command.Title,
command.OriginalTitle,
command.ReleaseYear,
command.CountryCode,
command.OriginalLanguage,
command.Genres?.Select(MovieGenre.Create),
command.Director,
command.Synopsis,
command.DurationMinutes,
command.AgeRating,
_clock.UtcNow);
await _movieRepository.AddAsync(movie, cancellationToken);
await _movieRepository.SaveChangesAsync(cancellationToken);
return new CreatedMovie(
movie.Id,
movie.Title,
movie.OriginalTitle,
movie.ReleaseYear,
movie.CountryCode,
movie.OriginalLanguage,
movie.Genres.Select(genre => genre.Name).ToArray(),
movie.Director,
movie.Synopsis,
movie.DurationMinutes,
movie.AgeRating);
}
}