Skip to content

Commit

Permalink
1.0.5-RC-1
Browse files Browse the repository at this point in the history
  • Loading branch information
NatanAmorim committed Dec 29, 2024
1 parent 0f94dcd commit 2da8eae
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 34 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ Todas as alterações notáveis ​​neste projeto serão documentadas neste ar
O formato é baseado em [Keep a Changelog (PT-BR)](https://keepachangelog.com/pt-BR/1.0.0/),
e este projeto adere a [Versionamento Semântico (PT-BR)](https://semver.org/lang/pt-BR/).

## 1.0.5-RC-1 (Dec 29, 2024)

- Add `AsNoTracking` AsNoTracking to improve query performance across multiple RPC services.
- Changes in `CustomerRpcService`
- Added query join to fetch customers including related `Person` and `Dependents` entities.
- Filtered customers based on `CustomerId` using `Ulid` parsed from the request cursor.
- Limited query results to 20 records, tracked without changes, and converted to a list asynchronously.

## 1.0.4-RC-7 (Jun 11, 2024)

- ID's are now required instead of having a default value to avoid some unintentional new ID problem.
- People Names are now indexed to make queries faster
- People "FullName" are now indexed but "MobilePhoneNumber" and "Cpf" are no longer indexed.

## 1.0.3-RC-7 (Jun 07, 2024)

Expand Down
5 changes: 3 additions & 2 deletions Services/AttendanceRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public override async Task<GetPaginatedAttendancesResponse> GetPaginatedAsync(Ge
}

List<GetAttendanceByIdResponse> Attendances = await Query
.Take(20)
.ToListAsync();
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedAttendancesResponse response = new();

Expand Down
77 changes: 48 additions & 29 deletions Services/CustomerRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public override async Task<GetPaginatedCustomersResponse> GetPaginatedAsync(GetP
List<GetCustomerByIdResponse> Customers =
await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedCustomersResponse response = new();
Expand Down Expand Up @@ -82,7 +83,13 @@ public override async Task<GetCustomerByIdResponse> GetByIdAsync(GetCustomerById
request.CustomerId
);

Customer? Customer = await _dbContext.Customers.FindAsync(request.CustomerId);
IQueryable<GetCustomerByIdResponse> Query = _dbContext.Customers
.Include(c => c.Person)
.Include(c => c.Dependents)
.Where(x => x.CustomerId == Ulid.Parse(request.CustomerId))
.Select(Customer => Customer.ToGetById());

GetCustomerByIdResponse? Customer = await Query.FirstOrDefaultAsync();

if (Customer is null)
{
Expand All @@ -102,8 +109,7 @@ public override async Task<GetCustomerByIdResponse> GetByIdAsync(GetCustomerById
typeof(Customer).Name
);

return Customer.ToGetById();

return Customer;
}

public override async Task<VoidValue> PostAsync(CreateCustomerRequest request, ServerCallContext context)
Expand Down Expand Up @@ -133,7 +139,7 @@ public override async Task<VoidValue> PostAsync(CreateCustomerRequest request, S
return new VoidValue();
}

public override Task<VoidValue> PutAsync(UpdateCustomerRequest request, ServerCallContext context)
public override async Task<VoidValue> PutAsync(UpdateCustomerRequest request, ServerCallContext context)
{
string RequestTracerId = context.GetHttpContext().TraceIdentifier;
string UserId = context.GetHttpContext().User.FindFirstValue(ClaimTypes.NameIdentifier)!;
Expand All @@ -145,44 +151,56 @@ public override Task<VoidValue> PutAsync(UpdateCustomerRequest request, ServerCa
request.CustomerId
);

Customer? Customer = await _dbContext.Customers.FindAsync(Ulid.Parse(request.CustomerId))
?? throw new RpcException(new Status(
StatusCode.NotFound, $"registro não encontrado"
));

// Attach the entity to the context in the modified state
_dbContext.Customers.Attach(Customer);

Customer.Person = Models.Person.FromProtoRequest(
request.Person,
Customer.CreatedBy
);
Customer.BillingAddress = request.BillingAddress;
Customer.AdditionalInformation = request.AdditionalInformation;
/// TODO FIX right now it does not delete things removed from list
// Customer.Dependents =
// request.Dependents.Select(
// Dependent => new Models.Dependent
// {
// DependentId = Ulid.Parse(Dependent.DependentId),
// FullName = Dependent.Name,
// BirthDate = Dependent.BirthDate,
// CreatedBy = Customer.CreatedBy,
// }
// ).ToList();

await _dbContext.SaveChangesAsync();

_logger.LogInformation(
"({TraceIdentifier}) record ({RecordType}) updated successfully",
RequestTracerId,
typeof(Customer).Name
);

throw new NotImplementedException();

// TODO
// CustomerModel? Customer = await _dbContext.Customers.FirstOrDefaultAsync(x => x.Id == request.Id);
// if (Customer is null)
// {
// throw new RpcException(new Status(
// StatusCode.NotFound, $"registro não encontrado"
// ));
// }

// Customer.Name = request.Name;
// // TODO Add Another fields

// await _dbContext.SaveChangesAsync();
// // TODO Log => Record (record type) ID Y was updated. Old value of (field name): (old value). New value: (new value). (This logs specific changes made to a field within a record)
// return new UpdateCustomerResponse();
return new VoidValue();
}

public override async Task<VoidValue> DeleteAsync(DeleteCustomerRequest request, ServerCallContext context)
{
string RequestTracerId = context.GetHttpContext().TraceIdentifier;
string UserId = context.GetHttpContext().User.FindFirstValue(ClaimTypes.NameIdentifier)!;
_logger.LogInformation(
"({TraceIdentifier}) User {UserID} deleting record ({RecordType}) with ID ({RecordId})",
RequestTracerId,
UserId,
typeof(Customer).Name,
request.CustomerId
);
"({TraceIdentifier}) User {UserID} deleting record ({RecordType}) with ID ({RecordId})",
RequestTracerId,
UserId,
typeof(Customer).Name,
request.CustomerId
);

Customer? Customer = await _dbContext.Customers.FindAsync(request.CustomerId);
Customer? Customer = await _dbContext.Customers.FindAsync(Ulid.Parse(request.CustomerId));

if (Customer is null)
{
Expand All @@ -197,7 +215,8 @@ public override async Task<VoidValue> DeleteAsync(DeleteCustomerRequest request,
));
}

/// TODO check if record is being used before deleting it use something like PK or FK
/// TODO check if record is being used before deleting it use something like PK or FK.
/// TODO check if every related table in the DB is deleted.

_dbContext.Customers.Remove(Customer);
await _dbContext.SaveChangesAsync();
Expand Down
5 changes: 3 additions & 2 deletions Services/DisciplineRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public override async Task<GetPaginatedDisciplinesResponse> GetPaginatedAsync(Ge
}

List<GetDisciplineByIdResponse> Disciplines = await Query
.Take(20)
.ToListAsync();
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedDisciplinesResponse response = new();

Expand Down
1 change: 1 addition & 0 deletions Services/InstructorRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedInstructorsResponse> GetPaginatedAsync(Ge

List<GetInstructorByIdResponse> Instructors = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedInstructorsResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/NotificationRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedNotificationsResponse> GetPaginatedAsync(

List<GetNotificationByIdResponse> Notifications = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedNotificationsResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/OrderRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public override async Task<GetPaginatedOrdersResponse> GetPaginatedAsync(GetPagi

List<GetOrderByIdResponse> Orders = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedOrdersResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/PaymentRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedPaymentsResponse> GetPaginatedAsync(GetPa

List<GetPaymentByIdResponse> Payments = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedPaymentsResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/PromotionRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedPromotionsResponse> GetPaginatedAsync(Get

List<GetPromotionByIdResponse> Promotions = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedPromotionsResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/ReturnRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public override async Task<GetPaginatedReturnsResponse> GetPaginatedAsync(GetPag

List<GetReturnByIdResponse> Returns = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedReturnsResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/SaleBillingRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedSaleBillingsResponse> GetPaginatedAsync(G

List<GetSaleBillingByIdResponse> SaleBillings = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedSaleBillingsResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/SaleRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedSalesResponse> GetPaginatedAsync(GetPagin

List<GetSaleByIdResponse> Sales = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedSalesResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/SubscriptionBillingRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedSubscriptionBillingsResponse> GetPaginate

List<GetSubscriptionBillingByIdResponse> SubscriptionBillings = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedSubscriptionBillingsResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/SubscriptionRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedSubscriptionsResponse> GetPaginatedAsync(

List<GetSubscriptionByIdResponse> Subscriptions = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedSubscriptionsResponse response = new();
Expand Down
1 change: 1 addition & 0 deletions Services/UserRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override async Task<GetPaginatedUsersResponse> GetPaginatedAsync(GetPagin

List<GetUserByIdResponse> Users = await Query
.Take(20)
.AsNoTracking()
.ToListAsync();

GetPaginatedUsersResponse response = new();
Expand Down

0 comments on commit 2da8eae

Please sign in to comment.