File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,26 +56,16 @@ public IActionResult ListAllTasks()
5656
5757 [ HttpGet ( "ListTaskByUser/{userId}" ) ]
5858 public IActionResult ListTarefaByUser (
59- [ FromRoute ] int userId ,
60- [ FromServices ] AppDbContext context )
59+ [ FromRoute ] int userId )
6160 {
62- var tasks = context . Tasks
63- . Where ( x => x . UserId == userId )
64- . Select ( task => new
65- {
66- TaskId = task . Id ,
67- TaskTitle = task . Title ,
68- TaskDescription = task . Description ,
69- Done = task . Done ,
70- CreatedAt = task . CreatedAt ,
71- CategoryName = context . CategorieTasks
72- . Where ( category => category . Id == task . CategorieTaskId )
73- . Select ( category => category . Name )
74- . FirstOrDefault ( )
75- } )
76- . ToList ( ) ;
77-
78- return Ok ( tasks ) ;
61+ try
62+ {
63+ var tasksByUser = taskManagerServices . GetTasksByUser ( userId ) ;
64+ return Ok ( tasksByUser ) ;
65+ } catch ( System . Exception )
66+ {
67+ return BadRequest ( ) ;
68+ }
7969 }
8070
8171 [ HttpGet ( "/GetById/{id:int}" ) ]
Original file line number Diff line number Diff line change @@ -70,5 +70,25 @@ public IActionResult GetAllTasks()
7070 . ToList ( ) ;
7171 return new OkObjectResult ( tasks ) ;
7272 }
73+
74+ public IActionResult GetTasksByUser ( int userId )
75+ {
76+ var tasks = context . Tasks
77+ . Where ( x => x . UserId == userId )
78+ . Select ( task => new
79+ {
80+ TaskId = task . Id ,
81+ TaskTitle = task . Title ,
82+ TaskDescription = task . Description ,
83+ Done = task . Done ,
84+ CreatedAt = task . CreatedAt ,
85+ CategoryName = context . CategorieTasks
86+ . Where ( category => category . Id == task . CategorieTaskId )
87+ . Select ( category => category . Name )
88+ . FirstOrDefault ( )
89+ } )
90+ . ToList ( ) ;
91+ return new OkObjectResult ( tasks ) ;
92+ }
7393 }
7494}
You can’t perform that action at this time.
0 commit comments