Fix code smell
continuous-integration/drone/push Build is failing Details

refonte_program
Matheo THIERRY 2 years ago
parent cff31cec4f
commit 8fcb08ed63

@ -15,7 +15,5 @@ namespace Biblioteque_de_Class
public void SaveUserData(User user); public void SaveUserData(User user);
public List<User> LoadUserData(); public List<User> LoadUserData();
//public List<Note> LoadNote();
} }
} }

@ -1,262 +1,262 @@
using Microsoft.VisualBasic.FileIO; using Microsoft.VisualBasic.FileIO;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Biblioteque_de_Class namespace Biblioteque_de_Class
{ {
[DataContract] [DataContract]
public class User public class User
{ {
[DataMember] [DataMember]
private string Username { get; set; } private string Username { get; set; }
[DataMember] [DataMember]
private string Email { get; set; } private string Email { get; set; }
[DataMember] [DataMember]
private string Password { get; set; } private string Password { get; set; }
[DataMember] [DataMember]
private List<Note> NoteList; private List<Note> NoteList;
[DataMember] [DataMember]
private List<Tags> TagList; private List<Tags> TagList;
[DataMember] [DataMember]
private List<Note> FavList; private List<Note> FavList;
[DataMember] [DataMember]
private bool IsConnected { get; set; } private bool IsConnected { get; set; }
[DataMember] [DataMember]
private Dictionary<Note, List<Tags>> NoteTagged; private Dictionary<Note, List<Tags>> NoteTagged;
public User(string username, string email, string password) public User(string username, string email, string password)
{ {
Username = username; Username = username;
Email = email; Email = email;
Password = password; Password = password;
NoteList = new List<Note>(); NoteList = new List<Note>();
TagList = new List<Tags>(); TagList = new List<Tags>();
FavList = new List<Note>(); FavList = new List<Note>();
NoteTagged = new Dictionary<Note, List<Tags>>(); NoteTagged = new Dictionary<Note, List<Tags>>();
} }
public string GetUsername() { return Username; } public string GetUsername() { return Username; }
public string GetEmail() { return Email; } public string GetEmail() { return Email; }
public string GetPassword() { return Password; } public string GetPassword() { return Password; }
public List<Note> GetNoteList() { return NoteList; } public List<Note> GetNoteList() { return NoteList; }
public List<Tags> GetTagList() { return TagList; } public List<Tags> GetTagList() { return TagList; }
public List<Note> GetFavList() { return FavList; } public List<Note> GetFavList() { return FavList; }
public bool GetIsConnected() { return IsConnected; } public bool GetIsConnected() { return IsConnected; }
public Dictionary<Note, List<Tags>> GetNoteTagged() { return NoteTagged; } public Dictionary<Note, List<Tags>> GetNoteTagged() { return NoteTagged; }
public void SetUsername(string username) { Username = username; } public void SetUsername(string username) { Username = username; }
public void SetEmail(string email) { Email = email; } public void SetEmail(string email) { Email = email; }
public void SetPassword(string password) { Password = password; } public void SetPassword(string password) { Password = password; }
public void SetIsConnected(bool isConnected) { IsConnected = isConnected; } public void SetIsConnected(bool isConnected) { IsConnected = isConnected; }
public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}"; public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}";
/// <summary> /// <summary>
/// rechercher une note dans la liste de note de l'utilisateur /// rechercher une note dans la liste de note de l'utilisateur
/// </summary> /// </summary>
public List<Note> SearchNoteByName(string name) public List<Note> SearchNoteByName(List<Note> ToResearchIntoList, string name)
{ {
List<Note> searchedNotes = new List<Note>(); List<Note> searchedNotes = new List<Note>();
string search = name.ToLower(); string search = name.ToLower();
foreach (Note note in NoteList) foreach (Note note in ToResearchIntoList)
{ {
if (note.GetName().ToLower().Contains(search)) if (note.GetName().ToLower().Contains(search))
{ {
searchedNotes.Add(note); searchedNotes.Add(note);
}
}
return searchedNotes;
}
/// <summary>
/// rechercher une note dans la liste de note favoris de l'utilisateur
/// </summary>
public List<Note> SearchFavoriteNoteByName(string name)
{
List<Note> searchedNotes = new List<Note>();
string search = name.ToLower();
foreach (Note note in FavList)
{
if (note.GetName().ToLower().Contains(search))
{
searchedNotes.Add(note);
}
}
return searchedNotes;
}
/// <summary>
/// rechercher un tag dans la liste de tag de l'utilisateur
/// </summary>
public List<Tags> SearchTagByName(string name)
{
List<Tags> searchedTags = new List<Tags>();
string search = name.ToLower();
foreach (Tags tag in TagList)
{
if (tag.GetName().ToLower().Contains(search))
{
searchedTags.Add(tag);
}
}
return searchedTags;
}
public List<Note> SearchNoteByDate(List<Note> ToResearchIntoList, string name, DateOnly FirstDate, DateOnly SecondeDate)
{
List<Note> searchedNotes = new List<Note>();
string search = name.ToLower();
foreach (Note note in ToResearchIntoList)
{
if (note.GetName().ToLower().Contains(search) && note.GetCreationDate() >= FirstDate && note.GetCreationDate() <= SecondeDate)
{
searchedNotes.Add(note);
}
}
return searchedNotes;
}
/// <summary>
/// ajouter une note dans la liste de note favorite de l'utilisateur
/// </summary>
public void AddFavorite(Note note)
{
if (FavList.Contains(note))
{
throw new AlreadyExistException("Note already in favorites");
}
FavList.Add(note);
}
/// <summary>
/// supprimer une note dans la liste de note favorite de l'utilisateur
/// </summary>
public void RemoveFavorite(Note note)
{
if (FavList.Contains(note))
{
FavList.Remove(note);
}
else
{
throw new NotFoundException("Note not found");
}
}
/// <summary>
///creer une note
/// </summary>
public void CreateNote(string name, string imagePath)
{
foreach (Note existingNote in NoteList)
{
if (existingNote.GetName() == name)
{
throw new AlreadyExistException("Note already exists");
}
}
Note note = new Note(name, imagePath, this);
NoteList.Add(note);
NoteTagged.Add(note, new List<Tags>());
}
/// <summary>
/// supprimer une note
/// </summary>
public void DeleteNote(string name)
{
foreach (Note note in NoteList)
{
if (note.GetName() == name)
{
NoteList.Remove(note);
NoteTagged.Remove(note);
}
else
{
throw new NotFoundException("Note not found");
} }
} }
} return searchedNotes;
}
/// <summary>
/// creer un tag /// <summary>
/// </summary> /// rechercher une note dans la liste de note favoris de l'utilisateur
public void CreateTag(string name, string color) /// </summary>
{ public List<Note> SearchFavoriteNoteByName(List<Note> ToResearchIntoList, string name)
foreach (Tags tag in TagList) {
{ List<Note> searchedNotes = new List<Note>();
if (tag.GetName() == name) string search = name.ToLower();
{ foreach (Note note in ToResearchIntoList)
throw new AlreadyExistException("Tag already exists"); {
} if (note.GetName().ToLower().Contains(search))
} {
TagList.Add(new Tags(name, color)); searchedNotes.Add(note);
} }
}
/// <summary> return searchedNotes;
/// supprimer un tag }
/// </summary>
public void DeleteTag(string name) /// <summary>
{ /// rechercher un tag dans la liste de tag de l'utilisateur
foreach (Tags tag in TagList) /// </summary>
{ public List<Tags> SearchTagByName(List<Tags> ToResearchIntoList, string name)
if (tag.GetName() == name) {
{ List<Tags> searchedTags = new List<Tags>();
TagList.Remove(tag); string search = name.ToLower();
return; foreach (Tags tag in ToResearchIntoList)
} {
} if (tag.GetName().ToLower().Contains(search))
} {
searchedTags.Add(tag);
/// <summary> }
/// ajouter un tag a une note }
/// </summary> return searchedTags;
public void AddTagToNoteList(Note note, Tags tagToAdd) }
{
if (!TagList.Contains(tagToAdd)) public List<Note> SearchNoteByDate(List<Note> ToResearchIntoList, string name, DateOnly FirstDate, DateOnly SecondeDate)
{ {
throw new NotFoundException("Tag not found"); List<Note> searchedNotes = new List<Note>();
} string search = name.ToLower();
if (!NoteList.Contains(note)) foreach (Note note in ToResearchIntoList)
{ {
throw new NotFoundException("Note not found"); if (note.GetName().ToLower().Contains(search) && note.GetCreationDate() >= FirstDate && note.GetCreationDate() <= SecondeDate || note.GetModificationDate() >= FirstDate && note.GetModificationDate() <= SecondeDate)
} {
NoteTagged[note].Add(tagToAdd); searchedNotes.Add(note);
} }
}
/// <summary> return searchedNotes;
/// supprimer un tag a une note }
/// </summary>
public void RemoveTagFromNoteList(Note note, Tags tagToRemove) /// <summary>
{ /// ajouter une note dans la liste de note favorite de l'utilisateur
if (!TagList.Contains(tagToRemove)) /// </summary>
{ public void AddFavorite(Note note)
throw new NotFoundException("Tag not found"); {
} if (FavList.Contains(note))
if (!NoteList.Contains(note)) {
{ throw new AlreadyExistException("Note already in favorites");
throw new NotFoundException("Note not found"); }
} FavList.Add(note);
NoteTagged[note].Remove(tagToRemove); }
}
/// <summary>
/// <summary> /// supprimer une note dans la liste de note favorite de l'utilisateur
/// ajouter plusieur tag a une note /// </summary>
/// </summary> public void RemoveFavorite(Note note)
public void AddTagsToNoteList(Note note, List<Tags> tags) {
{ if (FavList.Contains(note))
NoteTagged.Add(note, tags); {
} FavList.Remove(note);
}
/// <summary> else
///supprimer tout les tags d'une note {
/// </summary> throw new NotFoundException("Note not found");
public void RemoveTagsFromNoteList(Note note) }
{ }
NoteTagged.Remove(note);
} /// <summary>
///creer une note
} /// </summary>
public void CreateNote(string name, string imagePath)
{
foreach (Note existingNote in NoteList)
{
if (existingNote.GetName() == name)
{
throw new AlreadyExistException("Note already exists");
}
}
Note note = new Note(name, imagePath, this);
NoteList.Add(note);
NoteTagged.Add(note, new List<Tags>());
}
/// <summary>
/// supprimer une note
/// </summary>
public void DeleteNote(string note)
{
foreach (Note existingNote in NoteList)
{
if (existingNote.GetName() == note)
{
NoteList.Remove(existingNote);
NoteTagged.Remove(existingNote);
return;
}else
{
throw new NotFoundException("Note not found");
}
}
}
/// <summary>
/// creer un tag
/// </summary>
public void CreateTag(string name, string color)
{
foreach (Tags tag in TagList)
{
if (tag.GetName() == name)
{
throw new AlreadyExistException("Tag already exists");
}
}
TagList.Add(new Tags(name, color));
}
/// <summary>
/// supprimer un tag
/// </summary>
public void DeleteTag(string name)
{
foreach (Tags tag in TagList)
{
if (tag.GetName() == name)
{
TagList.Remove(tag);
return;
}
}
}
/// <summary>
/// ajouter un tag a une note
/// </summary>
public void AddTagToNoteList(Note note, Tags tagToAdd)
{
if (!TagList.Contains(tagToAdd))
{
throw new NotFoundException("Tag not found");
}
if (!NoteList.Contains(note))
{
throw new NotFoundException("Note not found");
}
NoteTagged[note].Add(tagToAdd);
}
/// <summary>
/// supprimer un tag a une note
/// </summary>
public void RemoveTagFromNoteList(Note note, Tags tagToRemove)
{
if (!TagList.Contains(tagToRemove))
{
throw new NotFoundException("Tag not found");
}
if (!NoteList.Contains(note))
{
throw new NotFoundException("Note not found");
}
NoteTagged[note].Remove(tagToRemove);
}
/// <summary>
/// ajouter plusieur tag a une note
/// </summary>
public void AddTagsToNoteList(Note note, List<Tags> tags)
{
NoteTagged.Add(note, tags);
}
/// <summary>
///supprimer tout les tags d'une note
/// </summary>
public void RemoveTagsFromNoteList(Note note)
{
NoteTagged.Remove(note);
}
}
} }

@ -66,7 +66,7 @@ switch (Console.ReadLine())
} }
//connection //connection
while (connection == true) while (connection)
{ {
connection = false; connection = false;
Console.WriteLine("\nEntrez un nom : "); Console.WriteLine("\nEntrez un nom : ");
@ -84,7 +84,7 @@ while (connection == true)
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
connection = true; connection = true;
} }
if (connection == false) if (!connection)
{ {
if (Database.ComparePassword(u, password)) if (Database.ComparePassword(u, password))
{ {
@ -98,11 +98,11 @@ while (connection == true)
u = uvide; u = uvide;
} }
} }
while (continuerboucle == true) { connection = continuer(); } while (continuerboucle) { connection = continuer(); }
} }
//inscription //inscription
while (inscription == true) while (inscription)
{ {
Console.WriteLine("\nEntrez un nom :"); Console.WriteLine("\nEntrez un nom :");
string? nom = Console.ReadLine(); string? nom = Console.ReadLine();
@ -122,12 +122,12 @@ while (inscription == true)
break; break;
} }
Console.WriteLine("\nNom d'utilisateur déjà utilisé. \n"); Console.WriteLine("\nNom d'utilisateur déjà utilisé. \n");
while (continuerboucle == true) { inscription = continuer(); } while (continuerboucle) { inscription = continuer(); }
} }
//une fois connecté ou inscription fait //une fois connecté ou inscription fait
while (u.GetIsConnected() == true) while (u.GetIsConnected())
{ {
Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("\n|--------------------------------------|");
Console.WriteLine("| |"); Console.WriteLine("| |");
@ -156,13 +156,13 @@ while (u.GetIsConnected() == true)
case "2": case "2":
Console.WriteLine("\nChoisissez le nom de la note (entrer - nom par defaut)"); Console.WriteLine("\nChoisissez le nom de la note (entrer - nom par defaut)");
string? wantedNameNote = Console.ReadLine(); string? wantedNameNote = Console.ReadLine();
if(wantedNameNote == null) { wantedNameNote = ""; } wantedNameNote??= "";
u.CreateNote(wantedNameNote, ""); u.CreateNote(wantedNameNote, "");
break; break;
case "3": case "3":
Console.WriteLine("\nChoisissez le nom de la note"); Console.WriteLine("\nChoisissez le nom de la note");
string? wantedDeleteNote = Console.ReadLine(); string? wantedDeleteNote = Console.ReadLine();
if (wantedDeleteNote == null) { wantedDeleteNote= ""; } wantedDeleteNote??= "";
try try
{ {
u.DeleteNote(wantedDeleteNote); u.DeleteNote(wantedDeleteNote);
@ -184,7 +184,7 @@ while (u.GetIsConnected() == true)
break; break;
} }
while (tags == true) while (tags)
{ {
Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("\n|--------------------------------------|");
Console.WriteLine("| |"); Console.WriteLine("| |");
@ -201,7 +201,7 @@ while (u.GetIsConnected() == true)
tags =false; tags =false;
} }
while(para == true) while(para)
{ {
Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("\n|--------------------------------------|");
Console.WriteLine("| |"); Console.WriteLine("| |");
@ -218,7 +218,7 @@ while (u.GetIsConnected() == true)
para = false; para = false;
} }
while (theme == true) while (theme)
{ {
Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("\n|--------------------------------------|");
Console.WriteLine("| |"); Console.WriteLine("| |");

@ -19,9 +19,7 @@ namespace Notus_UnitTest_Database
[Test] [Test]
public void GetLogoLink_LogoExists_ReturnsLogoLink() public void GetLogoLink_LogoExists_ReturnsLogoLink()
{ {
string logoName = "Logo2"; Assert.That(database.GetLogoLink("Logo2"), Is.EqualTo("link2"));
string logoLink = database.GetLogoLink(logoName);
Assert.That(logoLink, Is.EqualTo("link2"));
} }
[Test] [Test]

Loading…
Cancel
Save