910 lines
28 KiB
C#
910 lines
28 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xIdentityHelper;
|
|
using xCommons.Attributes;
|
|
using xCommons.Extensions;
|
|
using xIdentityModels.Constants;
|
|
using xIdentityModels.Dtos;
|
|
using xIdentityModels.Navigations;
|
|
using xModels.Dtos;
|
|
using System.Linq;
|
|
using xExceptions.Constants;
|
|
|
|
namespace xApi.Controllers
|
|
{
|
|
public partial class AccountController
|
|
{
|
|
//
|
|
#region Friendship Actions ...
|
|
/// <summary>
|
|
/// Follow a User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
|
[RequireXPowered]
|
|
[HttpPost("Friendship/{destUser}/Follow")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<XFriendshipFollowing>> Follow(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.Follow(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cancel Following Request
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>a boolean value</returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/Cancel")]
|
|
public async Task<ActionResult<bool>> Cancel(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.Cancel(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unfollow a Follower
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/UnFollowFollower")]
|
|
public async Task<ActionResult> UnFollowFollower(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
await identityProvider
|
|
.UnFollowFollower(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unfollow Following
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/UnFollowFollowing")]
|
|
public async Task<ActionResult> UnFollowFollowing(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
await identityProvider
|
|
.UnFollowFollowing(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Block a Follower
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
|
[HttpPost("Friendship/{destUser}/Block")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<XFriendshipFollowing>> Block(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.Block(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
|
|
//
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unblock a Blocked User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
|
[HttpPost("Friendship/{destUser}/UnBlock")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<XFriendshipFollowing>> UnBlock(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.UnBlock(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Accept a Following Request
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/AcceptRequest")]
|
|
public async Task<ActionResult<XFriendshipFollower>> AcceptRequest(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.AcceptRequest(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
// Prepare Push Message ...
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reject a Following Request
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Friendship/{destUser}/RejectRequest")]
|
|
public async Task<ActionResult<XFriendshipFollower>> RejectRequest(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.RejectRequest(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Friendship Getters ...
|
|
|
|
/// <summary>
|
|
/// Get Friendship Info Model between Specific User and Current User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipInfoDto</see></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FriendshipInfo")]
|
|
public async Task<ActionResult<XFriendshipInfoDto>> FriendshipInfo(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFriendshipInfo(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check a User IsFollower of Requested User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>a boolean value</returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/IsFollower")]
|
|
public async Task<ActionResult<bool>> IsFollower(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.IsFollower(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Follower State of a User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipState</see></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FollowerState")]
|
|
public async Task<ActionResult<XFriendshipState>> FollowerState(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFollowerState(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Specific Follower
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/Follower")]
|
|
public async Task<ActionResult<XFriendshipFollower>> Follower(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFollower(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Followers List Of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of <see>XFriendshipFollower</see></returns>
|
|
[HttpGet("Friendship/Followers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<IEnumerable<XFriendshipFollower>>> Followers()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFollowers(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
|
|
//
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Followers List Includes Blocked, Requested and etc
|
|
/// of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of <see>XFriendshipFollower</see></returns>
|
|
[HttpGet("Friendship/AllFollowers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<IEnumerable<XFriendshipFollower>>> AllFollowers()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetAllFollowers(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Followers List Includes Blocked, Requested and etc
|
|
/// of Current User based On Query Model ...
|
|
/// </summary>
|
|
/// <returns>a Query Result of <see>XFriendDto</see></returns>
|
|
[HttpGet("Friendship/QueryFollowers")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<XQueryResult<XFriendDto>>> QueryFollowers(
|
|
[FromQuery] XQuery query,
|
|
[FromQuery] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Normalizing Dest User ...
|
|
var userInfo = await GetUserInfo();
|
|
bool isAdmin = userInfo.Roles.Contains(XUserRoles.ADMIN);
|
|
if (destUser.IsNullOrEmpty())
|
|
{
|
|
destUser = userInfo.UserName;
|
|
}
|
|
bool isDestUserValid = isAdmin || destUser == userInfo.UserId || destUser == userInfo.Email || destUser == userInfo.PhoneNumber || destUser == userInfo.UserName;
|
|
if (!isDestUserValid)
|
|
{
|
|
XException.NotAllowed.Throw();
|
|
}
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.QueryFollowers(
|
|
query: query,
|
|
tokens: tokens,
|
|
destUser: destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check a User is in Followings of Current User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>a boolean value</returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/IsFollowing")]
|
|
public async Task<ActionResult<bool>> IsFollowing(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.IsFollowing(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Following State Relation between Specific User
|
|
/// and Current User
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipState</see></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/FollowingState")]
|
|
public async Task<ActionResult<XFriendshipState>> FollowingState(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFollowingState(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Specific Following Model
|
|
/// </summary>
|
|
/// <param name="destUser">a user identifier which represent destination user</param>
|
|
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Friendship/{destUser}/Following")]
|
|
public async Task<ActionResult<XFriendshipFollowing>> Following(
|
|
[FromRoute] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Validate Args ...
|
|
ValidationProvider.NotEmpty(destUser);
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFollowing(
|
|
tokens,
|
|
destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Followings of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of <see>XFriendshipFollowing</see></returns>
|
|
[HttpGet("Friendship/Followings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<IEnumerable<XFriendshipFollowing>>> Followings()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFollowings(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Following List Includes Blocked, Requested and etc
|
|
/// of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of <see>XFriendshipFollowing</see></returns>
|
|
[HttpGet("Friendship/AllFollowings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<IEnumerable<XFriendshipFollowing>>> AllFollowings()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetAllFollowings(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return Following UserName's List of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of UserNames</returns>
|
|
[HttpGet("Friendship/FollowingsList")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<IEnumerable<string>>> FollowingsList()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFollowingList(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return Followers UserName's List of Current User
|
|
/// </summary>
|
|
/// <returns>a collection of UserNames</returns>
|
|
[HttpGet("Friendship/FollowersList")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<IEnumerable<string>>> FollowersList()
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.GetFollowersList(tokens);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Followings List Includes Blocked, Requested and etc
|
|
/// of Current User based On Query Model ...
|
|
/// </summary>
|
|
/// <returns>a Query Result of <see>XFriendDto</see></returns>
|
|
[HttpGet("Friendship/QueryFollowings")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<XQueryResult<XFriendDto>>> QueryFollowings(
|
|
[FromQuery] XQuery query,
|
|
[FromQuery] string destUser
|
|
)
|
|
{
|
|
//
|
|
// Do Action ...
|
|
try
|
|
{
|
|
//
|
|
// Normalizing Dest User ...
|
|
var userInfo = await GetUserInfo();
|
|
bool isAdmin = userInfo.Roles.Contains(XUserRoles.ADMIN);
|
|
if (destUser.IsNullOrEmpty())
|
|
{
|
|
destUser = userInfo.UserName;
|
|
}
|
|
bool isDestUserValid = isAdmin || destUser == userInfo.UserId || destUser == userInfo.Email || destUser == userInfo.PhoneNumber || destUser == userInfo.UserName;
|
|
if (!isDestUserValid)
|
|
{
|
|
XException.NotAllowed.Throw();
|
|
}
|
|
|
|
//
|
|
var tokens = await RetrieveTokensAsXTokenResponse();
|
|
var result = await identityProvider
|
|
.QueryFollowings(
|
|
query: query,
|
|
tokens: tokens,
|
|
destUser: destUser
|
|
);
|
|
|
|
//
|
|
return Ok(result
|
|
.ToDynamicObject());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var exResult = GetExceptionActionResult(ex);
|
|
return exResult;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |