signing up through the discord bot works now
This commit is contained in:
parent
e445b2a181
commit
69337e69ae
11 changed files with 327 additions and 42 deletions
|
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.DataProtection;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Lieb.Data;
|
||||
using Lieb.Models.GuildWars2.Raid;
|
||||
using Lieb.Models.GuildWars2;
|
||||
using SharedClasses.SharedModels;
|
||||
|
||||
namespace Lieb.Controllers
|
||||
|
@ -13,20 +14,22 @@ namespace Lieb.Controllers
|
|||
public class DiscordBotController : ControllerBase
|
||||
{
|
||||
RaidService _raidService;
|
||||
UserService _userService;
|
||||
|
||||
public DiscordBotController(RaidService raidService)
|
||||
public DiscordBotController(RaidService raidService, UserService userService)
|
||||
{
|
||||
_raidService = raidService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("[action]/{raidId}/{userId}")]
|
||||
public List<ApiRole> GetRoles(int raidId, ulong userId)
|
||||
public ActionResult<List<ApiRole>> GetRoles(int raidId, ulong userId)
|
||||
{
|
||||
Raid raid = _raidService.GetRaid(raidId);
|
||||
if(!_raidService.IsRaidSignUpAllowed(userId, raidId, out string errorMessage))
|
||||
{
|
||||
//TODO: send error message
|
||||
return Problem(errorMessage);
|
||||
}
|
||||
|
||||
List<ApiRole> apiRoles = new List<ApiRole>();
|
||||
|
@ -35,7 +38,8 @@ namespace Lieb.Controllers
|
|||
apiRoles.Add(new ApiRole(){
|
||||
Name = role.Name,
|
||||
Description = role.Description,
|
||||
IsSignUpAllowed = _raidService.IsRoleSignUpAllowed(userId, role.RaidRoleId, SignUpType.SignedUp)
|
||||
IsSignUpAllowed = _raidService.IsRoleSignUpAllowed(userId, role.RaidRoleId, SignUpType.SignedUp),
|
||||
roleId = role.RaidRoleId
|
||||
});
|
||||
}
|
||||
return apiRoles;
|
||||
|
@ -45,7 +49,40 @@ namespace Lieb.Controllers
|
|||
[Route("[action]")]
|
||||
public async Task SignUp(ApiSignUp signUp)
|
||||
{
|
||||
_raidService.SignUp(signUp.raidId, signUp.userId, signUp.gw2AccountId, signUp.roleId, )
|
||||
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
|
||||
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.SignedUp);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("[action]")]
|
||||
public async Task SignUpMaybe(ApiSignUp signUp)
|
||||
{
|
||||
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
|
||||
await _raidService.SignUp(signUp.raidId, signUp.userId, signUp.gw2AccountId, signUp.roleId, SignUpType.Maybe);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("[action]")]
|
||||
public async Task SignUpBackup(ApiSignUp signUp)
|
||||
{
|
||||
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
|
||||
await _raidService.SignUp(signUp.raidId, signUp.userId, signUp.gw2AccountId, signUp.roleId, SignUpType.Backup);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("[action]")]
|
||||
public async Task SignUpFlex(ApiSignUp signUp)
|
||||
{
|
||||
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
|
||||
await _raidService.SignUp(signUp.raidId, signUp.userId, signUp.gw2AccountId, signUp.roleId, SignUpType.Flex);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("[action]")]
|
||||
public async Task SignOff(ApiSignUp signUp)
|
||||
{
|
||||
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
|
||||
await _raidService.SignOff(signUp.raidId, signUp.userId);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ namespace Lieb.Data
|
|||
//new LiebUser{Id=0, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||
new LiebUser{Id=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||
#if DEBUG
|
||||
new LiebUser{Id=1, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
|
||||
new LiebUser{Id=194455125769715713, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
|
||||
new LiebUser{Id=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -171,7 +171,10 @@ namespace Lieb.Data
|
|||
}
|
||||
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
context.Update(raid.DiscordRaidMessages);
|
||||
foreach(DiscordRaidMessage message in raid.DiscordRaidMessages)
|
||||
{
|
||||
context.Update(message);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
@ -192,6 +195,7 @@ namespace Lieb.Data
|
|||
foreach(RaidRole role in raid.Roles)
|
||||
{
|
||||
ApiRaid.Role apiRole = new ApiRaid.Role(){
|
||||
RoleId = role.RaidRoleId,
|
||||
Description = role.Description,
|
||||
Name = role.Name,
|
||||
Spots = role.Spots
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue