Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor customers page #897

Merged
merged 9 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/adminpanel/Client/Models/CustomerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class CustomerModel : IEquatable<CustomerModel>
public string? ContactEmail { get; set; }
public string? ContactPhone { get; set; }
public string? OrgNr { get; set; }
public int? ProjectCount { get; set; }
public IList<ProjectModel>? Projects { get; set; }
public bool ShowDetails { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
ActionLabel="@Localizer["Common.NavigateTo"]"
OnActionPress="@(() => Navigation.NavigateTo($"/kunder/{customer.Id}"))"
CustomerName="@customer.Name"
ProjectCount="@customer.Projects?.Count"
ProjectCount="@customer.ProjectCount"
ContactPerson="@customer.ContactPerson">
</CustomerCard>
}
Expand Down Expand Up @@ -86,13 +86,6 @@
}
}

private bool FilterCustomer(CustomerModel customer)
{
if (string.IsNullOrWhiteSpace(_customerSearchString))
return true;
return customer.Name.Contains(_customerSearchString, StringComparison.OrdinalIgnoreCase) || customer.ContactEmail.Contains(_customerSearchString, StringComparison.OrdinalIgnoreCase) || customer.ContactPerson.Contains(_customerSearchString, StringComparison.OrdinalIgnoreCase);
}

private void AddEmptyCustomer()
{
DialogService.ShowAsync<CustomerDialog>(@Localizer["CustomersPage.AddCustomer"], new DialogParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class CustomerAdminDto
public string ContactEmail { get; set; }
public string ContactPhone { get; set; }
public string OrgNr { get; set; }
public int ProjectCount { get; set; }
public IEnumerable<ProjectAdminDto> Projects { get; set; }
}
4 changes: 2 additions & 2 deletions packages/api/AlvTime.Business/Customers/CustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public async Task<Result<CustomerAdminDto>> GetCustomerDetailedById(int customer
return (await _customerStorage.GetCustomerDetailedById(customerId));
}

public async Task<IEnumerable<CustomerAdminDto>> GetCustomersDetailed()
public async Task<IEnumerable<CustomerAdminDto>> GetCustomersAdmin()
{
var customers = await _customerStorage.GetCustomersDetailed();
var customers = await _customerStorage.GetCustomersAdmin();
return customers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface ICustomerStorage
{
Task<CustomerAdminDto> GetCustomerDetailedById(int customerId);
Task<IEnumerable<CustomerDto>> GetCustomers(CustomerQuerySearch criterias);
Task<IEnumerable<CustomerAdminDto>> GetCustomersDetailed();
Task<IEnumerable<CustomerAdminDto>> GetCustomersAdmin();
Task CreateCustomer(CustomerDto customer);
Task UpdateCustomer(CustomerDto customer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
await _context.SaveChangesAsync();
}

public async Task<CustomerAdminDto?> GetCustomerDetailedById(int customerId)

Check warning on line 40 in packages/api/AlvTime.Persistence/Repositories/CustomerStorage.cs

View workflow job for this annotation

GitHub Actions / build_and_test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
return await _context.Customer
.Where(c => c.Id == customerId)
Expand Down Expand Up @@ -101,15 +101,9 @@
}).ToListAsync();
}

public async Task<IEnumerable<CustomerAdminDto>> GetCustomersDetailed()
public async Task<IEnumerable<CustomerAdminDto>> GetCustomersAdmin()
{
return await _context.Customer
.Include(c => c.Project)
.ThenInclude(p => p.Task)
.ThenInclude(t => t.HourRate)
.Include(c => c.Project)
.ThenInclude(p => p.Task)
.ThenInclude(t => t.CompensationRate)
.Select(customer => new CustomerAdminDto
{
Id = customer.Id,
Expand All @@ -119,25 +113,7 @@
ContactEmail = customer.ContactEmail,
ContactPhone = customer.ContactPhone,
OrgNr = customer.OrgNr,
Projects = customer.Project.Select(p => new ProjectAdminDto
{
Id = p.Id,
Name = p.Name,
Tasks = p.Task.Select(t => new TaskAdminDto
{
Id = t.Id,
Name = t.Name,
CompensationRate = EnsureCompensationRate(t.CompensationRate),
Locked = t.Locked,
Imposed = t.Imposed,
HourRates = t.HourRate.Select(hr => new HourRateDto
{
Id = hr.Id,
Rate = hr.Rate,
FromDate = hr.FromDate
})
})
})
ProjectCount = customer.Project.Count
}).ToListAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using AlvTimeWebApi.Controllers.Utils;
using AlvTimeWebApi.ErrorHandling;
using AlvTimeWebApi.Requests;
using AlvTimeWebApi.Responses;
using AlvTimeWebApi.Responses.Admin;

namespace AlvTimeWebApi.Controllers.Admin;
Expand All @@ -28,10 +27,10 @@ public CustomerController(CustomerService customerService, ProjectService projec
}

[HttpGet("Customers")]
public async Task<ActionResult<IEnumerable<CustomerDetailedResponse>>> FetchCustomersDetailed()
public async Task<ActionResult<IEnumerable<CustomerDetailedResponse>>> FetchCustomersAdmin()
{
var customers = await _customerService.GetCustomersDetailed();
return Ok(customers.Select(c => c.MapToCustomerResponse()));
var customers = await _customerService.GetCustomersAdmin();
return Ok(customers.Select(c => c.MapToCustomerAdminResponse()));
}

[HttpPost("Customers")]
Expand Down
15 changes: 15 additions & 0 deletions packages/api/AlvTimeWebApi/Controllers/Utils/CustomerMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ public static CustomerDetailedResponse MapToCustomerResponse(this CustomerAdminD
})
};
}

public static CustomerDetailedResponse MapToCustomerAdminResponse(this CustomerAdminDto customer)
{
return new CustomerDetailedResponse
{
Id = customer.Id,
Name = customer.Name,
InvoiceAddress = customer.InvoiceAddress,
ContactPerson = customer.ContactPerson,
ContactEmail = customer.ContactEmail,
ContactPhone = customer.ContactPhone,
OrgNr = customer.OrgNr,
ProjectCount = customer.ProjectCount
};
}

public static CustomerDto MapToCustomerDto(this CustomerUpsertRequest customer, int? id)
{
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Burde denne renames til CustomerAdminResponse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutt et bedre navn.

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public class CustomerDetailedResponse
public string ContactEmail { get; set; }
public string ContactPhone { get; set; }
public string OrgNr { get; set; }

public int ProjectCount { get; set; }
public IEnumerable<ProjectAdminResponse> Projects { get; set; }
}
Loading