Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge trading #231

Open
wants to merge 21 commits into
base: badge-trading
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions TPP.Persistence.MongoDB.Tests/Repos/BadgeRepoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public async Task can_handle_null_shiny_fields()
await bsonBadgeCollection.InsertOneAsync(BsonDocument.Create(new Dictionary<string, object?>
{
["_id"] = ObjectId.Parse(id),
["userid"] = "mogi",
["user"] = "mogi",
["species"] = "1",
["source"] = "manual_creation",
["created_at"] = instant.ToDateTimeUtc(),
Expand All @@ -220,8 +220,10 @@ await bsonBadgeCollection.InsertOneAsync(BsonDocument.Create(new Dictionary<stri
IMongoCollection<Badge> badgeCollection = db.GetCollection<Badge>("badges"); ;

Badge b = await badgeCollection.Find(b => b.Id == id).FirstAsync();

Assert.AreEqual(false, b.Shiny);

List<Badge> badges = await badgeRepo.FindAllByCustom(null, null, null, null, false);
Assert.AreEqual(1, badges.Count);
}

[TestFixture]
Expand Down
8 changes: 5 additions & 3 deletions TPP.Persistence.MongoDB/Repos/BadgeRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<List<Badge>> FindAllByUser(string? userId) =>
public async Task<List<Badge>> FindByUserAndSpecies(string? userId, PkmnSpecies species) =>
await Collection.Find(b => b.UserId == userId && b.Species == species).ToListAsync();

public async Task<List<Badge>> FindAllByCustom(string? userId = null, PkmnSpecies? species = null, int? form = null, Badge.BadgeSource? source = null, bool? shiny = null)
public async Task<List<Badge>> FindAllByCustom(string? userId, PkmnSpecies? species, int? form, Badge.BadgeSource? source, bool? shiny)
{
FilterDefinition<Badge> filter = Builders<Badge>.Filter.Empty;
if (userId != null)
Expand All @@ -103,8 +103,10 @@ public async Task<List<Badge>> FindAllByCustom(string? userId = null, PkmnSpecie
filter &= Builders<Badge>.Filter.Eq(b => b.Form, form);
if (source != null)
filter &= Builders<Badge>.Filter.Eq(b => b.Source, source);
if (shiny != null)
filter &= Builders<Badge>.Filter.Eq(b => b.Shiny, shiny);
if (shiny == true)
filter &= Builders<Badge>.Filter.Eq(b => b.Shiny, true);
else
filter &= Builders<Badge>.Filter.Ne(b => b.Shiny, true);
Mogiiii marked this conversation as resolved.
Show resolved Hide resolved

return await Collection.Find(filter).ToListAsync();
}
Expand Down