Skip to content

Commit fc667b0

Browse files
Commit inicial do projeto To-Do List Full-Stack
0 parents  commit fc667b0

26 files changed

+1189
-0
lines changed

.gitignore

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ===================================================================
2+
# Arquivo .gitignore combinado para .NET (Backend) e Node (Frontend)
3+
# ===================================================================
4+
5+
# Ignora arquivos de configuração de IDEs e editores
6+
.vscode/
7+
.vs/
8+
*.suo
9+
*.user
10+
*.userosscache
11+
*.sln.docstates
12+
13+
# Ignora saídas de build e pacotes do .NET (Backend)
14+
**/[Bb]in/
15+
**/[Oo]bj/
16+
**/[Pp]ublish/
17+
**/[Dd]ebug/
18+
**/[Rr]elease/
19+
*.csproj.user
20+
*.dbmdl
21+
*.efbundle
22+
project.lock.json
23+
project.fragment.lock.json
24+
25+
# User Secrets file (MUITO IMPORTANTE)
26+
**/secrets.json
27+
28+
# Ignora saídas de build e pacotes do Node.js (Frontend)
29+
**/node_modules/
30+
**/dist/
31+
**/coverage/
32+
.angular/
33+
npm-debug.log*
34+
yarn-debug.log*
35+
yarn-error.log*
36+
pnpm-debug.log*
37+
38+
# Ignora arquivos de ambiente que podem conter segredos (se você usar .env)
39+
.env
40+
.env.local
41+
.env.*.local
42+
43+
# Ignora arquivos de log e temporários
44+
*.log
45+
*.tmp
46+
*.temp
47+
48+
# Ignora arquivos do sistema operacional
49+
.DS_Store
50+
Thumbs.db
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System.Threading.Tasks;
3+
using ToDoListProjeto.Api.Models;
4+
using ToDoListProjeto.Api.Services;
5+
6+
[ApiController]
7+
[Route("api/auth")]
8+
public class AuthController : ControllerBase
9+
{
10+
private readonly AuthService _authService;
11+
12+
public AuthController(AuthService authService)
13+
{
14+
_authService = authService;
15+
}
16+
17+
[HttpPost("register")]
18+
public async Task<IActionResult> Register(UserRegisterModel model)
19+
{
20+
var user = await _authService.Register(model);
21+
if (user == null)
22+
{
23+
return BadRequest(new { message = "Email já cadastrado." });
24+
}
25+
return Ok(new { message = "Usuário registrado com sucesso!" });
26+
}
27+
28+
[HttpPost("login")]
29+
public async Task<IActionResult> Login(UserLoginModel model)
30+
{
31+
var response = await _authService.Login(model);
32+
if (response == null)
33+
{
34+
return Unauthorized(new { message = "Credenciais inválidas." });
35+
}
36+
return Ok(response);
37+
}
38+
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.EntityFrameworkCore;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Security.Claims;
8+
using System.Threading.Tasks;
9+
using ToDoListProjeto.Api.Data;
10+
using ToDoListProjeto.Api.Models;
11+
using ToDoListProjeto.Api.Services;
12+
13+
[Authorize]
14+
[ApiController]
15+
[Route("api/tasks")]
16+
public class TasksController : ControllerBase
17+
{
18+
private readonly ApplicationDbContext _dbContext;
19+
private readonly AIService _aiService;
20+
public TasksController(ApplicationDbContext dbContext, AIService aiService)
21+
{
22+
_dbContext = dbContext;
23+
_aiService = aiService;
24+
}
25+
26+
27+
[HttpGet]
28+
public async Task<ActionResult<IEnumerable<TaskItem>>> GetTasks()
29+
{
30+
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
31+
if (string.IsNullOrEmpty(userId)) return Unauthorized();
32+
33+
return await _dbContext.TaskItems
34+
.Where(t => t.UserId == userId)
35+
.ToListAsync();
36+
}
37+
38+
39+
[HttpGet("{id}")]
40+
public async Task<ActionResult<TaskItem>> GetTask(int id)
41+
{
42+
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
43+
if (string.IsNullOrEmpty(userId)) return Unauthorized();
44+
45+
var taskItem = await _dbContext.TaskItems
46+
.Where(t => t.Id == id && t.UserId == userId)
47+
.FirstOrDefaultAsync();
48+
49+
if (taskItem == null) return NotFound();
50+
51+
return taskItem;
52+
}
53+
54+
[HttpPost]
55+
public async Task<ActionResult<TaskItem>> PostTask(TaskCreateModel model)
56+
{
57+
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
58+
if (string.IsNullOrEmpty(userId))
59+
{
60+
return Unauthorized();
61+
}
62+
63+
var newTaskItem = new TaskItem
64+
{
65+
Title = model.Title,
66+
Description = model.Description,
67+
Status = model.Status,
68+
Priority = model.Priority,
69+
UserId = userId,
70+
CreatedAt = DateTime.UtcNow
71+
};
72+
73+
_dbContext.TaskItems.Add(newTaskItem);
74+
await _dbContext.SaveChangesAsync();
75+
76+
return CreatedAtAction(nameof(GetTask), new { id = newTaskItem.Id }, newTaskItem);
77+
}
78+
79+
// IA
80+
[HttpPost("smart-add")]
81+
public async Task<ActionResult<TaskItem>> PostSmartTask([FromBody] SmartTaskModel model)
82+
{
83+
var parsedTask = await _aiService.ParseTaskFromPrompt(model.Prompt);
84+
85+
if (parsedTask == null || string.IsNullOrWhiteSpace(parsedTask.Title))
86+
{
87+
return BadRequest(new { message = "Não foi possível interpretar a tarefa a partir do texto fornecido." });
88+
}
89+
90+
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
91+
if (string.IsNullOrEmpty(userId)) return Unauthorized();
92+
93+
var newTaskItem = new TaskItem
94+
{
95+
Title = parsedTask.Title,
96+
Description = parsedTask.Description,
97+
Status = parsedTask.Status,
98+
Priority = parsedTask.Priority,
99+
UserId = userId,
100+
CreatedAt = DateTime.UtcNow
101+
};
102+
103+
_dbContext.TaskItems.Add(newTaskItem);
104+
await _dbContext.SaveChangesAsync();
105+
106+
return CreatedAtAction(nameof(GetTask), new { id = newTaskItem.Id }, newTaskItem);
107+
}
108+
109+
110+
[HttpPut("{id}")]
111+
public async Task<IActionResult> PutTask(int id, TaskUpdateModel model)
112+
{
113+
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
114+
if (string.IsNullOrEmpty(userId)) return Unauthorized();
115+
116+
var existingTask = await _dbContext.TaskItems
117+
.Where(t => t.Id == id && t.UserId == userId)
118+
.FirstOrDefaultAsync();
119+
120+
if (existingTask == null) return NotFound();
121+
122+
if (model.Title != null) { existingTask.Title = model.Title; }
123+
if (model.Description != null) { existingTask.Description = model.Description; }
124+
if (model.Status != null)
125+
{
126+
existingTask.Status = model.Status;
127+
if (model.Status == "Concluída") { existingTask.CompletedAt = DateTime.UtcNow; }
128+
else { existingTask.CompletedAt = null; }
129+
}
130+
if (model.Priority != null) { existingTask.Priority = model.Priority; }
131+
132+
await _dbContext.SaveChangesAsync();
133+
return NoContent();
134+
}
135+
136+
[HttpDelete("{id}")]
137+
public async Task<IActionResult> DeleteTask(int id)
138+
{
139+
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
140+
if (string.IsNullOrEmpty(userId)) return Unauthorized();
141+
142+
var taskItem = await _dbContext.TaskItems
143+
.Where(t => t.Id == id && t.UserId == userId)
144+
.FirstOrDefaultAsync();
145+
146+
if (taskItem == null) return NotFound();
147+
148+
_dbContext.TaskItems.Remove(taskItem);
149+
await _dbContext.SaveChangesAsync();
150+
151+
return NoContent();
152+
}
153+
154+
private bool TaskItemExists(int id)
155+
{
156+
return _dbContext.TaskItems.Any(e => e.Id == id);
157+
}
158+
}
159+
160+
public class SmartTaskModel
161+
{
162+
public string Prompt { get; set; }
163+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using ToDoListProjeto.Api.Models;
3+
4+
namespace ToDoListProjeto.Api.Data
5+
{
6+
public class ApplicationDbContext : DbContext
7+
{
8+
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
9+
{
10+
}
11+
12+
public DbSet<TaskItem> TaskItems { get; set; }
13+
public DbSet<User> Users { get; set; }
14+
15+
protected override void OnModelCreating(ModelBuilder modelBuilder)
16+
{
17+
modelBuilder.Entity<User>()
18+
.HasKey(u => u.Id);
19+
20+
modelBuilder.Entity<TaskItem>()
21+
.HasKey(t => t.Id);
22+
23+
modelBuilder.Entity<TaskItem>()
24+
.HasOne(t => t.User)
25+
.WithMany(u => u.Tasks)
26+
.HasForeignKey(t => t.UserId)
27+
.OnDelete(DeleteBehavior.Cascade);
28+
}
29+
}
30+
}

ToDoListProjeto.Backend/ToDoListProjeto.Api/Migrations/20250511035252_InitialCreate.Designer.cs

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)