Skip to content

Commit

Permalink
Order Details
Browse files Browse the repository at this point in the history
  • Loading branch information
Manish Kumar committed Nov 5, 2024
1 parent 97bd31e commit 5997869
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 6 deletions.
28 changes: 28 additions & 0 deletions Duc.Splitt/Duc.Splitt.Common/Dtos/Requests/OrderRequestDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Duc.Splitt.Common.Enums;

namespace Duc.Splitt.Common.Dtos.Requests
{
public class OrderRequestDto
{
public class CreateOrderRequestDto
{
public Guid CustomerId { get; set; }
public Guid MerchantId { get; set; }



public List<CreaterOrderItemDto>? OrderItems { get; set; }
}
public class CreaterOrderItemDto
{
}



public class GetOrderRequestDetailsDto
{
public Guid? OrderId { get; set; }
public Guid? CustomerId { get; set; }
}
}
}
31 changes: 31 additions & 0 deletions Duc.Splitt/Duc.Splitt.Common/Dtos/Responses/OrderResponseDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Duc.Splitt.Common.Dtos.Requests;

namespace Duc.Splitt.Common.Dtos.Responses
{
public class OrderResponseDto
{


public class CreaterOrderResponseDto
{
public bool? IsSucess { get; set; }
public Guid? OrderId { get; set; }
public Guid? CustomerId { get; set; }
}

public class GetOrderDetailstResponseDto
{
public Guid CustomerId { get; set; }
public Guid MerchantId { get; set; }



public List<GetOrderItemDto>? OrderItems { get; set; }
}
public class GetOrderItemDto
{
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
using Duc.Splitt.Core.Helper;
using System.Threading.Tasks;
using static Duc.Splitt.Common.Dtos.Requests.MerchantRequestDto;
using static Duc.Splitt.Common.Dtos.Requests.OrderRequestDto;
using static Duc.Splitt.Common.Dtos.Responses.MerchantDto;
using static Duc.Splitt.Common.Dtos.Responses.OrderResponseDto;

namespace Duc.Splitt.Core.Contracts.Services
{
public interface IOrderService
{

Task<ResponseDto<CreateMerchantResponseDto>> PostMerchant(RequestHeader requestHeader, CreaterMerchantRequestDto merchant);

Task<ResponseDto<CreaterOrderResponseDto?>> PostOrder(RequestHeader requestHeader, CreateOrderRequestDto requestDto);
Task<ResponseDto<GetOrderDetailstResponseDto?>> GetOrderById(RequestHeader requestHeader, GetOrderRequestDetailsDto requestDto);

}
}
88 changes: 88 additions & 0 deletions Duc.Splitt/Duc.Splitt.CustomerApi/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Duc.Splitt.CustomerApi.Helper;
using Duc.Splitt.Common.Dtos.Responses;
using Duc.Splitt.Common.Enums;
using Duc.Splitt.Core.Contracts.Services;
using Duc.Splitt.Logger;
using Microsoft.AspNetCore.Mvc;
using Azure.Core;
using static System.Runtime.InteropServices.JavaScript.JSType;
using static Duc.Splitt.Common.Dtos.Requests.OrderRequestDto;
using static Duc.Splitt.Common.Dtos.Responses.OrderResponseDto;

namespace Duc.Splitt.CustomerApi.Controllers
{

public class OrderController : BaseAnonymous
{
private readonly IOrderService _orderService;
private readonly ILoggerService _logger;
private IUtilsService _utilsService;
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public OrderController(IOrderService orderService, ILoggerService logger, IUtilsService utilsService)
{
_orderService = orderService;
_logger = logger;
_utilsService = utilsService;
}


[HttpPost()]
public async Task<ResponseDto<CreaterOrderResponseDto?>> PostOrder(CreateOrderRequestDto requestDto)
{
ResponseDto<CreaterOrderResponseDto?> response = new ResponseDto<CreaterOrderResponseDto?>
{
Code = ResponseStatusCode.NoDataFound
};

try
{
var validateRequest = await _utilsService.ValidateRequest(this.Request, null);
if (validateRequest == null)
{
response.Code = ResponseStatusCode.InvalidToken;
return response;
}
var obj = await _orderService.PostOrder(validateRequest, requestDto);
return obj;
}
catch (Exception ex)
{
_logger.LogError(ex);
response.Code = ResponseStatusCode.ServerError;
response.Errors = _logger.ConvertExceptionToStringList(ex);
return response;
}
}

[HttpPost()]
public async Task<ResponseDto<GetOrderDetailstResponseDto?>> GetOrderById(GetOrderRequestDetailsDto requestDto)
{
ResponseDto<GetOrderDetailstResponseDto?> response = new ResponseDto<GetOrderDetailstResponseDto?>
{
Code = ResponseStatusCode.NoDataFound
};

try
{
var validateRequest = await _utilsService.ValidateRequest(this.Request, null);
if (validateRequest == null)
{
response.Code = ResponseStatusCode.InvalidToken;
return response;
}
var obj = await _orderService.GetOrderById(validateRequest, requestDto);
return obj;
}
catch (Exception ex)
{
_logger.LogError(ex);
response.Code = ResponseStatusCode.ServerError;
response.Errors = _logger.ConvertExceptionToStringList(ex);
return response;
}
}

}
}


27 changes: 23 additions & 4 deletions Duc.Splitt/Duc.Splitt.Service/OrderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
using System.Data;
using static Duc.Splitt.Common.Dtos.Requests.AuthMerchantUserDto;
using static Duc.Splitt.Common.Dtos.Requests.MerchantRequestDto;
using static Duc.Splitt.Common.Dtos.Requests.OrderRequestDto;
using static Duc.Splitt.Common.Dtos.Responses.MerchantDto;
using static Duc.Splitt.Common.Dtos.Responses.OrderResponseDto;

namespace Duc.Splitt.Service
{
Expand All @@ -26,18 +28,35 @@ public OrderService(IUnitOfWork unitOfWork, IDapperDBConnection dapperDBConnecti
_dapperDBConnection = dapperDBConnection;
}

public async Task<ResponseDto<CreateMerchantResponseDto?>> PostMerchant(RequestHeader requestHeader, CreaterMerchantRequestDto requestDto)
public async Task<ResponseDto<CreaterOrderResponseDto?>> PostOrder(RequestHeader requestHeader, CreateOrderRequestDto requestDto)
{

ResponseDto<CreateMerchantResponseDto?> response = new ResponseDto<CreateMerchantResponseDto?>
Order order = new Order { };
_unitOfWork.Orders.AddAsync(order);
await _unitOfWork.CompleteAsync();
ResponseDto<CreaterOrderResponseDto?> response = new ResponseDto<CreaterOrderResponseDto?>
{
Code = ResponseStatusCode.NoDataFound
};
response.Data = new CreateMerchantResponseDto { };

response.Data = null;
response.Code = ResponseStatusCode.Success;
return response;
}
public async Task<ResponseDto<GetOrderDetailstResponseDto?>> GetOrderById(RequestHeader requestHeader, GetOrderRequestDetailsDto requestDto)
{

Order order = new Order { };
_unitOfWork.Orders.AddAsync(order);
await _unitOfWork.CompleteAsync();
ResponseDto<GetOrderDetailstResponseDto?> response = new ResponseDto<GetOrderDetailstResponseDto?>
{
Code = ResponseStatusCode.NoDataFound
};

response.Data = null;
response.Code = ResponseStatusCode.Success;
return response;
}
}
}

0 comments on commit 5997869

Please sign in to comment.