Fix Null Warnings (#874)
* Fixing null warnings * Fix null warnings Fix other compiler warnings
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.PublicApi.AuthEndpoints;
|
||||
namespace Microsoft.eShopWeb.PublicApi.AuthEndpoints;
|
||||
|
||||
public class ClaimValue
|
||||
{
|
||||
@@ -17,6 +12,6 @@ public class ClaimValue
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Type { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopWeb.PublicApi.AuthEndpoints;
|
||||
|
||||
@@ -9,7 +6,7 @@ public class UserInfo
|
||||
{
|
||||
public static readonly UserInfo Anonymous = new UserInfo();
|
||||
public bool IsAuthenticated { get; set; }
|
||||
public string NameClaimType { get; set; }
|
||||
public string RoleClaimType { get; set; }
|
||||
public IEnumerable<ClaimValue> Claims { get; set; }
|
||||
public string NameClaimType { get; set; } = string.Empty;
|
||||
public string RoleClaimType { get; set; } = string.Empty;
|
||||
public IEnumerable<ClaimValue> Claims { get; set; } = new List<ClaimValue>();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ public class AuthenticateEndpoint : EndpointBaseAsync
|
||||
OperationId = "auth.authenticate",
|
||||
Tags = new[] { "AuthEndpoints" })
|
||||
]
|
||||
public override async Task<ActionResult<AuthenticateResponse>> HandleAsync(AuthenticateRequest request, CancellationToken cancellationToken = default)
|
||||
public override async Task<ActionResult<AuthenticateResponse>> HandleAsync(AuthenticateRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = new AuthenticateResponse(request.CorrelationId());
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
public class ListPagedCatalogItemRequest : BaseRequest
|
||||
{
|
||||
public int? PageSize { get; init; }
|
||||
public int? PageIndex { get; init; }
|
||||
public int PageSize { get; init; }
|
||||
public int PageIndex { get; init; }
|
||||
public int? CatalogBrandId { get; init; }
|
||||
public int? CatalogTypeId { get; init; }
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ public class CatalogItemListPagedEndpoint : IEndpoint<IResult, ListPagedCatalogI
|
||||
int totalItems = await itemRepository.CountAsync(filterSpec);
|
||||
|
||||
var pagedSpec = new CatalogFilterPaginatedSpecification(
|
||||
skip: request.PageIndex.Value * request.PageSize.Value,
|
||||
take: request.PageSize.Value,
|
||||
skip: request.PageIndex * request.PageSize,
|
||||
take: request.PageSize,
|
||||
brandId: request.CatalogBrandId,
|
||||
typeId: request.CatalogTypeId);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class CatalogItemListPagedEndpoint : IEndpoint<IResult, ListPagedCatalogI
|
||||
|
||||
if (request.PageSize > 0)
|
||||
{
|
||||
response.PageCount = int.Parse(Math.Ceiling((decimal)totalItems / request.PageSize.Value).ToString());
|
||||
response.PageCount = int.Parse(Math.Ceiling((decimal)totalItems / request.PageSize).ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -39,6 +39,10 @@ public class UpdateCatalogItemEndpoint : IEndpoint<IResult, UpdateCatalogItemReq
|
||||
var response = new UpdateCatalogItemResponse(request.CorrelationId());
|
||||
|
||||
var existingItem = await itemRepository.GetByIdAsync(request.Id);
|
||||
if (existingItem == null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
CatalogItem.CatalogItemDetails details = new(request.Name, request.Description, request.Price);
|
||||
existingItem.UpdateDetails(details);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BlazorShared;
|
||||
using BlazorShared.Models;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
@@ -41,7 +40,8 @@ builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||
builder.Services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
|
||||
builder.Services.AddScoped(typeof(IReadRepository<>), typeof(EfRepository<>));
|
||||
builder.Services.Configure<CatalogSettings>(builder.Configuration);
|
||||
builder.Services.AddSingleton<IUriComposer>(new UriComposer(builder.Configuration.Get<CatalogSettings>()));
|
||||
var catalogSettings = builder.Configuration.Get<CatalogSettings>() ?? new CatalogSettings();
|
||||
builder.Services.AddSingleton<IUriComposer>(new UriComposer(catalogSettings));
|
||||
builder.Services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
|
||||
builder.Services.AddScoped<ITokenClaimsService, IdentityTokenClaimService>();
|
||||
|
||||
@@ -73,12 +73,12 @@ const string CORS_POLICY = "CorsPolicy";
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(name: CORS_POLICY,
|
||||
corsPolicyBuilder =>
|
||||
{
|
||||
corsPolicyBuilder.WithOrigins(baseUrlConfig.WebBase.Replace("host.docker.internal", "localhost").TrimEnd('/'));
|
||||
corsPolicyBuilder.AllowAnyMethod();
|
||||
corsPolicyBuilder.AllowAnyHeader();
|
||||
});
|
||||
corsPolicyBuilder =>
|
||||
{
|
||||
corsPolicyBuilder.WithOrigins(baseUrlConfig!.WebBase.Replace("host.docker.internal", "localhost").TrimEnd('/'));
|
||||
corsPolicyBuilder.AllowAnyMethod();
|
||||
corsPolicyBuilder.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
@@ -172,12 +172,9 @@ app.UseSwaggerUI(c =>
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
|
||||
});
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
|
||||
app.MapControllers();
|
||||
app.MapEndpoints();
|
||||
|
||||
app.Logger.LogInformation("LAUNCHING PublicApi");
|
||||
app.Run();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user