Skip to content

Commit

Permalink
Merge pull request #65 from one-project-one-month/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
nyeinchannmoe authored Aug 18, 2024
2 parents 3b547ec + c35e00f commit 2990afd
Show file tree
Hide file tree
Showing 21 changed files with 402 additions and 162 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,28 @@ Scaffold-DbContext "Server=.;Database=AdminPortal;User ID=sa; Password=sa@123;In

### CI

GitHub Actions
GitHub Actions

https://stackoverflow.com/questions/30346907/how-to-remove-webdav-module-from-iis
https://learn.microsoft.com/en-us/answers/questions/856808/iis-net-6-aspnetcorev2-405-method-not-allowed
```xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<verbs>
<add verb="GET" allowed="true" />
<add verb="POST" allowed="true" />
<add verb="PUT" allowed="true" />
<add verb="PATCH" allowed="true" />
<add verb="DELETE" allowed="true" />
</verbs>
</requestFiltering>
</security>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</configuration>
```
16 changes: 8 additions & 8 deletions REMS.BackendApi/Features/Agent/AgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ public async Task<IActionResult> UpdateAgent(int userId, AgentRequestModel reque
}
}

[HttpPost("LoginAgent", Name = "LoginAgent")]
public async Task<IActionResult> LoginAgent(AgentLoginRequestModel agentLoginInfo)
{
Result<string> res = await _blAgent.LoginAgentAsync(agentLoginInfo);

return Ok(res);
}

[HttpGet("SearchUser/{id}", Name = "SearchUser")]
public async Task<IActionResult> SearchUser(int id)
{
Expand All @@ -96,4 +88,12 @@ public async Task<IActionResult> SearchAgentByNameAndLocation(SearchAgentRequest

return Ok(agentList);
}

[HttpGet("AgentAll", Name = "AgentAll")]
public async Task<IActionResult> AgentAll()
{
Result<List<AgentDto>> agentList = await _blAgent.AgentAll();

return Ok(agentList);
}
}
18 changes: 17 additions & 1 deletion REMS.BackendApi/Features/Appointment/AppointmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<IActionResult> DeleteAppointment(int id)
}

[HttpGet("{propertyId}/{pageNo}/{pageSize}")]
public async Task<IActionResult> GetAppointmentByAgentId(int propertyId, int pageNo, int pageSize)
public async Task<IActionResult> GetAppointmentByPropertyIdAsync(int propertyId, int pageNo, int pageSize)
{
try
{
Expand Down Expand Up @@ -76,5 +76,21 @@ public async Task<IActionResult> UpdateAppointment(int id, AppointmentRequestMod
return StatusCode(StatusCodes.Status500InternalServerError, ex);
}
}

[HttpGet("GetAppointmentByClientId/{clientId}/{pageNo}/{pageSize}", Name = "GetAppointmentByClientId")]
public async Task<IActionResult> GetAppointmentByClientId(int clientId, int pageNo, int pageSize)
{
try
{
var response = await _blAppointment.GetAppointmentByClientId(clientId, pageNo, pageSize);
if (response.IsError)
return BadRequest(response);
return Ok(response);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}
}
}
2 changes: 1 addition & 1 deletion REMS.BackendApi/Features/Client/ClientController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace REMS.BackendApi.Features.Client;

[Route("api/v1/clients")]
[ApiController]
[Authorize(Roles = "Agent")]
//[Authorize(Roles = "Agent")]
public class ClientController : ControllerBase
{
private readonly BL_Client _blClient;
Expand Down
90 changes: 65 additions & 25 deletions REMS.BackendApi/Features/Property/PropertyController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using REMS.Models.Property;
using REMS.Models;
using REMS.Models.Property;

namespace REMS.BackendApi.Features.Property;

Expand All @@ -14,11 +15,16 @@ public PropertyController(BL_Property blProperties)
}

[HttpGet]
public async Task<IActionResult> GetProperties()
public async Task<IActionResult> GetProperties(string? propertyStatus = "")
{
try
{
var response = await _blProperties.GetProperties();
if (!string.IsNullOrWhiteSpace(propertyStatus) && !IsValidPropertyStatus(propertyStatus))
{
return BadRequest($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
}

var response = await _blProperties.GetProperties(propertyStatus);
return Ok(response);
}
catch (Exception ex)
Expand All @@ -28,11 +34,16 @@ public async Task<IActionResult> GetProperties()
}

[HttpGet("{pageNo}/{pageSize}")]
public async Task<IActionResult> GetProperties(int pageNo, int pageSize)
public async Task<IActionResult> GetProperties(int pageNo, int pageSize, string? propertyStatus = "")
{
try
{
var response = await _blProperties.GetProperties(pageNo, pageSize);
if (!string.IsNullOrWhiteSpace(propertyStatus) && !IsValidPropertyStatus(propertyStatus))
{
return BadRequest($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
}

var response = await _blProperties.GetProperties(pageNo, pageSize, propertyStatus);
return Ok(response);
}
catch (Exception ex)
Expand All @@ -42,13 +53,13 @@ public async Task<IActionResult> GetProperties(int pageNo, int pageSize)
}

[HttpGet("agent/{agentId}")]
public async Task<IActionResult> GetPropertiesByAgentId(int agentId, [FromQuery] string propertyStatus = nameof(PropertyStatus.Approved))
public async Task<IActionResult> GetPropertiesByAgentId(int agentId, [FromQuery] string propertyStatus = "")
{
try
{
if (!Enum.TryParse<PropertyStatus>(propertyStatus, out var parsedStatus) || !Enum.IsDefined(typeof(PropertyStatus), parsedStatus))
if (!string.IsNullOrWhiteSpace(propertyStatus) && !IsValidPropertyStatus(propertyStatus))
{
throw new Exception($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
return BadRequest($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
}

var response = await _blProperties.GetPropertiesByAgentId(agentId, propertyStatus);
Expand All @@ -61,13 +72,13 @@ public async Task<IActionResult> GetPropertiesByAgentId(int agentId, [FromQuery]
}

[HttpGet("agent/{agentId}/{pageNo}/{pageSize}")]
public async Task<IActionResult> GetPropertiesByAgentId(int agentId, int pageNo, int pageSize, [FromQuery] string propertyStatus = nameof(PropertyStatus.Approved))
public async Task<IActionResult> GetPropertiesByAgentId(int agentId, int pageNo, int pageSize, [FromQuery] string propertyStatus = "")
{
try
{
if (!Enum.TryParse<PropertyStatus>(propertyStatus, out var parsedStatus) || !Enum.IsDefined(typeof(PropertyStatus), parsedStatus))
if (!string.IsNullOrWhiteSpace(propertyStatus) && !IsValidPropertyStatus(propertyStatus))
{
throw new Exception($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
return BadRequest($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
}

var response = await _blProperties.GetPropertiesByAgentId(agentId, pageNo, pageSize, propertyStatus);
Expand Down Expand Up @@ -96,15 +107,15 @@ public async Task<IActionResult> GetPropertyById(int propertyId)
[HttpPost]
public async Task<IActionResult> CreateProperty([FromBody] PropertyRequestModel requestModel)
{
if (requestModel == null)
var validationResult = ValidatePropertyRequestModel(requestModel);
if (validationResult != null)
{
return BadRequest("Request model cannot be null");
return validationResult;
}

try
{
var response = await _blProperties.CreateProperty(requestModel);
// return CreatedAtAction(nameof(GetPropertyById), new { propertyId = response.Property.PropertyId }, response);
return Ok(response);
}
catch (Exception ex)
Expand All @@ -113,17 +124,18 @@ public async Task<IActionResult> CreateProperty([FromBody] PropertyRequestModel
}
}

[HttpPut("{propertyId}")]
[HttpPut("Update/{propertyId}")]
public async Task<IActionResult> UpdateProperty(int propertyId, [FromBody] PropertyRequestModel requestModel)
{
if (propertyId < 1)
{
return BadRequest("Invalid Property Id");
}

if (requestModel == null)
var validationResult = ValidatePropertyRequestModel(requestModel);
if (validationResult != null)
{
return BadRequest("Request model cannot be null");
return validationResult;
}

try
Expand Down Expand Up @@ -174,18 +186,46 @@ public async Task<IActionResult> DeleteProperty(int propertyId)
{
var result = await _blProperties.DeleteProperty(propertyId);
return Ok(result);
//if (result)
//{
// return NoContent();
//}
//else
//{
// return NotFound("Property not found");
//}
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}

private IActionResult ValidatePropertyRequestModel(PropertyRequestModel requestModel)
{
if (requestModel == null)
{
return BadRequest("Request model cannot be null");
}

if (!IsValidPropertyType(requestModel.PropertyType))
{
return BadRequest($"Invalid Type; Property Type should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyType)))}");
}

if (!IsValidPropertyAvailiableType(requestModel.AvailiablityType))
{
return BadRequest($"Invalid Availability Type; Property Availability Type should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyAvailiableType)))}");
}

return null;
}


private static bool IsValidPropertyStatus(string status)
{
return Enum.TryParse<PropertyStatus>(status, out var parsedStatus) && Enum.IsDefined(typeof(PropertyStatus), parsedStatus);
}

private static bool IsValidPropertyType(string propertyType)
{
return Enum.TryParse<PropertyType>(propertyType, out var parsedPropertyType) && Enum.IsDefined(typeof(PropertyType), parsedPropertyType);
}

private static bool IsValidPropertyAvailiableType(string propertyAvailiableType)
{
return Enum.TryParse<PropertyAvailiableType>(propertyAvailiableType, out var paresedPropertyAvailiableType) && Enum.IsDefined(typeof(PropertyAvailiableType), paresedPropertyAvailiableType);
}
}
4 changes: 2 additions & 2 deletions REMS.BackendApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"AllowedHosts": "*",
"ConnectionStrings": {
//"DbConnection": "Server=.;Database=REMS;User Id=sa;Password=sasa@123;TrustServerCertificate=True;",
"DbConnection": "Server=.;Database=rems;User Id=sa;Password=sasa@123;TrustServerCertificate=True;"
//"DbConnection": "Server=LAPTOP-TTIU8JF8;Database=REMS;User Id=sa;Password=Minkhantthu3367;TrustServerCertificate=True;"
//"DbConnection": "Server=.;Database=rems;User Id=sa;Password=sasa@123;TrustServerCertificate=True;"
"DbConnection": "Server=LAPTOP-TTIU8JF8;Database=REMS;User Id=sa;Password=Minkhantthu3367;TrustServerCertificate=True;"
//"DbConnection": "Server=.;Database=REMS;User Id=sa;Password=P@ssw0rd;TrustServerCertificate=True;"
//"DbConnection": "Server=.\\SQL2019E;Database=REMS;User Id=sa;Password=p@ssw0rd;TrustServerCertificate=True;"
},
Expand Down
5 changes: 3 additions & 2 deletions REMS.Mapper/ChangeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public static Client Change(this ClientRequestModel requestModel)
return client;
}

public static ClientResponseModel Change(this Client dataModel, User user)
public static ClientModel Change(this Client dataModel, User user)
{
var clientResponseModel = new ClientResponseModel
var clientResponseModel = new ClientModel
{
ClientId = dataModel.ClientId,
UserId = dataModel.UserId,
Expand Down Expand Up @@ -214,6 +214,7 @@ public static ReviewModel Change(this Review dataModel)
PropertyId = dataModel.PropertyId,
Rating = dataModel.Rating,
Comments = dataModel.Comments,
DateCreated = dataModel.DateCreated,
};

return reviewModel;
Expand Down
30 changes: 30 additions & 0 deletions REMS.Models/Appointment/AppointmentDetail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

using REMS.Models.Custom;

namespace REMS.Models.Appointment;


public partial class AppointmentDetail
{
public int? AppointmentId { get; set; }
public string? AgentName { get; set; }
public string? ClientName { get; set; }
public string? AppointmentDate { get; set; }
public string? AppointmentTime { get; set; }
public string? AgentPhoneNumber { get; set; }
public string? Status { get; set; }
public string? Note { get; set; }
public string? Address { get; set; }
public string? City { get; set; }
public string? State { get; set; }
public decimal? Price { get; set; }
public decimal? Size { get; set; }
public int? NumberOfBedrooms { get; set; }
public int? NumberOfBathrooms { get; set; }
}

public partial class AppointmentDetailList
{
public PageSettingModel? pageSetting { get; set; }
public List<AppointmentDetail> appointmentDetails { get; set; }

Check warning on line 29 in REMS.Models/Appointment/AppointmentDetail.cs

View workflow job for this annotation

GitHub Actions / Build and Test (8.0.x, ubuntu-latest)

Non-nullable property 'appointmentDetails' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 29 in REMS.Models/Appointment/AppointmentDetail.cs

View workflow job for this annotation

GitHub Actions / Build and Test (6.0.x, ubuntu-latest)

Non-nullable property 'appointmentDetails' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 29 in REMS.Models/Appointment/AppointmentDetail.cs

View workflow job for this annotation

GitHub Actions / Build and Test (8.0.x, windows-latest)

Non-nullable property 'appointmentDetails' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
6 changes: 5 additions & 1 deletion REMS.Models/Appointment/AppointmentResponseModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using REMS.Database.AppDbContextModels;
using REMS.Models.Agent;
using REMS.Models.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -9,5 +12,6 @@ namespace REMS.Models.Appointment
public class AppointmentResponseModel
{
public AppointmentModel? Appointment { get; set; }

}
}
2 changes: 1 addition & 1 deletion REMS.Models/Client/ClientListResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace REMS.Models.Client;

public class ClientListResponseModel
{
public List<ClientResponseModel> DataLst { get; set; }
public List<ClientModel> DataLst { get; set; }

Check warning on line 13 in REMS.Models/Client/ClientListResponseModel.cs

View workflow job for this annotation

GitHub Actions / Build and Test (8.0.x, windows-latest)

Non-nullable property 'DataLst' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in REMS.Models/Client/ClientListResponseModel.cs

View workflow job for this annotation

GitHub Actions / Build and Test (6.0.x, windows-latest)

Non-nullable property 'DataLst' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public PageSettingModel PageSetting { get; set; }

Check warning on line 14 in REMS.Models/Client/ClientListResponseModel.cs

View workflow job for this annotation

GitHub Actions / Build and Test (8.0.x, windows-latest)

Non-nullable property 'PageSetting' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in REMS.Models/Client/ClientListResponseModel.cs

View workflow job for this annotation

GitHub Actions / Build and Test (6.0.x, windows-latest)

Non-nullable property 'PageSetting' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
2 changes: 2 additions & 0 deletions REMS.Models/Client/ClientModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public class ClientModel
public string? Email { get; set; }

public string? Address { get; set; }

public string? Role { get; set; }
}
6 changes: 5 additions & 1 deletion REMS.Models/Property/PropertyResponseModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace REMS.Models.Property;
using REMS.Models.Review;

namespace REMS.Models.Property;

public class PropertyResponseModel
{
public PropertyModel Property { get; set; }
public List<PropertyImageModel> Images { get; set; }

public List<ReviewModel> Reviews { get; set; }
}
5 changes: 5 additions & 0 deletions REMS.Models/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public static Result<T> Error(Exception ex)
IsSuccess = false,
};
}

public static implicit operator Result<T>(Result<string>? v)
{
throw new NotImplementedException();
}
}
Loading

0 comments on commit 2990afd

Please sign in to comment.