You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
API/src/StubAPI/AthleteService.cs

67 lines
2.0 KiB

using Model;
using Shared;
namespace StubAPI;
public class UserService : IUserService
{
private List<User> athletes =
[
new User
{
Id = 1, Username = "Athlete1", ProfilePicture = "default.png", FirstName = "First1", LastName = "Last1",
Sexe = "M", Lenght = 180, Weight = 70, DateOfBirth = new DateTime(1990, 1, 1),
Email = "athlete1@example.com", Role = new Athlete()
},
new User
{
Id = 2, Username = "Athlete2", ProfilePicture = "default.png", FirstName = "First2", LastName = "Last2",
Sexe = "F", Lenght = 170, Weight = 60, DateOfBirth = new DateTime(1992, 2, 2),
Email = "athlete2@example.com", Role = new Coach()
},
new User
{
Id = 3, Username = "Athlete3", ProfilePicture = "default.png", FirstName = "First3", LastName = "Last3",
Sexe = "M", Lenght = 190, Weight = 80, DateOfBirth = new DateTime(1994, 3, 3), Email = "ath@ex.fr",
Role = new Athlete()
}
];
public async Task<IEnumerable<User>> GetUsers(int index, int count, AthleteOrderCriteria criteria,
bool descending = false)
{
throw new NotImplementedException();
}
public async Task<User?> GetUserByIdAsync(int id)
{
return await Task.FromResult(athletes.FirstOrDefault(s => s.Id == id));
}
public async Task<User?> AddUser(User athlete)
{
return await athletes.AddItem(athlete);
}
public async Task<User?> UpdateUser(int id, User user)
{
var oldUser = athletes.FirstOrDefault(s => s.Id == id);
if (oldUser == null) return null;
return await athletes.UpdateItem(oldUser, user);
}
public async Task<bool> DeleteUser(int id)
{
var user = athletes.FirstOrDefault(s => s.Id == id);
if (user == null) return false;
return await athletes.DeleteItem(user);
}
public async Task<int> GetNbItems()
{
return await Task.FromResult(athletes.Count);
}
}