implement `AddBuddy and ApproveBuddy`

This commit is contained in:
Alan Moon 2025-03-03 13:39:56 -08:00
parent 6ede8af204
commit 684e8691d8
3 changed files with 58 additions and 3 deletions

View File

@ -24,6 +24,7 @@ public class ContentController : Controller {
private DisplayNamesService displayNamesService; private DisplayNamesService displayNamesService;
private NeighborhoodService neighborhoodService; private NeighborhoodService neighborhoodService;
private WorldIdService worldIdService; private WorldIdService worldIdService;
private BuddyService buddyService;
private Random random = new Random(); private Random random = new Random();
private readonly IOptions<ApiServerConfig> config; private readonly IOptions<ApiServerConfig> config;
@ -40,6 +41,7 @@ public class ContentController : Controller {
DisplayNamesService displayNamesService, DisplayNamesService displayNamesService,
NeighborhoodService neighborhoodService, NeighborhoodService neighborhoodService,
WorldIdService worldIdService, WorldIdService worldIdService,
BuddyService buddyService,
IOptions<ApiServerConfig> config IOptions<ApiServerConfig> config
) { ) {
this.ctx = ctx; this.ctx = ctx;
@ -54,6 +56,7 @@ public class ContentController : Controller {
this.displayNamesService = displayNamesService; this.displayNamesService = displayNamesService;
this.neighborhoodService = neighborhoodService; this.neighborhoodService = neighborhoodService;
this.worldIdService = worldIdService; this.worldIdService = worldIdService;
this.buddyService = buddyService;
this.config = config; this.config = config;
} }
@ -1142,12 +1145,40 @@ public class ContentController : Controller {
return Ok(taskResult); 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] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("ContentWebService.asmx/GetBuddyList")] [Route("ContentWebService.asmx/GetBuddyList")]
public IActionResult GetBuddyList() { [VikingSession]
// TODO: this is a placeholder public IActionResult GetBuddyList(Viking viking) {
return Ok(new BuddyList { Buddy = new Schema.Buddy[0] }); return Ok(buddyService.ConstructBuddyList(viking));
} }
[HttpPost] [HttpPost]

View File

@ -42,6 +42,7 @@ builder.Services.AddScoped<ProfileService>();
builder.Services.AddScoped<NeighborhoodService>(); builder.Services.AddScoped<NeighborhoodService>();
builder.Services.AddScoped<ModerationService>(); builder.Services.AddScoped<ModerationService>();
builder.Services.AddScoped<MessagingService>(); builder.Services.AddScoped<MessagingService>();
builder.Services.AddScoped<BuddyService>();
bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue<bool>("Enabled"); bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue<bool>("Enabled");
string assetIP = builder.Configuration.GetSection("AssetServer").GetValue<string>("ListenIP"); string assetIP = builder.Configuration.GetSection("AssetServer").GetValue<string>("ListenIP");

View File

@ -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) public void RemoveBuddy(Viking viking, Guid buddyUid)
{ {
// find buddy viking // find buddy viking