public async Task <SubjectResponseModel> GetSubject(int subjectId, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var query = new FindSubjectByIdQuery(subjectId); var subject = await _mediator.Send(query, cancellationToken); if (subject == null) { throw new NotFoundException(nameof(subject), subjectId); } var response = _mapper.Map <SubjectResponseModel>(subject); return(response); }
public async Task <SubjectResponseModel> PostSubject( [FromForm] SubjectRequestModel model, CancellationToken cancellationToken ) { cancellationToken.ThrowIfCancellationRequested(); var command = new CreateSubjectCommand( model.GroupId, model.Name ); var subjectId = await _mediator.Send(command, cancellationToken); var query = new FindSubjectByIdQuery(subjectId); var subject = await _mediator.Send(query, cancellationToken); var response = _mapper.Map <SubjectResponseModel>(subject); return(response); }