Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
LinThitHtwe authored Aug 9, 2024
2 parents de5f8a7 + 0400b58 commit 7690c55
Show file tree
Hide file tree
Showing 26 changed files with 344 additions and 129 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; }
}
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
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());
}
}
}
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
11 changes: 4 additions & 7 deletions REMS.Mapper/ChangeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static Client Change(this ClientRequestModel requestModel)
return client;
}

public static ClientModel Change(this Client dataModel)
public static ClientModel Change(this Client dataModel, User user)
{
var clientResponseModel = new ClientModel
{
Expand All @@ -88,6 +88,8 @@ public static ClientModel Change(this Client dataModel)
FirstName = dataModel.FirstName,
LastName = dataModel.LastName,
Address = dataModel.Address,
Email = user?.Email,
Phone = user?.Phone
};
return clientResponseModel;
}
Expand Down Expand Up @@ -139,10 +141,8 @@ public static Property Change(this PropertyRequestModel requestModel)
NumberOfBathrooms = requestModel.NumberOfBathrooms,
YearBuilt = requestModel.YearBuilt,
Description = requestModel.Description,
Status = requestModel.Status,
AvailiablityType = requestModel.AvailiablityType,
MinrentalPeriod = requestModel.MinRentalPeriod,
Approvedby = requestModel.ApprovedBy,
};

return property;
Expand Down Expand Up @@ -213,22 +213,19 @@ public static ReviewModel Change(this Review dataModel)
PropertyId = dataModel.PropertyId,
Rating = dataModel.Rating,
Comments = dataModel.Comments,
DateCreated = dataModel.DateCreated
};

return reviewModel;
}

public static Review Change(this ReviewModel dataModel)
public static Review Change(this ReviewRequestModel dataModel)
{
var review = new Review()
{
ReviewId = dataModel.ReviewId,
UserId = dataModel.UserId,
PropertyId = dataModel.PropertyId,
Rating = dataModel.Rating,
Comments = dataModel.Comments,
DateCreated = dataModel.DateCreated
};

return review;
Expand Down
4 changes: 1 addition & 3 deletions REMS.Models/Authentication/SigninRequestModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
namespace REMS.Models.Authentication;

public record class SigninRequestModel(string Email, string Password);

public record class SigninResponseModel(string AccessToken, string Role);
public record class SigninRequestModel(string Email, string Password);
3 changes: 3 additions & 0 deletions REMS.Models/Authentication/SigninResponseModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace REMS.Models.Authentication;

public record class SigninResponseModel(string AccessToken, string Role);
12 changes: 8 additions & 4 deletions REMS.Models/Client/ClientRequestModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
namespace REMS.Models.Client;
using System.Text.Json.Serialization;

namespace REMS.Models.Client;

public class ClientRequestModel
{
[JsonIgnore] // Completely hides from API schema
public int? UserId { get; set; }

public string FirstName { get; set; } = null!;
public string? FirstName { get; set; } = null!;

public string LastName { get; set; } = null!;
public string? LastName { get; set; } = null!;

public string? Phone { get; set; }

public string? Email { get; set; }

public string Password { get; set; }
public string? Password { get; set; }

public string? Address { get; set; }

[JsonIgnore]
public DateTime DateCreate { get; set; } = DateTime.Now;
}
7 changes: 7 additions & 0 deletions REMS.Models/Property/PropertyImageRequestModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace REMS.Models.Property;

public class PropertyImageRequestModel
{
public string? ImgBase64 { get; set; }
public string? Description { get; set; }
}
Loading

0 comments on commit 7690c55

Please sign in to comment.