test: edit user action backend
This commit is contained in:
parent
74c0d5235b
commit
ce50b7ef3e
|
@ -798,6 +798,23 @@ public class Controller : ControllerBase
|
|||
|
||||
}
|
||||
|
||||
[HttpPost(nameof(UpdateAction))]
|
||||
public async Task<ActionResult<IEnumerable<Object>>> UpdateAction([FromBody] UserAction action, Token authToken)
|
||||
{
|
||||
var session = Db.GetSession(authToken);
|
||||
var actionSuccess = await session.UpdateUserAction(action);
|
||||
return actionSuccess ? Ok() : Unauthorized();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost(nameof(DeleteAction))]
|
||||
public async Task<ActionResult<IEnumerable<Object>>> DeleteAction([FromBody] UserAction action, Token authToken)
|
||||
{
|
||||
var session = Db.GetSession(authToken);
|
||||
var actionSuccess = await session.DeleteUserAction(action);
|
||||
return actionSuccess ? Ok() : Unauthorized();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost(nameof(EditInstallationConfig))]
|
||||
public async Task<ActionResult<IEnumerable<Object>>> EditInstallationConfig([FromBody] Configuration config, Int64 installationId,Token authToken)
|
||||
|
|
|
@ -144,6 +144,34 @@ public static class SessionMethods
|
|||
Db.HandleAction(action);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<Boolean> UpdateUserAction(this Session? session, UserAction action)
|
||||
{
|
||||
var user = session?.User;
|
||||
|
||||
if (user is null || user.UserType == 0)
|
||||
return false;
|
||||
|
||||
action.UserName = user.Name;
|
||||
|
||||
Db.UpdateAction(action);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<Boolean> DeleteUserAction(this Session? session, UserAction action)
|
||||
{
|
||||
var user = session?.User;
|
||||
|
||||
if (user is null || user.UserType == 0)
|
||||
return false;
|
||||
|
||||
action.UserName = user.Name;
|
||||
|
||||
Db.Delete(action);
|
||||
Console.WriteLine("---------------Deleted the Action in the database-----------------");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Boolean Delete(this Session? session, Folder? folder)
|
||||
{
|
||||
|
|
|
@ -108,6 +108,19 @@ public static partial class Db
|
|||
}
|
||||
}
|
||||
|
||||
public static void UpdateAction(UserAction updatedAction)
|
||||
{
|
||||
var existingAction = UserActions.FirstOrDefault(action => action.Id == updatedAction.Id);
|
||||
if (existingAction != null)
|
||||
{
|
||||
existingAction.Description = updatedAction.Description;
|
||||
existingAction.Timestamp = updatedAction.Timestamp;
|
||||
//Update(existingAction);
|
||||
Console.WriteLine("---------------Updated the Action in the database-----------------");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void HandleError(Error newError,int installationId)
|
||||
{
|
||||
//Find the total number of errors for this installation
|
||||
|
|
|
@ -27,6 +27,11 @@ public static partial class Db
|
|||
{
|
||||
return Update(obj: warning);
|
||||
}
|
||||
|
||||
// public static Boolean Update(UserAction action)
|
||||
// {
|
||||
// return Update(obj: action);
|
||||
// }
|
||||
|
||||
public static Boolean Update(Installation installation)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue