added an API to get a list of contact-notes by contact ID
This commit is contained in:
parent
42b5478b52
commit
f7543a37a1
@ -188,5 +188,27 @@ namespace Marco.Pms.Model.Mapper
|
||||
Description = bucket.Description
|
||||
};
|
||||
}
|
||||
|
||||
//Contact Note
|
||||
public static ContactNote ToContactNoteFromCreateContactNoteDto(this CreateContactNoteDto noteDto, Guid tenantId, Guid employeeId)
|
||||
{
|
||||
return new ContactNote
|
||||
{
|
||||
Note = noteDto.Note,
|
||||
ContactId = noteDto.ContactId,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
CreatedById = employeeId,
|
||||
TenantId = tenantId
|
||||
};
|
||||
}
|
||||
public static ContactNoteVM ToContactNoteVMFromContactNote(this ContactNote note)
|
||||
{
|
||||
return new ContactNoteVM
|
||||
{
|
||||
Id = note.Id,
|
||||
Note = note.Note,
|
||||
ContactId = note.ContactId
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,6 +99,73 @@ namespace Marco.Pms.Services.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------- Contact Notes --------------------------------
|
||||
|
||||
[HttpPost("note")]
|
||||
public async Task<IActionResult> CreateContactNote([FromBody] CreateContactNoteDto noteDto)
|
||||
{
|
||||
return Ok();
|
||||
//var response = await _directoryHelper.CreateContactNote(noteDto);
|
||||
//if (response.StatusCode == 200)
|
||||
//{
|
||||
//return Ok(response);
|
||||
//}
|
||||
//else if (response.StatusCode == 404)
|
||||
//{
|
||||
// return NotFound(response);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return BadRequest(response);
|
||||
//}
|
||||
}
|
||||
|
||||
[HttpGet("note/{ContactId}")]
|
||||
public async Task<IActionResult> GetNoteListByContactId(Guid contactId)
|
||||
{
|
||||
var response = await _directoryHelper.GetNoteListByContactId(contactId);
|
||||
if (response.StatusCode == 200)
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
else if (response.StatusCode == 404)
|
||||
{
|
||||
return NotFound(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(response);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("note/{id}")]
|
||||
public async Task<IActionResult> UpdateContactNote(Guid id, [FromBody] UpdateContactNoteDto noteDto)
|
||||
{
|
||||
return Ok();
|
||||
//var response = await _directoryHelper.UpdateContactNote(id, noteDto);
|
||||
//if (response.StatusCode == 200)
|
||||
//{
|
||||
// return Ok(response);
|
||||
//}
|
||||
//else if (response.StatusCode == 404)
|
||||
//{
|
||||
// return NotFound(response);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return BadRequest(response);
|
||||
//}
|
||||
}
|
||||
|
||||
[HttpDelete("note/{id}")]
|
||||
public async Task<IActionResult> DeleteContactNote(Guid id)
|
||||
{
|
||||
return Ok();
|
||||
//var response = await _directoryHelper.DeleteContactNote(id);
|
||||
//return Ok(response);
|
||||
}
|
||||
|
||||
// -------------------------------- Bucket --------------------------------
|
||||
|
||||
[HttpGet("buckets")]
|
||||
public async Task<IActionResult> GetBucketList()
|
||||
|
@ -1963,6 +1963,29 @@ namespace Marco.Pms.Services.Helpers
|
||||
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
||||
}
|
||||
|
||||
// -------------------------------- Contact Notes --------------------------------
|
||||
|
||||
public async Task<ApiResponse<object>> GetNoteListByContactId(Guid id)
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
Contact? contact = await _context.Contacts.FirstOrDefaultAsync(c => c.Id == id && c.IsActive && c.TenantId == tenantId);
|
||||
if (contact != null)
|
||||
{
|
||||
List<ContactNote>? notes = await _context.ContactNotes.Where(n => n.ContactId == contact.Id && n.IsActive).ToListAsync();
|
||||
List<ContactNoteVM>? noteVMs = new List<ContactNoteVM>();
|
||||
foreach (var note in notes)
|
||||
{
|
||||
ContactNoteVM noteVM = note.ToContactNoteVMFromContactNote();
|
||||
noteVMs.Add(noteVM);
|
||||
}
|
||||
_logger.LogInfo("{count} contact-notes record from contact {ContactId} fetched by Employee {EmployeeId}", noteVMs.Count, id, LoggedInEmployee.Id);
|
||||
return ApiResponse<object>.SuccessResponse(noteVMs, $"{noteVMs.Count} contact-notes record fetched successfully", 200);
|
||||
}
|
||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} attempted to fetch a list notes from contact with ID {ContactId}, but the contact was not found in the database.", LoggedInEmployee.Id, id);
|
||||
return ApiResponse<object>.ErrorResponse("Contact not found", "Contact not found", 404);
|
||||
}
|
||||
|
||||
// -------------------------------- Bucket --------------------------------
|
||||
|
||||
public async Task<ApiResponse<object>> GetBucketList()
|
||||
|
Loading…
x
Reference in New Issue
Block a user