Skip to content

Commit

Permalink
Bump d.py version and add auto role assign functionality (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay-Madden authored Oct 31, 2022
1 parent 9001c87 commit 815e57c
Show file tree
Hide file tree
Showing 24 changed files with 1,266 additions and 155 deletions.
5 changes: 4 additions & 1 deletion ClemBot.Api/ClemBot.Api.Core/Features/Guilds/Bot/Roles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Model
public string? Name { get; init; }

public bool IsAssignable { get; init; }

public bool IsAutoAssigned { get; init; }
}

public record QueryHandler(ClemBotContext _context)
Expand All @@ -45,7 +47,8 @@ public async Task<QueryResult<IEnumerable<Model>>> Handle(Query request,
{
Id = role.Id,
Name = role.Name,
IsAssignable = role.IsAssignable ?? false
IsAssignable = role.IsAssignable,
IsAutoAssigned = role.IsAutoAssigned
}));
}
}
Expand Down
9 changes: 6 additions & 3 deletions ClemBot.Api/ClemBot.Api.Core/Features/Roles/Bot/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class Model
public bool Admin { get; init; }

public bool IsAssignable { get; init; }

public bool IsAutoAssigned { get; init; }
}

public record QueryHandler(ClemBotContext _context) : IRequestHandler<Query, QueryResult<Model>>
Expand All @@ -34,19 +36,20 @@ public async Task<QueryResult<Model>> Handle(Query request, CancellationToken ca
{
var role = await _context.Roles
.Where(x => x.Id == request.Id)
.FirstAsync();
.FirstOrDefaultAsync();

if (role is null)
{
return QueryResult<Model>.NotFound();
}

return QueryResult<Model>.Success(new Model()
return QueryResult<Model>.Success(new Model
{
Id = role.Id,
Name = role.Name,
GuildId = role.GuildId,
IsAssignable = role.IsAssignable ?? false,
IsAssignable = role.IsAssignable,
IsAutoAssigned = role.IsAutoAssigned,
Admin = role.Admin
});
}
Expand Down
3 changes: 3 additions & 0 deletions ClemBot.Api/ClemBot.Api.Core/Features/Roles/Bot/Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class Command : IRequest<QueryResult<ulong>>
public bool? Admin { get; set; } = null;

public bool? Assignable { get; set; } = null;

public bool? AutoAssigned { get; set; } = null;
}

public record Handler(ClemBotContext _context) : IRequestHandler<Command, QueryResult<ulong>>
Expand All @@ -44,6 +46,7 @@ public async Task<QueryResult<ulong>> Handle(Command request, CancellationToken
role.Name = request.Name ?? role.Name;
role.Admin = request.Admin ?? role.Admin;
role.IsAssignable = request.Assignable ?? role.IsAssignable;
role.IsAutoAssigned = request.AutoAssigned ?? role.IsAutoAssigned;

await _context.SaveChangesAsync();

Expand Down
9 changes: 9 additions & 0 deletions ClemBot.Api/ClemBot.Api.Core/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ClemBot.Api.Core (No Browser)": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": false,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
4 changes: 0 additions & 4 deletions ClemBot.Api/ClemBot.Api.Data/Contexts/ClemBotContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ static ClemBotContext()

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Role>()
.Property(p => p.IsAssignable)
.HasDefaultValue(true);

modelBuilder.Entity<Guild>()
.HasMany(p => p.Users)
.WithMany(p => p.Guilds)
Expand Down
Loading

0 comments on commit 815e57c

Please sign in to comment.