forked from SoDOff-Project/sodoff
Buddy System #3
@ -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<ApiServerConfig> config;
|
||||
|
||||
@ -40,6 +41,7 @@ public class ContentController : Controller {
|
||||
DisplayNamesService displayNamesService,
|
||||
NeighborhoodService neighborhoodService,
|
||||
WorldIdService worldIdService,
|
||||
BuddyService buddyService,
|
||||
IOptions<ApiServerConfig> 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]
|
||||
|
@ -42,6 +42,7 @@ builder.Services.AddScoped<ProfileService>();
|
||||
builder.Services.AddScoped<NeighborhoodService>();
|
||||
builder.Services.AddScoped<ModerationService>();
|
||||
builder.Services.AddScoped<MessagingService>();
|
||||
builder.Services.AddScoped<BuddyService>();
|
||||
|
||||
bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue<bool>("Enabled");
|
||||
string assetIP = builder.Configuration.GetSection("AssetServer").GetValue<string>("ListenIP");
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user