Skip to content

Commit

Permalink
Organized namespace between navigation, paging and alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtocode committed Jul 17, 2023
1 parent e6fc4c5 commit ca23049
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,9 @@ public class BusinessesController : BaseController
[HttpGet(Name = "GetBusinessesByNameQuery")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<PagedResult<BusinessEntity>> Get(string name, int pageNumber = 1, int pageSize = 20) => await Mediator.Send(new GetBusinessesByNameQuery
public async Task<PagedResult<BusinessEntity>> Get(string? name, int pageNumber = 1, int pageSize = 20) => await Mediator.Send(new GetBusinessesByNameQuery
{
BusinessName = name,
BusinessName = name ?? string.Empty,
PageNumber = pageNumber,
});

/// <summary> Get Businesses by Name</summary>
/// <remarks>
/// Sample request:
/// "businessName": "My Business"
/// "api-version": 1
/// </remarks>
/// <returns>Collection of BusinessEntity</returns>
[HttpGet(Name = "GetBusinessesAllQuery")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<PagedResult<BusinessEntity>> Get(int pageNumber, int pageSize) => await Mediator.Send(new GetBusinessesAllQuery
{
PageNumber = pageNumber,
PageSize = pageSize
});
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@using Goodtocode.Subjects.Alerts;
@using Microsoft.AspNetCore.Components.Routing;
@implements IDisposable
@inject IAlertService AlertService
@inject NavigationManager NavigationManager

@namespace Goodtocode.Subjects.Alerts

@foreach (var alert in alerts)
{
<div class="@CssClass(alert)">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Goodtocode.Subjects.Rcl;
namespace Goodtocode.Subjects.Alerts;

public class AlertModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Goodtocode.Subjects.Rcl;
namespace Goodtocode.Subjects.Alerts;

public interface IAlertService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Goodtocode.Subjects.Rcl;
namespace Goodtocode.Subjects.Alerts;

public enum AlertTypes
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@using Goodtocode.Common.Extensions;

@namespace Goodtocode.Subjects.Alerts

<div hidden="@string.IsNullOrEmpty(Message)" class="alert m-4 @alertClass" role="alert">@Message</div>

@code {
Expand Down
4 changes: 2 additions & 2 deletions src/Subjects/Presentation.Shared.Rcl/ExampleJsInterop.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.JSInterop;

namespace Goodtocode.Subjects.Rcl;
namespace Goodtocode.Subjects;

// This class provides an example of how JavaScript functionality can be wrapped
// in a .NET class for easy consumption. The associated JavaScript module is
Expand All @@ -16,7 +16,7 @@ public class ExampleJsInterop : IAsyncDisposable
public ExampleJsInterop(IJSRuntime jsRuntime)
{
moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>(
"import", "./_content/Presentation.Shared.Rcl/exampleJsInterop.js").AsTask());
"import", "./_content/Presentation.Shared/exampleJsInterop.js").AsTask());
}

public async ValueTask<string> Prompt(string message)
Expand Down
12 changes: 12 additions & 0 deletions src/Subjects/Presentation.Shared.Rcl/Navigation/BusinessRoutes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Goodtocode.Subjects.Navigation;

public struct BusinessRoutes
{
public const string BusinessList = "/businesses";
public const string BusinessSearch = "/businesses/search";
public const string BusinessDetails = "/businesses/details";
public const string BusinessCreate = "/businesses/create";
public const string BusinessEdit = "/businesses/edit";
public const string BusinessDelete = "/businesses/delete";
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Goodtocode.Subjects.Rcl;
namespace Goodtocode.Subjects.Paging;

public class PageHistoryState
{
Expand Down
2 changes: 2 additions & 0 deletions src/Subjects/Presentation.Shared.Rcl/Paging/Pager.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@using Goodtocode.Common.Extensions;

@namespace Goodtocode.Subjects.Paging

@if (Result != null)
{
<div class="row">
Expand Down
3 changes: 2 additions & 1 deletion src/Subjects/Presentation.Web.BlazorServer/App.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<CascadingAuthenticationState>
@using Goodtocode.Subjects.BlazorServer.Shared;
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Goodtocode.Subjects.Domain;
using System.ComponentModel.DataAnnotations;

namespace Goodtocode.Subjects.BlazorServer.Models;
namespace Goodtocode.Subjects.Models;

public class BusinessModel : IBusinessEntity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentValidation;

namespace Goodtocode.Subjects.BlazorServer.Models;
namespace Goodtocode.Subjects.Models;

public class BusinessValidator : AbstractValidator<BusinessModel>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Goodtocode.Subjects.Domain;
using System.ComponentModel.DataAnnotations;

namespace Goodtocode.Subjects.BlazorServer.Models;
namespace Goodtocode.Subjects.Models;

public class SearchModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
@page "/business/create"
@using Goodtocode.Subjects.BlazorServer.Data;
@using Goodtocode.Subjects.BlazorServer.Models;
@using Goodtocode.Subjects.Alerts;
@using Goodtocode.Subjects.Data;
@using Goodtocode.Subjects.Domain;
@using Goodtocode.Subjects.Models;
@using System.ComponentModel.DataAnnotations;
@using Goodtocode.Subjects.Rcl.Alert
@using Goodtocode.Subjects.Rcl;

@inject BusinessService Service

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@using Goodtocode.Subjects.BlazorServer.Models;
@inject Goodtocode.Subjects.Rcl.PageHistoryState PageHistoryState
@using Goodtocode.Subjects.Models;
@using Goodtocode.Subjects.Paging;
@inject Goodtocode.Subjects.Paging.PageHistoryState PageHistoryState

<EditForm Model="@business" OnValidSubmit="@OnValidSubmit">
<FluentValidator TValidator="BusinessValidator" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
@page "/business"
@page "/business/{page:int}"
@page "/businesses/{page:int}"
@using Goodtocode.Common.Extensions;
@using Goodtocode.Subjects.BlazorServer.Data;
@using Goodtocode.Subjects.BlazorServer.Models;
@using Goodtocode.Subjects.Data;
@using Goodtocode.Subjects.Models;
@using Goodtocode.Subjects.Domain;
@using System.ComponentModel.DataAnnotations;
@using Goodtocode.Subjects.Rcl;
@using Goodtocode.Subjects.Rcl.Paging
@using Goodtocode.Subjects.Paging
@using Microsoft.AspNetCore.Http.Extensions;

@inject BusinessService Service
@inject PageHistoryState PageHistory
@inject NavigationManager UriHelper

<PageTitle>Business Search</PageTitle>
<PageTitle>Business List</PageTitle>

<EditForm Model="@SearchTerm" OnValidSubmit="@GetBusinessesAsync">
<DataAnnotationsValidator />
<div class="input-group mb-3">
<input type="text" class="form-control form-control-lg" placeholder="Search" aria-label="Search" aria-describedby="button-addon2"
@bind="@SearchTerm">
<button class="btn btn-primary btn-lg" type="submit" id="button-addon2"><i class="bi bi-search"></i></button>
</div>
<ValidationSummary />
<div hidden="@string.IsNullOrEmpty(alertMessage)" class="alert alert-danger" role="alert">@alertMessage</div>
<div hidden="@(!processing)" class="spinner-border text-primary center-screen" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</EditForm>
<div hidden="@string.IsNullOrEmpty(alertMessage)" class="alert alert-danger" role="alert">@alertMessage</div>
<div hidden="@(!processing)" class="spinner-border text-primary center-screen" role="status">
<span class="visually-hidden">Loading...</span>
</div>


@if (businesses.Results.Count() > 0)
Expand Down Expand Up @@ -115,7 +104,7 @@
{
processing = true;
await Task.Delay(500, cts.Token);
businesses = await Service.GetBusinessesAsync(page);
businesses = await Service.GetBusinessesAsync(businessSearch, page);
if (businesses.Results.Count() == 0)
alertMessage = "No businesses found";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@page "/business/search"
@page "/businesses/search"
@using Goodtocode.Common.Extensions;
@using Goodtocode.Subjects.BlazorServer.Data;
@using Goodtocode.Subjects.BlazorServer.Models;
@using Goodtocode.Subjects.Data;
@using Goodtocode.Subjects.Domain;
@using System.ComponentModel.DataAnnotations;
@using Goodtocode.Subjects.Rcl;
@using Goodtocode.Subjects.Models;
@using Goodtocode.Subjects.Paging;
@using Microsoft.AspNetCore.Http.Extensions;
@using System.ComponentModel.DataAnnotations;

@inject BusinessService Service
@inject PageHistoryState PageHistory
Expand Down Expand Up @@ -106,7 +106,7 @@
{
processing = true;
await Task.Delay(500, cts.Token);
businesses = await Service.GetBusinessesAsync(businessSearch.Name, Page);
businesses = await Service.GetBusinessesAsync(businessSearch, Page);
if (businesses.Results.Count() == 0)
alertMessage = "No businesses found";
}
Expand Down
5 changes: 3 additions & 2 deletions src/Subjects/Presentation.Web.BlazorServer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Azure.Identity;
using Goodtocode.Common.Infrastructure.ApiClient;
using Goodtocode.Subjects.BlazorServer.Data;
using Goodtocode.Subjects.Rcl;
using Goodtocode.Subjects.Alerts;
using Goodtocode.Subjects.Data;
using Goodtocode.Subjects.Paging;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Goodtocode.Common.Extensions;
using Goodtocode.Subjects.BlazorServer.Models;
using Goodtocode.Subjects.Models;
using Goodtocode.Subjects.Domain;
using Goodtocode.Subjects.Rcl;
using System.Net;
using System.Text.Json;

namespace Goodtocode.Subjects.BlazorServer.Data;
namespace Goodtocode.Subjects.Data;

public class BusinessService : IBusinessService
{
Expand All @@ -32,25 +31,11 @@ public async Task<BusinessModel> GetBusinessAsync(Guid businessKey)
return business;
}

public async Task<PagedResult<BusinessModel>> GetBusinessesAsync(int page)
public async Task<PagedResult<BusinessModel>> GetBusinessesAsync(SearchModel search, int page)
{
var business = new PagedResult<BusinessModel>();
var httpClient = _clientFactory.CreateClient("SubjectsApiClient");
var response = await httpClient.GetAsync($"{httpClient.BaseAddress}Businesses?pageNumber={page}&pageSize=20&api-version={apiVersion}");
if (response.StatusCode != HttpStatusCode.NotFound)
{
response.EnsureSuccessStatusCode();
business = JsonSerializer.Deserialize<PagedResult<BusinessModel>>(response.Content.ReadAsStream()) ?? throw new Exception("Deserialization failed.");
}

return business;
}

public async Task<PagedResult<BusinessModel>> GetBusinessesAsync(string name, int page)
{
var business = new PagedResult<BusinessModel>();
var httpClient = _clientFactory.CreateClient("SubjectsApiClient");
var response = await httpClient.GetAsync($"{httpClient.BaseAddress}Businesses?name={name}&pageNumber={page}&pageSize=20&api-version={apiVersion}");
var response = await httpClient.GetAsync($"{httpClient.BaseAddress}Businesses?name={search.Name}&pageNumber={page}&pageSize=20&api-version={apiVersion}");
if (response.StatusCode != HttpStatusCode.NotFound)
{
response.EnsureSuccessStatusCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Goodtocode.Common.Extensions;
using Goodtocode.Subjects.BlazorServer.Models;
using Goodtocode.Subjects.Models;

namespace Goodtocode.Subjects.BlazorServer.Data
namespace Goodtocode.Subjects.Data
{
public interface IBusinessService
{
Task<PagedResult<BusinessModel>> GetBusinessesAsync(string name, int page);
Task<PagedResult<BusinessModel>> GetBusinessesAsync(SearchModel search, int page);

Task<BusinessModel> GetBusinessAsync(Guid businessKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="business/search">
<NavLink class="nav-link" href="businesses/search">
<span class="oi oi-list-rich" aria-hidden="true"></span> Search
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="business/1">
<NavLink class="nav-link" href="businesses/1">
<span class="oi oi-list-rich" aria-hidden="true"></span> List
</NavLink>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/Subjects/Presentation.Web.BlazorServer/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@using Goodtocode.Subjects.BlazorServer
@using Goodtocode.Subjects.BlazorServer.Shared
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
Expand Down

0 comments on commit ca23049

Please sign in to comment.