Skip to content

Commit

Permalink
Merge pull request #45 from one-project-one-month/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
sannlynnhtun-coding authored Aug 11, 2024
2 parents 466686a + 5a07bca commit 3b547ec
Show file tree
Hide file tree
Showing 40 changed files with 576 additions and 331 deletions.
4 changes: 4 additions & 0 deletions REMS.BackendApi/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class AppSettings
{
public int Port { get; set; }
}
6 changes: 3 additions & 3 deletions REMS.BackendApi/Features/Appointment/AppointmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public async Task<IActionResult> DeleteAppointment(int id)
}
}

[HttpGet("{id}/{pageNo}/{pageSize}")]
public async Task<IActionResult> GetAppointmentByAgentId(int id, int pageNo, int pageSize)
[HttpGet("{propertyId}/{pageNo}/{pageSize}")]
public async Task<IActionResult> GetAppointmentByAgentId(int propertyId, int pageNo, int pageSize)
{
try
{
var response = await _blAppointment.GetAppointmentByAgentIdAsync(id, pageNo, pageSize);
var response = await _blAppointment.GetAppointmentByPropertyIdAsycn(propertyId, pageNo, pageSize);
if (response.IsError)
return BadRequest(response);
return Ok(response);
Expand Down
5 changes: 4 additions & 1 deletion REMS.BackendApi/Features/Authentication/SigninController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace REMS.BackendApi.Features.Authentication;
using REMS.Models.Authentication;
using REMS.Modules.Features.Authentication;

namespace REMS.BackendApi.Features.Authentication;

[Route("api/v1/")]
[ApiController]
Expand Down
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
43 changes: 39 additions & 4 deletions REMS.BackendApi/Features/Property/PropertyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ public async Task<IActionResult> GetProperties(int pageNo, int pageSize)
}

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

var response = await _blProperties.GetPropertiesByAgentId(agentId, propertyStatus);
return Ok(response);
}
catch (Exception ex)
Expand All @@ -56,11 +61,16 @@ public async Task<IActionResult> GetPropertiesByAgentId(int agentId)
}

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

var response = await _blProperties.GetPropertiesByAgentId(agentId, pageNo, pageSize, propertyStatus);
return Ok(response);
}
catch (Exception ex)
Expand Down Expand Up @@ -127,6 +137,31 @@ public async Task<IActionResult> UpdateProperty(int propertyId, [FromBody] Prope
}
}

[HttpPut("ChangeStatus")]
public async Task<IActionResult> ChangePropertyStatus(PropertyStatusChangeRequestModel requestModel)
{
if (requestModel == null)
{
return BadRequest("Reuqest cannot be null");
}

if (requestModel.PropertyId < 1)
{
return BadRequest("Invalid Property Id");
}

try
{
var result = await _blProperties.ChangePropertyStatus(requestModel);
return Ok(result);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}

}

