Skip to content

Commit 266aa07

Browse files
Refactor: Controller categoria deverá chamar apenas a service.
1 parent 81e867f commit 266aa07

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

Controllers/CategorieTaskController.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,8 @@ public IActionResult UpdateCategorieTask([FromBody] CategorieTaskEntity model)
5050
{
5151
try
5252
{
53-
CategorieTaskEntity categorieToUpdate = new()
54-
{
55-
Name = model.Name,
56-
Description = model.Description
57-
};
58-
59-
_context.CategorieTasks.Update(categorieToUpdate);
60-
_context.SaveChanges();
61-
return Ok("Categoria de tarefa atualizada com sucesso.");
53+
var categorieTask = _categorieTaskService.UpdateCategorieTask(model);
54+
return Ok(categorieTask);
6255
}
6356
catch (Exception ex)
6457
{

Services/CategorieTaskService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,25 @@ public IActionResult CreateCategorieTask([FromBody] CategorieTaskEntity model)
4646
}
4747
}
4848

49+
public IActionResult UpdateCategorieTask([FromBody] CategorieTaskEntity model)
50+
{
51+
try
52+
{
53+
CategorieTaskEntity categorieToUpdate = new()
54+
{
55+
Name = model.Name,
56+
Description = model.Description
57+
};
58+
59+
_context.CategorieTasks.Update(categorieToUpdate);
60+
_context.SaveChanges();
61+
return Ok("Categoria de tarefa atualizada com sucesso.");
62+
}
63+
catch (Exception ex)
64+
{
65+
return BadRequest("Não foi possível atualizar a categoria de tarefa.");
66+
}
67+
}
68+
4969
}
5070
}

0 commit comments

Comments
 (0)