Skip to content

Commit

Permalink
add localization
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Valkenburg committed Jun 13, 2024
1 parent 53c5902 commit 07bd6a5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Talpa Api/Controllers/Api/SuggestionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<ActionResult<List<Suggestion>>> GetSuggestions()
}

[HttpPost]
public async Task<ActionResult<List<SimilarityCheck.ObjectWithSimilarity>>> CreateSuggestion(string title, string description, string creatorId, IFormFile? image, bool overrideSimilarity = false)
public async Task<ActionResult<List<SimilarityCheck.ObjectWithSimilarity>>> CreateSuggestion(string title, string description, string creatorId, List<int> tagIds, IFormFile? image, bool overrideSimilarity = false)
{
var user = await context.Users.FindAsync(creatorId);
if (user is null) return NotFound(localizer["UserNotFound"].Value);
Expand All @@ -49,12 +49,18 @@ public async Task<ActionResult<List<Suggestion>>> GetSuggestions()
if (!overrideSimilarity && similarity.objects.Count > 0 && similarity.max > 70)
return Accepted(similarity.objects.OrderByDescending(x => x.Similarity).ToList());

if (tagIds.Any(tag => context.Tags.Find(tag) is null))
return NotFound(localizer["TagNotFound"].Value);

var tags = await context.Tags.Where(tag => tagIds.Contains(tag.Id)).ToListAsync();

context.Suggestions.Add(new Suggestion
{
Title = title,
Description = description,
ImagePath = imagePath,
Creator = user
Creator = user,
Tags = tags
});

await context.SaveChangesAsync();
Expand Down
18 changes: 18 additions & 0 deletions Talpa Api/Localization/LocalizationStrings.Designer.cs

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

6 changes: 6 additions & 0 deletions Talpa Api/Localization/LocalizationStrings.nl-nl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@
<data name="PollHasEnded" xml:space="preserve">
<value>Poll is gesloten.</value>
</data>
<data name="TagNotFound" xml:space="preserve">
<value>Tag niet gevonden.</value>
</data>
<data name="TagAlreadyExists" xml:space="preserve">
<value>Tag bestaat al.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Talpa Api/Localization/LocalizationStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,10 @@
<data name="PollHasEnded" xml:space="preserve">
<value>Poll has ended.</value>
</data>
<data name="TagNotFound" xml:space="preserve">
<value>Tag not found.</value>
</data>
<data name="TagAlreadyExists" xml:space="preserve">
<value>Tag already exists.</value>
</data>
</root>

0 comments on commit 07bd6a5

Please sign in to comment.