public async Task <IActionResult> AddNote([FromBody] string?title, [FromBody] string?content) { var userName = this.HttpContext.GetUserName(); if (userName is null) { return(Unauthorized()); } var creator = await _authors.GetByUserName(userName, _cancellation); if (!creator.HasValue) { return(Unauthorized()); } if (title is null || content is null) { return(BadRequest()); } var input = new NotesRepository.NoteInput(title, content); var note = await _notes.AddNote(input, creator.Value, _cancellation); return(new RestResult(NoteDTO.FromNote(note))); }
public async Task <IActionResult> GetNoteById(int id) { var note = await _notes.GetById(id, _cancellation); if (!note.HasValue) { return(NotFound()); } return(new RestResult(NoteDTO.FromNote(note.Value))); }