test: edit user action backend

This commit is contained in:
Yinyin Liu 2024-07-18 09:37:40 +02:00
parent 74c0d5235b
commit ce50b7ef3e
4 changed files with 63 additions and 0 deletions

View File

@ -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))] [HttpPost(nameof(EditInstallationConfig))]
public async Task<ActionResult<IEnumerable<Object>>> EditInstallationConfig([FromBody] Configuration config, Int64 installationId,Token authToken) public async Task<ActionResult<IEnumerable<Object>>> EditInstallationConfig([FromBody] Configuration config, Int64 installationId,Token authToken)

View File

@ -144,6 +144,34 @@ public static class SessionMethods
Db.HandleAction(action); Db.HandleAction(action);
return true; 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) public static Boolean Delete(this Session? session, Folder? folder)
{ {

View File

@ -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) public static void HandleError(Error newError,int installationId)
{ {
//Find the total number of errors for this installation //Find the total number of errors for this installation

View File

@ -27,6 +27,11 @@ public static partial class Db
{ {
return Update(obj: warning); return Update(obj: warning);
} }
// public static Boolean Update(UserAction action)
// {
// return Update(obj: action);
// }
public static Boolean Update(Installation installation) public static Boolean Update(Installation installation)
{ {