Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .idea/.idea.olympo-webapi/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.olympo-webapi/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.olympo-webapi/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 0 additions & 124 deletions Controllers/AuthController.cs

This file was deleted.

41 changes: 28 additions & 13 deletions Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using olympo_webapi.Models;
using olympo_webapi.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;

namespace olympo_webapi.Controllers
{
Expand Down Expand Up @@ -48,22 +49,35 @@ public async Task<ActionResult<User>> GetById(int id)
return Ok(user);
}

[HttpGet("{userId}/exercises")]
public async Task<ActionResult<IEnumerable<Exercise>>> GetExercisesByUserId(int userId)
{
var user = await _userRepository.GetByIdAsync(userId);
if (user == null)
{
return NotFound($"User with ID {userId} not found.");
}
[HttpGet("{userId}/exercises")]
public async Task<ActionResult<IEnumerable<Exercise>>> GetExercisesByUserId(int userId)
{
var user = await _userRepository.GetByIdAsync(userId);
if (user == null)
{
return NotFound($"User with ID {userId} not found.");
}

var exercises = await _exerciseRepository.GetAsync();
var userExercises = exercises.Where(e => e.UserId == userId).ToList();
var exercises = await _exerciseRepository
.GetAsync(e => e.UserId == userId);

if (!exercises.Any())
{
return NotFound($"No exercises found for user with ID {userId}.");
}

foreach (var exercise in exercises)
{
await _context.Entry(exercise)
.Collection(e => e.Sessions)
.LoadAsync();
}

return Ok(exercises);
}

return Ok(userExercises);
}

[HttpGet("type")]
[HttpGet("type")]
public async Task<ActionResult<IEnumerable<User>>> GetUserType(int type)
{
var users = await _userRepository.GetAsync();
Expand Down Expand Up @@ -113,6 +127,7 @@ public async Task<IActionResult> Post([FromBody] User input)
{
CPF = input.CPF,
Name = input.Name,
Type = input.Type,
Email = input.Email,
ImagePath = imagePath,
Password = HashService.HashPassword(input.Password),
Expand Down
29 changes: 0 additions & 29 deletions Middlewares/AuthorizationMiddleware.cs

This file was deleted.

8 changes: 4 additions & 4 deletions Models/Exercise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class Exercise
public string? Description { get; set; }
public string? ImagePath { get; set; }
public string? VideoPath { get; set; }
public int? Day { get; set; }
public int UserId { get; set; }

[JsonIgnore]
[ForeignKey("UserId")]
public User? User { get; set; }

public List<Session>? Sessions { get; set; } = new List<Session>();
public List<ExerciseDay>? ExerciseDays { get; set; } = new List<ExerciseDay>();

[ForeignKey("UserId")]
public User? User { get; set; }

[NotMapped]
public IFormFile? Image { get; set; }
Expand Down
17 changes: 17 additions & 0 deletions Models/ExerciseDay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace olympo_webapi.Models
{
public class ExerciseDay
{
[Key]
public int Id { get; set; }

public int ExerciseId { get; set; }
public int DayOfWeek { get; set; }

[ForeignKey("ExerciseId")]
public Exercise? Exercise { get; set; }
}
}
4 changes: 3 additions & 1 deletion Models/IExerciseRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace olympo_webapi.Models

namespace olympo_webapi.Models
{
public interface IExerciseRepository
{
Expand All @@ -8,5 +9,6 @@ public interface IExerciseRepository
Task UpdateAsync(Exercise exercise);
Task DeleteAsync(int id);
Task<bool> ExistsAsync(int id);
Task<IEnumerable<object>> GetAsync(Func<object, bool> value);
}
}
2 changes: 1 addition & 1 deletion Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class User
public UserType Type { get; set; }
public string? ImagePath { get; set; }
public string? Password { get; set; }
public List<Exercise>? Exercise { get; set; } = new List<Exercise>();
public List<Exercise>? Exercises { get; set; } = new List<Exercise>();

[NotMapped]
public IFormFile? Image { get; set; }
Expand Down
Loading