diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index 9bc67fb..87cbc23 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -24,6 +24,7 @@ public class ContentController : Controller { private DisplayNamesService displayNamesService; private NeighborhoodService neighborhoodService; private WorldIdService worldIdService; + private BuddyService buddyService; private Random random = new Random(); private readonly IOptions config; @@ -40,6 +41,7 @@ public class ContentController : Controller { DisplayNamesService displayNamesService, NeighborhoodService neighborhoodService, WorldIdService worldIdService, + BuddyService buddyService, IOptions config ) { this.ctx = ctx; @@ -54,6 +56,7 @@ public class ContentController : Controller { this.displayNamesService = displayNamesService; this.neighborhoodService = neighborhoodService; this.worldIdService = worldIdService; + this.buddyService = buddyService; this.config = config; } @@ -1142,12 +1145,40 @@ public class ContentController : Controller { return Ok(taskResult); } + [HttpPost] + [Produces("application/xml")] + [Route("ContentWebService.asmx/AddBuddy")] + [VikingSession] + public IActionResult AddBuddy(Viking viking, [FromForm] Guid buddyUserID) + { + // get buddy + Viking? buddyViking = ctx.Vikings.FirstOrDefault(e => e.Uid == buddyUserID); + + if (buddyViking != null) + return Ok(buddyService.CreateBuddyRelation(viking, buddyViking)); + else return Ok(new BuddyActionResult{ Result = BuddyActionResultType.InvalidFriendCode }); + } + + [HttpPost] + [Produces("application/xml")] + [Route("ContentWebService.asmx/ApproveBuddy")] + [VikingSession] + public IActionResult ApproveBuddy(Viking viking, [FromForm] Guid buddyUserID) + { + // get buddy + Viking? buddyViking = ctx.Vikings.FirstOrDefault(e => e.Uid == buddyUserID); + + if (buddyViking != null) + return Ok(buddyService.UpdateBuddyRelation(viking, buddyViking, BuddyStatus.Approved, BuddyStatus.Approved)); + else return Ok(new BuddyActionResult{ Result = BuddyActionResultType.InvalidFriendCode }); + } + [HttpPost] [Produces("application/xml")] [Route("ContentWebService.asmx/GetBuddyList")] - public IActionResult GetBuddyList() { - // TODO: this is a placeholder - return Ok(new BuddyList { Buddy = new Schema.Buddy[0] }); + [VikingSession] + public IActionResult GetBuddyList(Viking viking) { + return Ok(buddyService.ConstructBuddyList(viking)); } [HttpPost] diff --git a/src/Program.cs b/src/Program.cs index 1bc1dcd..fb2beee 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -42,6 +42,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue("Enabled"); string assetIP = builder.Configuration.GetSection("AssetServer").GetValue("ListenIP"); diff --git a/src/Services/BuddyService.cs b/src/Services/BuddyService.cs index f750be5..861cfb7 100644 --- a/src/Services/BuddyService.cs +++ b/src/Services/BuddyService.cs @@ -59,6 +59,29 @@ public class BuddyService }; } + public BuddyActionResult UpdateBuddyRelation(Viking viking, Viking buddyViking, BuddyStatus buddyStatus1, BuddyStatus buddyStatus2) + { + // find relation + Model.Buddy? buddy = ctx.Buddies.Where(e => e.VikingId == viking.Id) + .FirstOrDefault(e => e.BuddyVikingId == buddyViking.Id); + + if (buddy != null) + { + // update it + buddy.BuddyStatus1 = buddyStatus1; + buddy.BuddyStatus2 = buddyStatus2; + ctx.SaveChanges(); + + // return result + return new BuddyActionResult + { + Status = buddy.BuddyStatus1, + Result = BuddyActionResultType.Success, + BuddyUserID = buddyViking.Uid.ToString() + }; + } else return new BuddyActionResult { Result = BuddyActionResultType.Unknown }; + } + public void RemoveBuddy(Viking viking, Guid buddyUid) { // find buddy viking