création des entités (à finir), des DTOs et du modèle + création des ordersCriterias
continuous-integration/drone/push Build is passing Details

API
Damien NORTIER 1 year ago
parent 8e229a61f7
commit d31875144c

@ -13,10 +13,10 @@ namespace DTOs
/// define a DTO for an administrator
/// properties :
/// Id : identifier in the database
/// Username : username for a player
/// HashedPassword : hashed of the password of the player
/// Username : username for a administrator
/// HashedPassword : hash of the password of the administrator
/// </summary>
public int Id { get; set; }
public int? Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -10,9 +10,9 @@ namespace DTOs
/// properties :
/// Id : identifier in the database
/// Content : content of the answer
/// idQuestion : the id of the question which it answer to
/// IdQuestion : the id of the question which it answer to
/// </summary>
public int Id { get; set; }
public int? Id { get; set; }
public string Content { get; set; } = null!;
public int? IdQuestion { get; set; }
}

@ -15,7 +15,7 @@ namespace DTOs
/// Id : identifier in the database
/// Name : name of the chapter
/// </summary>
public int Id { get; set; }
public int? Id { get; set; }
public string Name { get; set; } = null!;
}
}

@ -18,10 +18,10 @@ namespace DTOs
/// Password : password require to access at the lobby
/// IdCreator : identifier of the creator player
/// </summary>
public int Id { get; set; }
public int? Id { get; set; }
public string Name { get; set; } = null!;
public string Password { get; set; } = null!;
public int NbPlayers { get; set; }
public int IdCreator { get; set; }
public int? IdCreator { get; set; }
}
}

@ -13,10 +13,10 @@ namespace DTOs
/// define a DTO for a player
/// properties :
/// Id : identifier in the database
/// Nickname : nickname for a player
/// Nickname : nickname for the player
/// HashedPassword : hashed of the password of the player
/// </summary>
public int Id { get; set; }
public int? Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -20,11 +20,11 @@ namespace DTOs
/// IdChapter : identifier of the chapter of the question
/// IdAnswerGood : identifier of the right answer to this question
/// </summary>
public int Id { get; set; }
public int? Id { get; set; }
public string Content { get; set; } = null!;
public int Difficuty { get; set; }
public int Difficulty { get; set; }
public int NbFalls { get; set; }
public int IdChapter { get; set; }
public int IdAnswerGood { get; set; }
public int? IdChapter { get; set; }
public int? IdAnswerGood { get; set; }
}
}

@ -5,7 +5,12 @@ namespace DbConnectionLibrairie
{
public class MyDbContext : DbContext
{
public DbSet<AdministratorEntity> Administrators { get; set; }
public DbSet<AnswerEntity> Answers { get; set; }
public DbSet<ChapterEntity> Chapters { get; set; }
public DbSet<LobbyEntity> Lobbies { get; set; }
public DbSet<PlayerEntity> Players { get; set; }
public DbSet<QuestionEntity> Questions { get; set; }
public MyDbContext()
{ }

@ -13,11 +13,11 @@ namespace Entities
/// define an entity for an administrator
/// properties :
/// Id : identifier in the database
/// Username : username for a player
/// HashedPassword : hashed of the password of the player
/// Username : username for a administrator
/// HashedPassword : hash of the password of the administrator
/// </summary>
[Key]
public int Id { get; set; }
public int? Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -10,10 +10,10 @@ namespace Entities
/// properties :
/// Id : identifier in the database
/// Content : content of the answer
/// idQuestion : the id of the question which it answer to
/// IdQuestion : the id of the question which it answer to
/// </summary>
[Key]
public int Id { get; set; }
public int? Id { get; set; }
public string Content { get; set; } = null!;
[ForeignKey(nameof(QuestionEntity))]

@ -16,7 +16,7 @@ namespace Entities
/// Name : name of the chapter
/// </summary>
[Key]
public int Id { get; set; }
public int? Id { get; set; }
public string Name { get; set; } = null!;
}
}

@ -19,12 +19,12 @@ namespace Entities
/// IdCreator : identifier of the creator player
/// </summary>
[Key]
public int Id { get; set; }
public int? Id { get; set; }
public string Name { get; set; } = null!;
public string Password { get; set; } = null!;
public int NbPlayers { get; set; }
[ForeignKey(nameof(PlayerEntity))]
public int IdCreator { get; set; }
public int? IdCreator { get; set; }
}
}

@ -13,11 +13,11 @@ namespace Entities
/// define an entity for a player
/// properties :
/// Id : identifier in the database
/// Nickname : nickname for a player
/// Nickname : nickname for the player
/// HashedPassword : hashed of the password of the player
/// </summary>
[Key]
public int Id { get; set; }
public int? Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -21,15 +21,15 @@ namespace Entities
/// IdAnswerGood : identifier of the right answer to this question
/// </summary>
[Key]
public int Id { get; set; }
public int? Id { get; set; }
public string Content { get; set; } = null!;
public int Difficuty { get; set; }
public int Difficulty { get; set; }
public int NbFalls { get; set; }
[ForeignKey(nameof(ChapterEntity))]
public int IdChapter { get; set; }
public int? IdChapter { get; set; }
[ForeignKey(nameof(AnswerEntity))]
public int IdAnswerGood { get; set; }
public int? IdAnswerGood { get; set; }
}
}

@ -1,83 +0,0 @@
using DbConnectionLibrairie;
using Entities;
using ManagerInterfaces;
using Microsoft.EntityFrameworkCore;
using OrderCriterias;
using System.Collections.ObjectModel;
namespace EntityManagers
{
/// <summary>
/// a manager for answer entity
/// </summary>
public class AnswerEntityManager : IAnswerManager<AnswerEntity>
{
private MyDbContext dbContext;
public int getNbElement()
{
return dbContext.Answers.CountAsync().Result;
}
public AnswerEntityManager(MyDbContext dbContext)
{
this.dbContext = dbContext;
}
public AnswerEntity ajouterAnswer(AnswerEntity answer)
{
var tmp = dbContext.Answers.Where(a => a.Equals(answer)).FirstOrDefaultAsync().Result;
if (tmp != null) return tmp;
dbContext.Answers.Add(answer);
dbContext.SaveChangesAsync();
return dbContext.Answers.Where(a => a.Equals(answer)).FirstAsync().Result;
}
public IEnumerable<AnswerEntity> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById)
{
if ((nb - 1) * count >= getNbElement()) throw new Exception("too many page skiped");
if (orderCriteria == AnswerOrderCriteria.ById)
{
return dbContext.Answers.OrderBy(a => a.Id).Skip((nb - 1) * count).Take(count).ToListAsync().Result;
}
else
{
return dbContext.Answers.OrderBy(a => a.Content).Skip((nb - 1) * count).Take(count).ToListAsync().Result;
}
}
private AnswerEntity? getAnswer(long id)
{
return dbContext.Answers.Where(a => a.Id == id).FirstOrDefaultAsync().Result;
}
public AnswerEntity? modifierAnswer(long id, AnswerEntity answer)
{
var tmp = getAnswer(id);
if (tmp == null) return null;
tmp.Content = answer.Content;
dbContext.SaveChangesAsync();
return tmp;
}
public AnswerEntity? supprimerAnswer(long id)
{
var tmp = getAnswer(id);
if (tmp == null) return null;
dbContext.Answers.Remove(tmp);
dbContext.SaveChangesAsync();
return tmp;
}
public void supprimerAnswer(AnswerEntity answer)
{
dbContext.Answers.Remove(answer);
dbContext.SaveChangesAsync();
}
public ReadOnlyCollection<AnswerEntity>? getAnswersByIdQuestion(long id)
{
throw new NotImplementedException();
}
}
}

@ -62,7 +62,11 @@ namespace ExtensionsClassLibrairie
/// <returns>the dto answer that correspond</returns>
public static AnswerDto ToDto(this Answer a)
{
return new AnswerDto(a.Content, a.Id);
return new AnswerDto
{
Content = a.Content,
Id = a.Id
};
}
/// <summary>
@ -72,7 +76,11 @@ namespace ExtensionsClassLibrairie
/// <returns>the dto answer that correspond</returns>
public static AnswerDto ToDto(this AnswerEntity a)
{
return new AnswerDto(a.Content, a.Id);
return new AnswerDto
{
Content = a.Content,
Id = a.Id
};
}
/// <summary>

@ -25,7 +25,7 @@ namespace ManagerInterfaces
/// this page (or null if (nb-1)*count
/// is outside boundaries (0, getNbElement()-1)
/// </returns>
public Task<(int nbAnswer, IEnumerable<T>? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById);
public Task<(int nbAnswers, ReadOnlyCollection<T>? answers)> getAnswers(int nb, int count, AnswerOrderCriteria orderCriteria = AnswerOrderCriteria.ById);
/// <summary>
/// get a T element with an id
/// </summary>
@ -67,5 +67,14 @@ namespace ManagerInterfaces
/// to the id or null if there isn't any
/// </returns>
public Task<T> ajouterAnswer(T answer);
/// <summary>
/// get a T element with an id
/// </summary>
/// <param name="id">the id of the T element</param>
/// <returns>
/// the T element that corresponde
/// to the id or null if there isn't any
/// </returns>
public Task<T?> getAnswer(long id);
}
}

