Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feature/added-linter
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Gogete <gogeterobert@yahoo.com>
  • Loading branch information
gogeterobert committed Jul 1, 2022
2 parents 42869de + 1df9ace commit 682e47a
Show file tree
Hide file tree
Showing 28 changed files with 92 additions and 84 deletions.
22 changes: 11 additions & 11 deletions src/Application/Channels/Commands/PatchChannelCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<Unit> Handle(PatchChannelCommand request, CancellationToken ca
return Unit.Value;
}

private void UpdateEnvironmentVariables(PatchChannelCommand request, Channel? channel)
private void UpdateEnvironmentVariables(PatchChannelCommand request, Channel channel)
{
var existingVariables = GetExistingEnvironmentVariables(request.ChannelId);

Expand All @@ -75,13 +75,13 @@ private void UpdateEnvironmentVariables(PatchChannelCommand request, Channel? ch

_context.EnvironmentVariables.AddRange(envVariablesToBeAdded);

if (existingVariables.Count > 0 && request.EnvironmentVariables.Value != null)
if (existingVariables.Count > 0 && request.EnvironmentVariables.Value is not null)
{
foreach (var environmentVariable in request.EnvironmentVariables.Value)
{
var updatedEnvVar = existingVariables.FirstOrDefault(v => v.Id == environmentVariable.Id);

if (updatedEnvVar == null)
if (updatedEnvVar is null)
{
continue;
}
Expand All @@ -107,15 +107,15 @@ private List<EnvironmentVariable> GetExistingEnvironmentVariables(Guid channelId
.ToList();
}

private static List<EnvironmentVariable> EnvironmentVariablesToBeAdded(List<UpdateEnvironmentVariableDto> environmentVariables, Channel channel)
private static List<EnvironmentVariable> EnvironmentVariablesToBeAdded(List<UpdateEnvironmentVariableDto>? environmentVariables, Channel channel)
{
if (environmentVariables == null)
if (environmentVariables is null)
{
return new List<EnvironmentVariable>();
}

var toBeAdded = new List<EnvironmentVariable>();
var newVariables = environmentVariables.Where(v => v.Id == null);
var newVariables = environmentVariables.Where(v => v.Id is null);

foreach (var environmentVariable in newVariables)
{
Expand All @@ -133,22 +133,22 @@ private static List<EnvironmentVariable> EnvironmentVariablesToBeAdded(List<Upda
}

private static List<EnvironmentVariable> EnvironmentVariablesToBeUpdated(List<EnvironmentVariable> existingVariables,
List<UpdateEnvironmentVariableDto> environmentVariables)
List<UpdateEnvironmentVariableDto>? environmentVariables)
{
if (environmentVariables == null)
if (environmentVariables is null)
{
return new List<EnvironmentVariable>();
}

var environmentVariablesIds = environmentVariables?.Select(v => v.Id);
var environmentVariablesIds = environmentVariables.Select(v => v.Id);

return existingVariables.Where(v => environmentVariablesIds.Contains(v.Id)).ToList();
}

private static List<EnvironmentVariable> EnvironmentVariablesToBeRemoved(List<EnvironmentVariable> existingVariables,
List<UpdateEnvironmentVariableDto> environmentVariables)
List<UpdateEnvironmentVariableDto>? environmentVariables)
{
if (environmentVariables == null)
if (environmentVariables is null)
{
environmentVariables = new List<UpdateEnvironmentVariableDto>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Task Handle(CreatedEvent<Channel> notification, CancellationToken cancell

_logger.LogInformation($"Hippo Domain Event: {notification.GetType().Name}");

if (channel.ActiveRevision != null)
if (channel.ActiveRevision is not null)
{
_logger.LogInformation($"{channel.App.Name}: Starting channel {channel.Name} at revision {channel.ActiveRevision.RevisionNumber}");
var envvars = channel.EnvironmentVariables.ToDictionary(
Expand Down
5 changes: 5 additions & 0 deletions src/Application/Channels/Queries/GetChannelQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public async Task<ChannelItem> Handle(GetChannelQuery request, CancellationToken
.Select(a => a.ToAppSummaryDto())
.FirstOrDefaultAsync(cancellationToken);

if (entity.ActiveRevision is not null)
{
entity.ActiveRevision.Type = entity.ActiveRevision.Components.FirstOrDefault()?.Type;
}

return entity;
}
}
4 changes: 2 additions & 2 deletions src/Application/Common/Extensions/IgnoreNoMapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public static IMappingExpression IgnoreMarkedAttributes(
foreach (var property in destinationType.GetProperties())
{
PropertyDescriptor? descriptor = TypeDescriptor.GetProperties(destinationType)?[property.Name];
if (descriptor == null || descriptor.Attributes == null)
if (descriptor is null || descriptor.Attributes is null)
continue;

var attribute = descriptor.Attributes[typeof(NoMapAttribute)];
if (attribute != null && (NoMapAttribute)attribute != null)
if (attribute is not null && (NoMapAttribute)attribute is not null)
{
expression.ForMember(property.Name, opt => opt.Ignore());
}
Expand Down
6 changes: 3 additions & 3 deletions src/Application/JobStatuses/Queries/GetJobStatusesQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ public async Task<Page<ChannelJobStatusItem>> Handle(GetJobStatusesQuery request
Items = entities,
PageIndex = request.PageIndex,
PageSize = request.PageSize,
TotalItems = jobs == null ? 0 : jobs.Count
TotalItems = jobs is null ? 0 : jobs.Count
};
}

private static JobStatus GetJobStatus(List<Job>? jobs, Guid jobId)
{
if (jobs == null)
if (jobs is null)
{
return JobStatus.Unknown;
}

var job = jobs.Where(job => job.Id == jobId).FirstOrDefault();

return job != null ? job.Status : JobStatus.Dead;
return job is not null ? job.Status : JobStatus.Dead;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<Unit> Handle(UpdateRevisionDetailsCommand request, Cancellatio
.SingleOrDefaultAsync(cancellationToken);
_ = revision ?? throw new NotFoundException(nameof(Core.Entities.Revision), request.RevisionId);
var revisionDetails = request.RevisionDetails;
if (revisionDetails == null || revisionDetails.SpinToml == null)
if (revisionDetails is null || revisionDetails.SpinToml is null)
{
return Unit.Value;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Application/Revisions/Queries/RevisionItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Hippo.Application.Common.Attributes;
using Hippo.Application.Common.Mappings;
using Hippo.Core.Entities;

Expand All @@ -18,6 +19,9 @@ public class RevisionItem : IMapFrom<Revision>
[Required]
public IList<RevisionComponentDto> Components { get; private set; } = new List<RevisionComponentDto>();

[NoMap]
public string? Type { get; set; }

public string OrderKey()
{
if (SemVer.Version.TryParse(RevisionNumber, out var version))
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Models/Extensions/FieldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class FieldExtensions
{
public static bool IsSet<T>(this Field<T> field)
{
return field != null;
return field is not null;
}

public static void WhenSet<T>(this Field<T> field, Action<T> action)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Models/Extensions/FilteringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static IEnumerable<T> SortBy<T>(this IEnumerable<T> items, string sortBy,
IOrderedEnumerable<T> orderedItems;
var sortPropInfo = typeof(T).GetProperty(sortBy);

if (sortPropInfo == null)
if (sortPropInfo is null)
{
throw new Exception("Sort field does it exist");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Models/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PageAndSortFilter : IPageFilter, ISortFilter
public int PageIndex { get; set; }
public int PageSize { get; set; }
public int Offset { get { return PageIndex * PageSize; } }
public string SortBy { get; set; }
public string SortBy { get; set; } = string.Empty;
public bool IsSortedAscending { get; set; }

public PageAndSortFilter()
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Models/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Page(IReadOnlyCollection<TModel> items, int totalItems)
/// <summary>
/// the fetched items
/// </summary>
public IReadOnlyCollection<TModel> Items { get; set; }
public IReadOnlyCollection<TModel> Items { get; set; } = new List<TModel>();

/// <summary>
/// the total number of items for the requested query
Expand All @@ -38,7 +38,7 @@ public bool? IsLastPage
{
if (!PageIndex.HasValue || !PageSize.HasValue)
return null;

return TotalItems == PageIndex * PageSize + Items.Count;
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/Core/Serialization/FieldConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,36 @@ public override bool CanConvert(Type objectType)
throw new NotImplementedException();
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
var fieldInnerPropertyType = objectType
.GetProperty(nameof(Field<string>.Value))
.GetProperty(nameof(Field<string>.Value))?
.PropertyType;
var jsonValue = ReadInnerFieldValue(reader, serializer, fieldInnerPropertyType);

return Activator.CreateInstance(objectType, new[] { jsonValue });
}

private static object ReadInnerFieldValue(JsonReader reader, JsonSerializer serializer, Type fieldInnerPropertyType)
private static object? ReadInnerFieldValue(JsonReader reader, JsonSerializer serializer, Type? fieldInnerPropertyType)
{
if (reader.TokenType == JsonToken.Null)
if (reader.TokenType == JsonToken.Null || fieldInnerPropertyType is null)
return null;

return serializer.Deserialize(reader, fieldInnerPropertyType);
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
var fieldInnerProperty = value
.GetType()
.GetProperty(nameof(Field<string>.Value));
object? val = null;
if (value is not null)
{
var fieldInnerProperty = value
.GetType()
.GetProperty(nameof(Field<string>.Value));

val = fieldInnerProperty is null ? null : fieldInnerProperty.GetValue(value);
}

var fieldInnerValue = fieldInnerProperty.GetValue(value);
serializer.Serialize(writer, fieldInnerValue);
serializer.Serialize(writer, val);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextE

public void UpdateEntities(DbContext? context)
{
if (context == null) return;
if (context is null) return;

foreach (var entry in context.ChangeTracker.Entries<AuditableEntity>())
{
Expand All @@ -59,7 +59,7 @@ public static class Extensions
{
public static bool HasChangedOwnedEntities(this EntityEntry entry) =>
entry.References.Any(r =>
r.TargetEntry != null &&
r.TargetEntry is not null &&
r.TargetEntry.Metadata.IsOwned() &&
(r.TargetEntry.State == EntityState.Added || r.TargetEntry.State == EntityState.Modified));
}
2 changes: 1 addition & 1 deletion src/Infrastructure/Services/BindleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<IEnumerable<string>> QueryAvailableStorages(string query, ulon
if (matches.Total == 0)
return new List<string>();
return matches.Invoices
.Where(i => i.Bindle != null && !string.IsNullOrEmpty(i.Bindle.Name))
.Where(i => i.Bindle is not null && !string.IsNullOrEmpty(i.Bindle.Name))
.Select(i => new string(i.Bindle?.Name))
.Distinct()
.Take(limit ?? int.MaxValue);
Expand Down
19 changes: 14 additions & 5 deletions src/Infrastructure/Services/NomadJobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public string[] GetJobLogs(string jobName)
.Select(a => a.ID)
.FirstOrDefault();

if (allocationId == null)
if (allocationId is null)
{
return new string[] { };
}
Expand Down Expand Up @@ -149,12 +149,19 @@ private Service GenerateJobService(NomadJob nomadJob)
tags.Add("traefik.http.routers." + nomadJob.Id + @".tls.domains[0].main=" + nomadJob.Domain);
}

return new Service
var serviceProvider = _configuration.GetValue("Nomad:ServiceProvider", "consul");

var service = new Service
{
PortLabel = "http",
Name = nomadJob.Id.ToString(),
Tags = tags,
Checks = new List<ServiceCheck>
Provider = serviceProvider,
};

if (serviceProvider == "consul")
{
service.Checks = new List<ServiceCheck>
{
new ServiceCheck
{
Expand All @@ -163,8 +170,10 @@ private Service GenerateJobService(NomadJob nomadJob)
Interval = 10000000000,
Timeout = 2000000000
}
}
};
};

}
return service;
}

private Fermyon.Nomad.Model.Task GenerateJobTask(NomadJob nomadJob)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<div *ngIf="channel && channel.appSummary" class="is-flex is-flex-direction-row is-align-items-center is-justify-content-space-between mb-6">
<div>
<h1 class="is-size-1">{{channel.appSummary.name}}</h1>
<a href="{{protocol}}//{{channel.domain}}" target="_blank">{{channel.domain}}</a>
<div *ngIf="channel.activeRevision?.type === types.HTTP">
<a href="{{protocol}}//{{channel.domain}}" target="_blank">{{channel.domain}}</a>
</div>
<div *ngIf="channel.activeRevision?.type !== types.HTTP">
<p>{{channel.domain}}</p>
</div>
</div>
<div *ngIf="channel.appSummary.channels.length > 1 && activeTab !== tabs.Settings">
<div class="dropdown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChannelItem,
ChannelService,
} from 'src/app/core/api/v1';
import { ApplicationTabs, ComponentTypes } from 'src/app/_helpers/constants';
import { Component, OnInit } from '@angular/core';
import {
faAngleDown,
Expand All @@ -12,7 +13,6 @@ import {
faFilter,
faStream,
} from '@fortawesome/free-solid-svg-icons';
import { ApplicationTabs } from 'src/app/_helpers/constants';

@Component({
selector: 'app-channel',
Expand All @@ -26,6 +26,7 @@ export class ChannelComponent implements OnInit {
selectedChannel!: AppChannelListItem;
isSelectClicked = false;
tabs = ApplicationTabs;
types = ComponentTypes;
activeTab = ApplicationTabs.Overview;
protocol = window.location.protocol;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.4.0
6.0.0
7 changes: 2 additions & 5 deletions src/Web/ClientApp/src/app/core/api/v1/api/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@ export class AccountService {
);
} else if (value instanceof Date) {
if (key != null) {
httpParams = httpParams.append(
key,
(value as Date).toISOString().substr(0, 10)
);
httpParams = httpParams.append(key, (value as Date).toISOString().substr(0, 10));
} else {
throw Error('key may not be null if value is Date');
throw Error("key may not be null if value is Date");
}
} else {
Object.keys(value).forEach(
Expand Down
6 changes: 2 additions & 4 deletions src/Web/ClientApp/src/app/core/api/v1/api/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ export class AppService {
);
} else if (value instanceof Date) {
if (key != null) {
httpParams = httpParams.append(
key,
(value as Date).toISOString().substr(0, 10)
);
httpParams = httpParams.append(key, (value as Date).toISOString().substr(0, 10));
} else {
throw Error("key may not be null if value is Date");
throw Error('key may not be null if value is Date');
}
} else {
Expand Down
Loading

0 comments on commit 682e47a

Please sign in to comment.