Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

challenge solved #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 52 additions & 17 deletions Controllers/TarefaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,43 @@ public TarefaController(OrganizadorContext context)
[HttpGet("{id}")]
public IActionResult ObterPorId(int id)
{
// TODO: Buscar o Id no banco utilizando o EF
// TODO: Validar o tipo de retorno. Se não encontrar a tarefa, retornar NotFound,
// caso contrário retornar OK com a tarefa encontrada
return Ok();
// Implementado
var tarefa = _context.Tarefas.Find(id);

if (tarefa == null)
{
return NotFound();
}
return Ok(tarefa);

}

[HttpGet("ObterTodos")]
public IActionResult ObterTodos()
{
// TODO: Buscar todas as tarefas no banco utilizando o EF
return Ok();
// Implementado
var tarefa = _context.Tarefas.ToList();

if (tarefa == null || tarefa.Count == 0)
{
return NotFound("Nenhuma tarefa encontrada");
}

return Ok(tarefa);
}

[HttpGet("ObterPorTitulo")]
public IActionResult ObterPorTitulo(string titulo)
{
// TODO: Buscar as tarefas no banco utilizando o EF, que contenha o titulo recebido por parâmetro
// Dica: Usar como exemplo o endpoint ObterPorData
return Ok();
// Implementado
var tarefa = _context.Tarefas.Where(t => t.Titulo.Contains(titulo)).ToList();

if (tarefa == null || tarefa.Count == 0)
{
return NotFound("Pesquisa por titulo não encontrada");
}

return Ok(tarefa);
}

[HttpGet("ObterPorData")]
Expand All @@ -49,9 +67,13 @@ public IActionResult ObterPorData(DateTime data)
[HttpGet("ObterPorStatus")]
public IActionResult ObterPorStatus(EnumStatusTarefa status)
{
// TODO: Buscar as tarefas no banco utilizando o EF, que contenha o status recebido por parâmetro
// Dica: Usar como exemplo o endpoint ObterPorData
var tarefa = _context.Tarefas.Where(x => x.Status == status);
// Implementado
var tarefa = _context.Tarefas.Where(x => x.Status == status).ToList();

if (tarefa == null || tarefa.Count == 0)
{
return NotFound("Pesquisa por status não encontrada");
}
return Ok(tarefa);
}

Expand All @@ -61,7 +83,10 @@ public IActionResult Criar(Tarefa tarefa)
if (tarefa.Data == DateTime.MinValue)
return BadRequest(new { Erro = "A data da tarefa não pode ser vazia" });

// TODO: Adicionar a tarefa recebida no EF e salvar as mudanças (save changes)
// Implementado
_context.Tarefas.Add(tarefa);
_context.SaveChanges();

return CreatedAtAction(nameof(ObterPorId), new { id = tarefa.Id }, tarefa);
}

Expand All @@ -76,9 +101,16 @@ public IActionResult Atualizar(int id, Tarefa tarefa)
if (tarefa.Data == DateTime.MinValue)
return BadRequest(new { Erro = "A data da tarefa não pode ser vazia" });

// TODO: Atualizar as informações da variável tarefaBanco com a tarefa recebida via parâmetro
// TODO: Atualizar a variável tarefaBanco no EF e salvar as mudanças (save changes)
return Ok();
// Implementado
tarefaBanco.Titulo = tarefa.Titulo;
tarefaBanco.Status = tarefa.Status;
tarefaBanco.Descricao = tarefa.Descricao;
tarefaBanco.Data = tarefa.Data;

_context.Tarefas.Update(tarefaBanco);
_context.SaveChanges();

return Ok(tarefaBanco);
}

[HttpDelete("{id}")]
Expand All @@ -89,7 +121,10 @@ public IActionResult Deletar(int id)
if (tarefaBanco == null)
return NotFound();

// TODO: Remover a tarefa encontrada através do EF e salvar as mudanças (save changes)
// Implementado
_context.Tarefas.Remove(tarefaBanco);
_context.SaveChanges();

return NoContent();
}
}
Expand Down
2 changes: 1 addition & 1 deletion TrilhaApiDesafio.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
25 changes: 25 additions & 0 deletions TrilhaApiDesafio.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrilhaApiDesafio", "TrilhaApiDesafio.csproj", "{0CFC3774-11B6-48BA-8F21-333FCE752975}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0CFC3774-11B6-48BA-8F21-333FCE752975}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CFC3774-11B6-48BA-8F21-333FCE752975}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CFC3774-11B6-48BA-8F21-333FCE752975}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CFC3774-11B6-48BA-8F21-333FCE752975}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {359C325E-15BB-4B55-9E2F-1BCF6EAB4D7D}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
}
},
"ConnectionStrings": {
"ConexaoPadrao": "COLOCAR SUA CONNECTION STRING AQUI"
"ConexaoPadrao": "Server=localhost\\SQLEXPRESS; Initial Catalog=Organizador; Integrated Security=True"
}
}
2 changes: 1 addition & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
}
},
"AllowedHosts": "*"
}
}