Skip to content

Commit

Permalink
Update Word Model
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthagen committed Oct 23, 2020
1 parent 3e2fb66 commit ca5d5fb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Backend.Tests/Controllers/AudioControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void TestAudioImport()

// Generate parameters for controller call.
var formFile = new FormFile(fstream, 0, fstream.Length, "name", "sound.mp3");
var fileUpload = new FileUpload { Name = "FileName", File = formFile };
var fileUpload = new FileUpload(formFile) { Name = "FileName" };

var word = _wordrepo.Create(RandomWord()).Result;

Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Controllers/AvatarControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void TestAvatarImport()
var fstream = File.OpenRead(filePath);

var formFile = new FormFile(fstream, 0, fstream.Length, "dave", "combine.png");
var fileUpload = new FileUpload { Name = "FileName", File = formFile };
var fileUpload = new FileUpload(formFile) { Name = "FileName" };

_ = _avatarController.UploadAvatar(_jwtAuthenticatedUser.Id, fileUpload).Result;

Expand Down
4 changes: 2 additions & 2 deletions Backend.Tests/Controllers/LiftControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ private static Word RandomWord(string projId)
return word;
}

private static FileUpload InitFile(FileStream fstream, string filename)
private static FileUpload InitFile(Stream fstream, string filename)
{
var formFile = new FormFile(fstream, 0, fstream.Length, "name", filename);
var fileUpload = new FileUpload { Name = "FileName", File = formFile };
var fileUpload = new FileUpload(formFile) { Name = "FileName" };

return fileUpload;
}
Expand Down
73 changes: 50 additions & 23 deletions Backend/Models/Word.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public Word Clone()
{
var clone = new Word
{
Id = Id.Clone() as string,
Id = (Id.Clone() as string)!,
Guid = Guid,
Vernacular = Vernacular.Clone() as string,
Plural = Plural.Clone() as string,
Created = Created.Clone() as string,
Modified = Modified.Clone() as string,
PartOfSpeech = PartOfSpeech.Clone() as string,
OtherField = OtherField.Clone() as string,
ProjectId = ProjectId.Clone() as string,
Vernacular = (Vernacular.Clone() as string)!,
Plural = (Plural.Clone() as string)!,
Created = (Created.Clone() as string)!,
Modified = (Modified.Clone() as string)!,
PartOfSpeech = (PartOfSpeech.Clone() as string)!,
OtherField = (OtherField.Clone() as string)!,
ProjectId = (ProjectId.Clone() as string)!,
Accessibility = Accessibility,
Audio = new List<string>(),
EditedBy = new List<string>(),
Expand All @@ -104,15 +104,15 @@ public Word Clone()

foreach (var file in Audio)
{
clone.Audio.Add(file.Clone() as string);
clone.Audio.Add((file.Clone() as string)!);
}
foreach (var id in EditedBy)
{
clone.EditedBy.Add(id.Clone() as string);
clone.EditedBy.Add((id.Clone() as string)!);
}
foreach (var id in History)
{
clone.History.Add(id.Clone() as string);
clone.History.Add((id.Clone() as string)!);
}
foreach (var sense in Senses)
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public bool ContentEquals(Word other)
other.Note.Equals(Note);
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (!(obj is Word other) || GetType() != obj.GetType())
{
Expand Down Expand Up @@ -206,8 +206,8 @@ public Note Clone()
{
return new Note
{
Language = Language.Clone() as string,
Text = Text.Clone() as string
Language = (Language.Clone() as string)!,
Text = (Text.Clone() as string)!
};
}

Expand All @@ -217,7 +217,7 @@ public bool IsBlank()
return Text == "";
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (!(obj is Note other) || GetType() != obj.GetType())
{
Expand Down Expand Up @@ -280,7 +280,7 @@ public Sense Clone()
return clone;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (!(obj is Sense other) || GetType() != obj.GetType())
{
Expand Down Expand Up @@ -309,16 +309,22 @@ public class Gloss
/// <summary> The gloss string. </summary>
public string Def { get; set; }

public Gloss()
{
Language = "";
Def = "";
}

public Gloss Clone()
{
return new Gloss
{
Language = Language.Clone() as string,
Def = Def.Clone() as string
Language = (Language.Clone() as string)!,
Def = (Def.Clone() as string)!
};
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (!(obj is Gloss other) || GetType() != obj.GetType())
{
Expand All @@ -344,9 +350,9 @@ public SemanticDomain Clone()
{
return new SemanticDomain
{
Name = Name.Clone() as string,
Id = Id.Clone() as string,
Description = Description.Clone() as string
Name = (Name.Clone() as string)!,
Id = (Id.Clone() as string)!,
Description = (Description.Clone() as string)!
};
}

Expand All @@ -357,7 +363,7 @@ public SemanticDomain()
Description = "";
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (!(obj is SemanticDomain other) || GetType() != obj.GetType())
{
Expand All @@ -379,6 +385,13 @@ public class FileUpload
public IFormFile File { get; set; }
public string Name { get; set; }
public string FilePath { get; set; }

public FileUpload(IFormFile file)
{
File = file;
Name = "";
FilePath = "";
}
}

/// <summary>
Expand All @@ -391,13 +404,27 @@ public class MergeWords
public List<MergeSourceWord> ChildrenWords { get; set; }
public string MergedBy { get; set; }
public string Time { get; set; }

public MergeWords()
{
Parent = new Word();
ChildrenWords = new List<MergeSourceWord>();
MergedBy = "";
Time = "";
}
}

/// <summary> Helper object that contains a wordId and the type of merge that should be performed </summary>
public class MergeSourceWord
{
public string SrcWordId;
public List<State> SenseStates;

public MergeSourceWord()
{
SrcWordId = "";
SenseStates = new List<State>();
}
}

/// <summary> Information about the state of the word in that database used for merging </summary>
Expand Down

0 comments on commit ca5d5fb

Please sign in to comment.