mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 06:03:12 +00:00
Add JSON-based AddCommentJson endpoint
- Accepts JSON body instead of FormData for simple text comments - Returns new comment with user name for immediate UI update - Defaults to internal comment type
This commit is contained in:
parent
e1f57d3fb2
commit
18ca737307
1 changed files with 34 additions and 0 deletions
|
|
@ -824,6 +824,40 @@ namespace Api.SeaHavenIndustries.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("AddCommentJson")]
|
||||
public async Task<IActionResult> AddCommentJson([FromBody] Comments_DTO model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = _httpContext?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "";
|
||||
var comment = new Comments
|
||||
{
|
||||
CreatedDate = DateTime.UtcNow,
|
||||
UserId = userId,
|
||||
WorkerOrderId = model.WorkorderId,
|
||||
Commenttext = model.Text,
|
||||
CommentType = model.CommentType ?? "internal",
|
||||
};
|
||||
_db.Comments.Add(comment);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
var user = await _db.Users.FindAsync(userId);
|
||||
return Ok(new
|
||||
{
|
||||
comment.Id,
|
||||
comment.CreatedDate,
|
||||
comment.Commenttext,
|
||||
comment.CommentType,
|
||||
userName = user != null ? (user.FirstName + " " + user.LastName).Trim() : ""
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(new Response { Status = "Error", Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("GetComments")]
|
||||
public async Task<IActionResult> GetComments()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue