Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 8962a30

Browse files
committed
Adicionados comentários no SWAGGER #1
1 parent c961bc0 commit 8962a30

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

DevStudyNotes.API/Controllers/StudyNotesController.cs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,98 @@ public class StudyNotesController : ControllerBase
1515
public StudyNotesController(StudyNoteDbContext context)
1616
=> _context = context;
1717

18+
// GET: api/study-notes
19+
/// <summary>
20+
/// Listagem de Notas de Estudo
21+
/// </summary>
22+
/// <returns>Lista de Notas de Estudo</returns>
23+
/// <response code="200">Sucesso</response>
1824
[HttpGet]
25+
[ProducesResponseType(StatusCodes.Status200OK)]
1926
public IActionResult GetAll()
2027
{
2128
var studyNotes = _context.StudyNotes.ToList();
2229

2330
return Ok(studyNotes);
2431
}
2532

33+
// GET: api/study-notes/{id}
34+
/// <summary>
35+
/// Detalhes da Nota de Estudo
36+
/// </summary>
37+
/// <param name="id">ID da Nota de Estudo</param>
38+
/// <returns>Mostra uma Nota de Estudo</returns>
39+
/// <response code="200">Sucesso</response>
40+
/// <response code="404">Não encontrado</response>
2641
[HttpGet("{id}")]
42+
[ProducesResponseType(StatusCodes.Status200OK)]
43+
[ProducesResponseType(StatusCodes.Status404NotFound)]
2744
public IActionResult GetById(int id)
2845
{
2946
var studyNote = _context.StudyNotes.Include(s => s.Reactions).SingleOrDefault(s => s.Id == id);
3047

3148
if (studyNote == null)
32-
return NotFound();
49+
return NotFound("Nota de Estudo não encontrada.");
3350

3451
return Ok(studyNote);
3552
}
3653

37-
// api/study-notes HTTP POST
54+
// POST: api/study-notes
3855
/// <summary>
39-
/// Cadastrar uma nota de estudo
56+
/// Cadastro de Nota de Estudo
4057
/// </summary>
4158
/// <remarks>
42-
/// { "title": "Estudos AZ-400", "description": "Sobre o Azure Blob Storage", "isPublic": true }
59+
/// Requisição:
60+
/// {
61+
/// "title": "Estudos AZ-400",
62+
/// "description": "Sobre o Azure Blob Storage",
63+
/// "isPublic": true
64+
/// }
4365
/// </remarks>
44-
/// <param name="model">Dados de uma nota de estudo</param>
45-
/// <returns>Objeto recém-criado</returns>
66+
/// <param name="model">Dados da Nota de Estudo</param>
67+
/// <returns>Objeto criado</returns>
4668
/// <response code="201">Sucesso</response>
69+
/// <response code="400">Dados inválidos</response>
4770
[HttpPost]
71+
[ProducesResponseType(StatusCodes.Status201Created)]
72+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
4873
public IActionResult Post(AddStudyNoteInputModel model)
4974
{
5075
var studyNote = new StudyNote(model.Title, model.Description, model.IsPublic);
5176

5277
_context.StudyNotes.Add(studyNote);
5378
_context.SaveChanges();
5479

55-
return CreatedAtAction("GetById", new { id = studyNote.Id }, model);
80+
return CreatedAtAction(nameof(GetById), new { id = studyNote.Id }, model);
5681
}
5782

83+
// POST: api/study-notes/{id}/reactions
84+
/// <summary>
85+
/// Cadastro de Reações da Nota de Estudo
86+
/// </summary>
87+
/// <remarks>
88+
/// Requisição:
89+
/// {
90+
/// "studyNoteId": 1,
91+
/// "isPositive": true
92+
/// }
93+
/// </remarks>
94+
/// <param name="id">ID da Nota de Estudo</param>
95+
/// <param name="model">Dados da Reação da Nota de Estudo</param>
96+
/// <returns>Objeto criado</returns>
97+
/// <response code="204">Sucesso</response>
98+
/// <response code="400">Dados inválidos</response>
99+
/// <response code="404">Não encontrado</response>
58100
[HttpPost("{id}/reactions")]
101+
[ProducesResponseType(StatusCodes.Status204NoContent)]
102+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
103+
[ProducesResponseType(StatusCodes.Status404NotFound)]
59104
public IActionResult PostReaction(int id, AddReactionStudyNoteInputModel model)
60105
{
61106
var studyNote = _context.StudyNotes.SingleOrDefault(s => s.Id == id);
62107

63108
if (studyNote == null)
64-
return BadRequest();
109+
return NotFound("Nota de Estudo não encontrada.");
65110

66111
studyNote.AddReaction(model.IsPositive);
67112

README_IMGS/swagger_ui.png

14.7 KB
Loading

0 commit comments

Comments
 (0)