Added favorite softkey API
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using Step.Database.Controllers;
|
||||
using Step.Model.DatabaseModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using static Step.Model.Constants;
|
||||
|
||||
namespace Step.Controllers.WebApi
|
||||
{
|
||||
[RoutePrefix("api/user_softkey")]
|
||||
public class FavoriteUserSoftkeyController : ApiController
|
||||
{
|
||||
[Route("favorite"), HttpGet]
|
||||
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.MAINTENANCE, Action = ACTIONS.WRITE)]
|
||||
public IHttpActionResult GetFavoriteSoftkeys()
|
||||
{
|
||||
var identity = User.Identity as ClaimsIdentity;
|
||||
// Find user id from the bearer token
|
||||
var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault();
|
||||
int userIdInt = Convert.ToInt32(userId.Value);
|
||||
using (FavoriteUserSoftkeysController controller = new FavoriteUserSoftkeysController())
|
||||
{
|
||||
return Ok(
|
||||
controller.GetUserFavoriteSoftkeys(userIdInt)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("favorite"), HttpPut]
|
||||
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.MAINTENANCE, Action = ACTIONS.WRITE)]
|
||||
public IHttpActionResult PutFavoriteSoftkeys(List<uint> favoriteSoftkeyIds)
|
||||
{
|
||||
var identity = User.Identity as ClaimsIdentity;
|
||||
|
||||
var userId = identity.Claims.Where(c => c.Type == USER_ID_KEY).FirstOrDefault();
|
||||
int intUserId = Convert.ToInt32(userId.Value);
|
||||
using (FavoriteUserSoftkeysController controller = new FavoriteUserSoftkeysController())
|
||||
{
|
||||
// Delete saved softkey
|
||||
controller.DeleteUserSoftkeyModel(intUserId);
|
||||
List<FavoriteUserSoftkeyModel> favorite = new List<FavoriteUserSoftkeyModel>();
|
||||
if (favoriteSoftkeyIds == null && favoriteSoftkeyIds.Count > 0)
|
||||
{
|
||||
// Insert new list of id
|
||||
favorite = controller.InsertUserSoftkeyModel(favoriteSoftkeyIds, intUserId);
|
||||
}
|
||||
|
||||
return Ok(favorite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user