[HttpDelete("{propertyId}")]
public async Task<IActionResult> DeleteProperty(int propertyId)
{
Expand Down
12 changes: 6 additions & 6 deletions REMS.BackendApi/Features/Review/ReviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task<IActionResult> GetReview()
}
catch (Exception ex)
{
return BadRequest(ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}

Expand Down Expand Up @@ -49,12 +49,12 @@ public async Task<IActionResult> GetReviewById(int reviewId)
}
catch (Exception ex)
{
return BadRequest(ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}

[HttpPost]
public async Task<IActionResult> CreateReview(ReviewModel requestModel)
public async Task<IActionResult> CreateReview(ReviewRequestModel requestModel)
{
try
{
Expand All @@ -68,7 +68,7 @@ public async Task<IActionResult> CreateReview(ReviewModel requestModel)
}

[HttpPatch("{id}")]
public async Task<IActionResult> Update(int id, ReviewModel requestModel)
public async Task<IActionResult> Update(int id, ReviewRequestModel requestModel)
{
try
{
Expand All @@ -77,7 +77,7 @@ public async Task<IActionResult> Update(int id, ReviewModel requestModel)
}
catch (Exception ex)
{
return BadRequest(ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}

Expand All @@ -91,7 +91,7 @@ public async Task<IActionResult> Delete(int id)
}
catch (Exception ex)
{
return BadRequest(ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}
}
30 changes: 6 additions & 24 deletions REMS.BackendApi/Features/Transaction/TransactionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public async Task<IActionResult> GetTransactionsByPropertyId(int pageNumber, int
}
}

[HttpPost("GetTransactionsByPropertyIdAndAgentId/{pageNumber}/{pageSize}/{propertyId}/{agentId}")]
public async Task<IActionResult> GetTransactionsByPropertyIdAndAgentId(int pageNumber, int pageSize, int propertyId, int agentId)
[HttpPost("GetTransactionsByPropertyIdAndClientId/{clientId}/{propertyId}/{pageNumber}/{pageSize}")]
public async Task<IActionResult> GetTransactionsByPropertyIdAndClientId(int pageNumber, int pageSize, int propertyId, int clientId)
{
try
{
var response = await _blTransaction.GetTransactionsByPropertyIdAndAgentIdAsync(pageNumber, pageSize, propertyId, agentId);
var response = await _blTransaction.GetTransactionsByPropertyIdAndClientIdAsync(pageNumber, pageSize, propertyId, clientId);
if (response.IsError)
{
return BadRequest(response);
Expand All @@ -83,30 +83,12 @@ public async Task<IActionResult> GetTransactionsByPropertyIdAndAgentId(int pageN
}
}

[HttpPost("GetTransactionsByPropertyIdAndBuyerId/{buyerId}/{propertyId}/{pageNumber}/{pageSize}")]
public async Task<IActionResult> GetTransactionsByPropertyIdAndBuyerId(int pageNumber, int pageSize, int propertyId, int buyerId)
[HttpPost("GetTransactionsByClientId/{clientId}/{pageNumber}/{pageSize}")]
public async Task<IActionResult> GetTransactionsByClientId(int pageNumber, int pageSize, int clientId)
{
try
{
var response = await _blTransaction.GetTransactionsByPropertyIdAndBuyerIdAsync(pageNumber, pageSize, propertyId, buyerId);
if (response.IsError)
{
return BadRequest(response);
}
return Ok(response);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}

[HttpGet("GetTransactionsByPropertyIdAndSellerId/{pageNumber}/{pageSize}/{propertyId}/{sellerId}")]
public async Task<IActionResult> GetTransactionsByPropertyIdAndSellerId(int pageNumber, int pageSize, int propertyId, int sellerId)
{
try
{
var response = await _blTransaction.GetTransactionsByPropertyIdAndSellerIdAsync(pageNumber, pageSize, propertyId, sellerId);
var response = await _blTransaction.GetTransactionsByClientIdAsync(pageNumber, pageSize, clientId);
if (response.IsError)
{
return BadRequest(response);
Expand Down
1 change: 1 addition & 0 deletions REMS.BackendApi/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
global using REMS.Models.Review;
global using REMS.Models.Appointment;
global using REMS.Models.Authentication;
global using REMS.Models.Jwt;
global using REMS.Models.Transaction;
global using REMS.Modules.Features.Agent;
global using REMS.Modules.Features.Client;
Expand Down
1 change: 1 addition & 0 deletions REMS.BackendApi/ModularService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using REMS.Modules.Features.Authentication;
using REMS.Shared;

namespace REMS.BackendApi;
Expand Down
22 changes: 20 additions & 2 deletions REMS.BackendApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
var builder = WebApplication.CreateBuilder(args);

using REMS.Models.Jwt;
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins",
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});

var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<AppSettings>(builder.Configuration.GetSection("AppSettings"));

builder.Services.AddControllers();
builder
Expand All @@ -14,6 +24,9 @@
builder.Services.Configure<JwtTokenModel>(builder.Configuration.GetSection("Jwt"));

var app = builder.Build();

var appSettings = builder.Configuration.GetSection("AppSettings").Get<AppSettings>();

//if (app.Environment.IsDevelopment())
//{
// app.UseSwagger();
Expand All @@ -25,9 +38,14 @@

app.UseHttpsRedirection();
app.UseRouting();

app.UseCors("AllowAllOrigins");

app.UseAuthentication();
app.UseAuthorization();

//app.Urls.Add($"http://localhost:{appSettings.Port}");

app.MapControllers();

app.Run();
3 changes: 3 additions & 0 deletions REMS.BackendApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"Issuer": "REMS",
"Audience": "REMS",
"Key": "SU57Ie4vseXyJeUUSL6y8Z1QMFRMb2ZN"
},
"AppSettings": {
"Port": 8000
}
}
20 changes: 10 additions & 10 deletions REMS.Database/AppDbContextModels/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Agent>(entity =>
{
entity.HasKey(e => e.AgentId).HasName("PK__Agents__2C05379EA6EBB571");
entity.HasKey(e => e.AgentId).HasName("PK__Agents__2C05379E031C7552");

entity.Property(e => e.AgentId).HasColumnName("agent_id");
entity.Property(e => e.Address)
Expand All @@ -60,7 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Appointment>(entity =>
{
entity.HasKey(e => e.AppointmentId).HasName("PK__Appointm__A50828FC24A54744");
entity.HasKey(e => e.AppointmentId).HasName("PK__Appointm__A50828FC11F5BF47");

entity.Property(e => e.AppointmentId).HasColumnName("appointment_id");
entity.Property(e => e.AppointmentDate)
Expand All @@ -85,7 +85,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Client>(entity =>
{
entity.HasKey(e => e.ClientId).HasName("PK__Clients__BF21A4249CF6CCE3");
entity.HasKey(e => e.ClientId).HasName("PK__Clients__BF21A424084C6F3F");

entity.Property(e => e.ClientId).HasColumnName("client_id");
entity.Property(e => e.Address)
Expand Down Expand Up @@ -128,7 +128,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Message>(entity =>
{
entity.HasKey(e => e.MessageId).HasName("PK__Messages__0BBF6EE6D6430682");
entity.HasKey(e => e.MessageId).HasName("PK__Messages__0BBF6EE6030CF454");

entity.Property(e => e.MessageId).HasColumnName("message_id");
entity.Property(e => e.DateSent)
Expand Down Expand Up @@ -158,7 +158,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Property>(entity =>
{
entity.HasKey(e => e.PropertyId).HasName("PK__Properti__735BA463E2519AE2");
entity.HasKey(e => e.PropertyId).HasName("PK__Properti__735BA46382020C5F");

entity.Property(e => e.PropertyId).HasColumnName("property_id");
entity.Property(e => e.Adddate)
Expand Down Expand Up @@ -213,7 +213,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<PropertyImage>(entity =>
{
entity.HasKey(e => e.ImageId).HasName("PK__Property__DC9AC955F55B85D2");
entity.HasKey(e => e.ImageId).HasName("PK__Property__DC9AC9559298D349");

entity.Property(e => e.ImageId).HasColumnName("image_id");
entity.Property(e => e.DateUploaded)
Expand All @@ -233,7 +233,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Review>(entity =>
{
entity.HasKey(e => e.ReviewId).HasName("PK__Reviews__60883D902BBAE4A3");
entity.HasKey(e => e.ReviewId).HasName("PK__Reviews__60883D9094BA37F0");

entity.Property(e => e.ReviewId).HasColumnName("review_id");
entity.Property(e => e.Comments).HasColumnName("comments");
Expand All @@ -256,7 +256,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Transaction>(entity =>
{
entity.HasKey(e => e.TransactionId).HasName("PK__Transact__85C600AFF7042CF1");
entity.HasKey(e => e.TransactionId).HasName("PK__Transact__85C600AF52FA1EC6");

entity.Property(e => e.TransactionId).HasColumnName("transaction_id");
entity.Property(e => e.ClientId).HasColumnName("client_id");
Expand Down Expand Up @@ -287,9 +287,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<User>(entity =>
{
entity.HasKey(e => e.UserId).HasName("PK__Users__B9BE370FBAC9D2EE");
entity.HasKey(e => e.UserId).HasName("PK__Users__B9BE370F8DDB2A90");

entity.HasIndex(e => e.Email, "UQ__Users__AB6E6164B090FACB").IsUnique();
entity.HasIndex(e => e.Email, "UQ__Users__AB6E61643D1F7791").IsUnique();

entity.Property(e => e.UserId).HasColumnName("user_id");
entity.Property(e => e.DateCreated)
Expand Down
Loading

0 comments on commit 3b547ec

Please sign in to comment.