@ -5,27 +5,27 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace model
namespace Model
{
public class Administrator
{
/// <summary>
/// define a DTO for an administrator
/// define an administrator
/// attributes :
/// id : identifier in the database
/// username : username for a player
/// hashedPassword : hashed of the password of the player
/// username : username for a administrator
/// hashedPassword : hash of the password of the administrator
/// </summary>
private int id;
private string? username;
private string hashedPassword;
private string? hashedPassword;
/// <summary>
/// getters and setters for attributes
/// </summary>
public int Id
{
get => id;
private set { id = value < 0 ? 0 : value; }
private set { id = value < -1 ? -1 : value; }
}
public string Username
{
@ -34,11 +34,17 @@ namespace model
}
public string HashedPassword
{
get => hashedPassword;
set { hashedPassword = value; }
get => hashedPassword == null ? "" : hashedPassword;
set { hashedPassword = value == "" ? null : value; }
}
public Administrator(string username, string hashedPassword, int id)
/// <summary>
/// constructor of an administrator
/// </summary>
/// <param name="username">the username of the administrator</param>
/// <param name="hashedPassword">the hash of the password of the administrator</param>
/// <param name="id">the id in the database</param>
public Administrator(string username, string hashedPassword, int id = -1)
{
this.Username = username;
this.HashedPassword = hashedPassword;

@ -1,19 +1,51 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace model
namespace Model
{
public class Answer
{
/// <summary>
/// define a DTO for an answer for a Question with Mutiple Choice
/// properties :
/// Id : identifier in the database
/// Content : content of the answer
/// define an answer for a Question with Mutiple Choice
/// attributes :
/// id : identifier in the database
/// content : content of the answer
/// idQuestion : the id of the question which it answer to
/// </summary>
public int Id { get; set; }
public string Content { get; set; } = null!;
public int? IdQuestion { get; set; }
private int id;
private string? content;
private int idQuestion;
/// <summary>
/// getters and setters for attributes
/// </summary>
public int? Id
{
get => id == -1 ? null : id; // null = no id
private set { id = value < -1 || value == null ? -1 : value.Value; }
}
public string Content
{
get => content == null ? "" : content;
set { content = value == "" ? null : value; }
}
public int? IdQuestion
{
get => idQuestion == -1 ? null : idQuestion; // null = no idQuestion
private set { idQuestion = value < -1 || value == null ? -1 : value.Value; }
}
/// <summary>
/// constructor of an answer
/// </summary>
/// <param name="content">the content of the answer</param>
/// <param name="id">the id in the database</param>
/// <param name="idQuestion">the id of the question which it answer to</param>
public Answer(string content, int? idQuestion = null, int? id = null)
{
Content = content;
Id = id;
IdQuestion = idQuestion;
}
}
}

@ -5,17 +5,41 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace model
namespace Model
{
public class Chapter
{
/// <summary>
/// define a mathematical chapter or thematic
/// properties :
/// Id : identifier in the database
/// Name : name of the chapter
/// attributes :
/// id : identifier in the database
/// name : name of the chapter
/// </summary>
public int Id { get; set; }
public string Name { get; set; } = null!;
int id;
string? name;
/// <summary>
/// getters and setters for attributs
/// </summary>
public int? Id
{
get => id == -1 ? null : id ;
private set { id = value == null || value < -1 ? -1 : value.Value; }
}
public string Name
{
get => name == null ? "" : name;
set { name = value == "" ? null : value; }
}
/// <summary>
/// custructor of a mathematical chapter
/// </summary>
/// <param name="name">name of the chapter</param>
/// <param name="id">id in the database</param>
public Chapter(string name, int? id = null)
{
Name = name;
Id = id;
}
}
}
}

@ -6,22 +6,67 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace model
namespace Model
{
public class Lobby
{
/// <summary>
/// define a lobby for QMC rapidity fight
/// properties :
/// Id : identifier of the lobby in the database
/// Name : name of the lobby
/// Password : password require to access at the lobby
/// attributes :
/// id : identifier of the lobby in the database
/// name : name of the lobby
/// password : password require to access at the lobby
/// idCreator : identifier of the creator player
/// </summary>
public int Id { get; set; }
public string Name { get; set; } = null!;
public string Password { get; set; } = null!;
public int NbPlayers { get; set; }
public int idCreator { get; set; }
private int id;
private string? name;
private string? password;
private int nbPlayers;
private int idCreator;
/// <summary>
/// getters and setters of attributes
/// </summary>
public int? Id
{
get => id == -1 ? null : id;
private set { id = value == null || value < -1 ? -1 : value.Value; }
}
public string Name
{
get => name == null ? "" : name;
private set { name = value == "" ? null : value; }
}
public string Password
{
get => password == null ? "" : password;
private set { password = value == "" ? null : value; }
}
public int NbPlayers
{
get => nbPlayers;
set { nbPlayers = value < 0 ? 0 : value; }
}
public int? IdCreator
{
get => idCreator == -1 ? null : id;
private set { idCreator = value == null || value < -1 ? -1 : value.Value; }
}
/// <summary>
/// constructor of a lobby
/// </summary>
/// <param name="name">the name of the lobby</param>
/// <param name="idCreator">the id of the creator</param>
/// <param name="password">the password require to access to the lobby</param>
/// <param name="nbPlayer">the number of players in the lobby</param>
/// <param name="id">the id of the lobby</param>
public Lobby(string name, int idCreator, string password = "", int nbPlayer = 0, int? id = null)
{
Name = name;
IdCreator = idCreator;
Password = password;
NbPlayers = nbPlayer;
Id = id;
}
}
}

@ -5,19 +5,51 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace model
namespace Model
{
public class Player
{
/// <summary>
/// define a DTO for a player
/// properties :
/// Id : identifier in the database
/// Nickname : nickname for a player
/// HashedPassword : hashed of the password of the player
/// define a player
/// attributes :
/// id : identifier in the database
/// nickname : nickname for the player
/// hashedPassword : hashed of the password of the player
/// </summary>
public int Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
private int id;
private string? nickname;
private string? hashedPassword;
/// <summary>
/// getters and setters for attributes
/// </summary>
public int? Id
{
get => id == -1 ? null : id;
private set { id = value == null || value < -1 ? -1 : value.Value; }
}
public string Nickname
{
get => nickname == null ? "" : nickname;
private set { nickname = value == "" ? null : nickname; }
}
public string HashedPassword
{
get => hashedPassword == null ? "" : hashedPassword;
set { hashedPassword = value == "" ? null : value; }
}
/// <summary>
/// constructor of a player
/// </summary>
/// <param name="nickname">nickname of the player</param>
/// <param name="hashedPassword">hash of the password of the player</param>
/// <param name="id">id of the player</param>
public Player(string nickname, string hashedPassword = "", int? id = null)
{
Nickname = nickname;
HashedPassword = hashedPassword;
Id = id;
}
}
}

@ -6,25 +6,66 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace model
namespace Model
{
public class Question
{
/// <summary>
/// represent a mathematical question
/// properties :
/// Id : identifier of the question in the database
/// Content : the content of the question
/// Difficulty : difficulty (between 1 and 3 included) of the question
/// NbFails : number of time that people fail on this question
/// IdChapter : identifier of the chapter of the question
/// IdAnswerGood : identifier of the right answer to this question
/// attributes :
/// id : identifier of the question in the database
/// content : the content of the question
/// difficulty : difficulty (between 1 and 3 included) of the question
/// nbFails : number of time that people fail on this question
/// idChapter : identifier of the chapter of the question
/// idAnswerGood : identifier of the right answer to this question
/// </summary>
public int Id { get; set; }
public string Content { get; set; } = null!;
public int Difficuty { get; set; }
public int NbFalls { get; set; }
public int IdChapter { get; set; }
public int IdAnswerGood { get; set; }
private int id;
private string? content;
private int difficulty;
private int nbFalls;
private int idChapter;
private int idAnswerGood;
public int? Id
{
get => id == -1 ? null : id;
private set { id = value == null || value < -1 ? -1 : value.Value; }
}
public string Content
{
get => content == null ? "" : content;
set { content = value == "" ? null : value;}
}
public int Difficulty
{
get => difficulty;
set { difficulty = value < 0 ? 0 : value; }
}
public int NbFalls
{
get => nbFalls;
set { nbFalls = value < 0 ? 0 : value; }
}
public int? IdChapter
{
get => idChapter == -1 ? null : idChapter;
private set { idChapter = value == null || value < -1 ? -1 : value.Value; }
}
public int? IdAnswerGood
{
get => idAnswerGood == -1 ? null : idAnswerGood;
set { idAnswerGood = value == null || value < -1 ? -1 : value.Value; }
}
public Question(string content, int idChapter = -1, int id = -1, int idAnswerGood = -1)
{
Id = id;
Content = content;
Difficulty = 1;
NbFalls = 0;
IdChapter = idChapter;
IdAnswerGood = idAnswerGood;
}
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrderCriterias
{
public enum AdministratorOrderCriteria
{
ById = 0,
ByUserName = 1,
}
}

@ -12,6 +12,7 @@ namespace OrderCriterias
public enum AnswerOrderCriteria
{
ById = 0,
ByContent = 1
ByContent = 1,
ByIdQuestion = 2,
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrderCriterias
{
public enum ChapterOrderCriteria
{
ById = 0,
ByName = 1,
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrderCriterias
{
public enum LobbyOrderCriteria
{
ById = 0,
ByName = 1,
ByNbJoueur = 2,
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrderCriterias
{
public enum PlayerOrderCriteria
{
ById = 0,
ByNickname = 1,
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrderCriterias
{
public enum QuestionOrderCriteria
{
ById = 0,
ByContent = 1,
ByDifficulty = 2,
ByNbFalls = 3,
ByIdChapter = 4,
}
}

@ -7,6 +7,7 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>

Loading…
Cancel
Save