changes
This commit is contained in:
43
Controllers/JournalController.cs
Normal file
43
Controllers/JournalController.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using public_valetax.DTOs;
|
||||
using public_valetax.Exceptions;
|
||||
using public_valetax.Repositories;
|
||||
|
||||
namespace public_valetax.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api.[controller]")]
|
||||
public class JournalController(IJournalRepository _journalRepository) : ControllerBase
|
||||
{
|
||||
[HttpPost("getRange")]
|
||||
public async Task<ActionResult<MRange_MJournalInfo>> GetRange([FromQuery] int skip, [FromQuery] int take, [FromBody] VJournalFilter filter)
|
||||
{
|
||||
var result = await _journalRepository.GetJournalEntriesRangeAsync(skip, take, filter);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("getSingle")]
|
||||
public async Task<ActionResult<MJournal?>> GetSingle([FromQuery] long id)
|
||||
{
|
||||
var result = await _journalRepository.GetJournalEntryAsync(id);
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("simulateError")]
|
||||
public void SimulateError([FromQuery] bool isSecureException, [FromBody] Dictionary<string, object> someBody)
|
||||
{
|
||||
if (isSecureException)
|
||||
{
|
||||
throw new SecureException("Some secure error happened");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Some error happened");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
83
Controllers/NodeController.cs
Normal file
83
Controllers/NodeController.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using public_valetax.Repositories;
|
||||
using public_valetax.Exceptions;
|
||||
|
||||
namespace public_valetax.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api.[controller]")]
|
||||
public class NodeController(ITreeRepository _treeRepository) : ControllerBase
|
||||
{
|
||||
[HttpPost("create")]
|
||||
public async Task<IActionResult> Create(
|
||||
[FromQuery] string treeName,
|
||||
[FromQuery] long? parentNodeId,
|
||||
[FromQuery] string nodeName)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get or create the tree
|
||||
var tree = await _treeRepository.GetTreeByNameAsync(treeName);
|
||||
if (tree == null)
|
||||
{
|
||||
tree = await _treeRepository.CreateTreeAsync(treeName);
|
||||
}
|
||||
|
||||
// Create the node
|
||||
var node = await _treeRepository.CreateNodeAsync(tree.Id, parentNodeId, nodeName);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (SecureException)
|
||||
{
|
||||
// Re-throw secure exceptions to be handled by middleware
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Wrap other exceptions in SecureException to trigger proper error handling
|
||||
throw new SecureException(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("delete")]
|
||||
public async Task<IActionResult> Delete([FromQuery] long nodeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _treeRepository.DeleteNodeAsync(nodeId);
|
||||
return Ok();
|
||||
}
|
||||
catch (SecureException)
|
||||
{
|
||||
// Re-throw secure exceptions to be handled by middleware
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Wrap other exceptions in SecureException to trigger proper error handling
|
||||
throw new SecureException(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("rename")]
|
||||
public async Task<IActionResult> Rename([FromQuery] long nodeId, [FromQuery] string newNodeName)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _treeRepository.RenameNodeAsync(nodeId, newNodeName);
|
||||
return Ok();
|
||||
}
|
||||
catch (SecureException)
|
||||
{
|
||||
// Re-throw secure exceptions to be handled by middleware
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Wrap other exceptions in SecureException to trigger proper error handling
|
||||
throw new SecureException(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Controllers/PartnerController.cs
Normal file
20
Controllers/PartnerController.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using public_valetax.DTOs;
|
||||
|
||||
namespace public_valetax.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api.[controller]")]
|
||||
public class PartnerController : ControllerBase
|
||||
{
|
||||
[HttpPost("rememberMe")]
|
||||
public ActionResult<TokenInfo> RememberMe([FromQuery] string code)
|
||||
{
|
||||
// This is a simplified implementation
|
||||
// In a real application, you would validate the code and generate a proper JWT token
|
||||
var token = $"generated_token_for_code_{code}";
|
||||
|
||||
return Ok(new TokenInfo { Token = token });
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Controllers/TreeController.cs
Normal file
32
Controllers/TreeController.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using public_valetax.DTOs;
|
||||
using public_valetax.Repositories;
|
||||
|
||||
namespace public_valetax.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api.[controller]")]
|
||||
public class TreeController(ITreeRepository _treeRepository) : ControllerBase
|
||||
{
|
||||
[HttpPost("get")]
|
||||
public async Task<ActionResult<MNode>> Get([FromQuery] string treeName)
|
||||
{
|
||||
var tree = await _treeRepository.GetTreeStructureAsync(treeName);
|
||||
|
||||
// If tree doesn't exist, create it
|
||||
if (tree == null)
|
||||
{
|
||||
// Create the tree (implementation would depend on your requirements)
|
||||
// For now, we'll just return an empty structure
|
||||
tree = new MNode
|
||||
{
|
||||
Id = 0,
|
||||
Name = treeName,
|
||||
Children = []
|
||||
};
|
||||
}
|
||||
|
||||
return Ok(tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user