Beispiel #1
0
        public async Task <IActionResult> CreateNoteAsync(
            [FromBody] Client.Notes.NoteBuildInfo clientBuildInfo,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!this.TryGetSessionState(this.HttpContext.Request.Cookies, out var state))
            {
                return(this.Unauthorized());
            }
            if (!this.ModelState.IsValid)
            {
                var error = ServiceErrorResponses.BodyIsMissing(nameof(Client.Notes.NoteBuildInfo));
                return(this.BadRequest(error));
            }

            var modelBuildInfo = NoteBuildInfoConverter.Convert(state.UserId.ToString(), clientBuildInfo);
            var modelNoteInfo  = await this.repository.CreateAsync(modelBuildInfo, cancellationToken).ConfigureAwait(false);

            var clientNoteInfo = NoteInfoConverter.Convert(modelNoteInfo);
            var routeParams    = new Dictionary <string, object>
            {
                { "noteId", clientNoteInfo.Id }
            };

            return(this.CreatedAtRoute("GetNoteRoute", routeParams, clientNoteInfo));
        }
        public async Task <IActionResult> SearchNotesAsync([FromQuery] Client.Notes.NoteInfoSearchQuery query, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var modelQuery = NoteInfoSearchQueryConverter.Convert(query ?? new Client.Notes.NoteInfoSearchQuery());
            var modelNotes = await this.repository.SearchAsync(modelQuery, cancellationToken).ConfigureAwait(false);

            var clientNotes     = modelNotes.Select(note => NoteInfoConverter.Convert(note)).ToList();
            var clientNotesList = new Client.Notes.NoteList
            {
                Notes = clientNotes
            };

            return(this.Ok(clientNotesList));
        }
Beispiel #3
0
        public async Task <IActionResult> SearchNotesAsync(
            [FromQuery] Client.Notes.NoteInfoSearchQuery clientQuery,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!this.TryGetSessionState(this.HttpContext.Request.Cookies, out var state))
            {
                return(this.Unauthorized());
            }

            var modelQuery = NoteInfoSearchQueryConverter.Convert(clientQuery ?? new Client.Notes.NoteInfoSearchQuery());

            modelQuery.UserId = state.UserId;
            var modelNotes = await this.repository.SearchAsync(modelQuery, cancellationToken).ConfigureAwait(false);

            var clientNotesList = modelNotes.Select(note => NoteInfoConverter.Convert(note)).ToList();

            return(this.Ok(clientNotesList));
        }
        public async Task <IActionResult> CreateNoteAsync([FromBody] Client.Notes.NoteBuildInfo buildInfo, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (buildInfo == null)
            {
                var error = ServiceErrorResponses.BodyIsMissing("NoteBuildInfo");
                return(this.BadRequest(error));
            }

            var userId = Guid.Empty.ToString(); // Нужно исправить

            var creationInfo  = NoteBuildInfoConverter.Convert(userId, buildInfo);
            var modelNoteInfo = await this.repository.CreateAsync(creationInfo, cancellationToken).ConfigureAwait(false);

            var clientNoteInfo = NoteInfoConverter.Convert(modelNoteInfo);

            var routeParams = new Dictionary <string, object>
            {
                { "noteId", clientNoteInfo.Id }
            };

            return(this.CreatedAtRoute("GetNoteRoute", routeParams, clientNoteInfo));
        }