Skip to content

Commit

Permalink
Merge pull request #78 from LinThitHtwe/dev
Browse files Browse the repository at this point in the history
[add] appointment get all for admin
  • Loading branch information
LinThitHtwe authored Sep 10, 2024
2 parents f4278fd + 8d1362e commit 1cc251f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
22 changes: 20 additions & 2 deletions REMS.BackendApi/Features/Appointment/AppointmentController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace REMS.BackendApi.Features.Appointment;
using Microsoft.AspNetCore.Authorization;

namespace REMS.BackendApi.Features.Appointment;

[Route("api/v1/appointments")]
[ApiController]
Expand Down Expand Up @@ -75,7 +77,7 @@ public async Task<IActionResult> UpdateAppointment(int id, AppointmentRequestMod
}

[HttpGet("client/{id}/{pageNo}/{pageSize}", Name = "GetAppointmentByClientId")]
public async Task<IActionResult> GetAppointmentByClientId(int id, int pageNo, int pageSize)
public async Task<IActionResult> GetAppointmentByClientId(int id, int pageNo = 1, int pageSize = 10)
{
try
{
Expand All @@ -89,4 +91,20 @@ public async Task<IActionResult> GetAppointmentByClientId(int id, int pageNo, in
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}
[Authorize(Roles = "Admin")]
[HttpGet("admin/{pageNo}/{pageSize}", Name = "GetAllAppointmentsForAdmin")]
public async Task<IActionResult> GetAllAppointmentsForAdmin(int pageNo = 1, int pageSize = 10)
{
try
{
var response = await _blAppointment.GetAllAppointments(pageNo, pageSize);
if (response.IsError)
return BadRequest(response);
return Ok(response);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}
}
5 changes: 5 additions & 0 deletions REMS.Modules/Features/Appointment/BL_Appointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public async Task<Result<AppointmentDetailList>> GetAppointmentByClientId(int cl
{
return await _daAppointment.GetAppointmentByClientId(clientId, pageNo, pageSize);
}

public async Task<Result<AppointmentDetailList>> GetAllAppointments(int pageNo, int pageSize)
{
return await _daAppointment.GetAllAppointments(pageNo, pageSize);
}
}
59 changes: 59 additions & 0 deletions REMS.Modules/Features/Appointment/DA_Appointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,63 @@ join _user in _db.Users on _age.UserId equals _user.UserId

return model;
}

public async Task<Result<AppointmentDetailList>> GetAllAppointments(int pageNo, int pageSize)
{
Result<AppointmentDetailList> model = null;
try
{
var query = from app in _db.Appointments
join cli in _db.Clients on app.ClientId equals cli.ClientId
join pro in _db.Properties on app.PropertyId equals pro.PropertyId
join age in _db.Agents on pro.AgentId equals age.AgentId
join user in _db.Users on age.UserId equals user.UserId
select new AppointmentDetail
{
AppointmentId = app.AppointmentId,
AgentName = age.AgencyName,
ClientName = $"{cli.FirstName} {cli.LastName}",
AppointmentDate = app.AppointmentDate.ToString("yyyy-MM-dd"),
AppointmentTime = app.AppointmentTime.ToString(),
AgentPhoneNumber = user.Phone,
Status = app.Status,
Note = app.Notes,
Address = pro.Address,
City = pro.City,
State = pro.State,
Price = pro.Price,
Size = pro.Size,
NumberOfBedrooms = pro.NumberOfBedrooms,
NumberOfBathrooms = pro.NumberOfBathrooms
};

var totalCount = await query.CountAsync();

var appointmentList = await query
.Skip((pageNo - 1) * pageSize)
.Take(pageSize)
.ToListAsync();


if (!appointmentList.Any())
throw new Exception("No Data Found");

var pageCount = (int)Math.Ceiling((double)totalCount / pageSize);

var appointmentDetailList = new AppointmentDetailList
{
pageSetting = new PageSettingModel(pageNo, pageSize, pageCount, totalCount),
appointmentDetails = appointmentList
};


model = Result<AppointmentDetailList>.Success(appointmentDetailList);
return model;
}
catch (Exception ex)
{
model = Result<AppointmentDetailList>.Error(ex);
return model;
}
}
}

0 comments on commit 1cc251f

Please sign in to comment.