Skip to content

Commit

Permalink
Fix - Refactoring fixes (#85)
Browse files Browse the repository at this point in the history
* refactor(repositories): Updated URL to /v1

* fix(UserController.cs): Added message to identify first setup

* fix(BaseResultCommand.cs): Fixed that you cannot map list without Paginated Result Command

* fix(login.component.ts): Added message to identify first setup

* fix(connectors.component.html): Changed delete button color

* fix(connector-function-repository.service.ts): Added connector id in query param
  • Loading branch information
jpcarpanezi authored Aug 8, 2023
1 parent 4df29b6 commit 8bc727c
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/Adapters/Houston.API/Controllers/V1/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public UserController(IDistributedCache cache, IMediator mediator) {
/// <response code="404">Initial configurations not found</response>
[HttpGet("isFirstSetup")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(MessageViewModel), (int)HttpStatusCode.NotFound)]
public async Task<IActionResult> IsFirstSetup() {
var configurations = await _cache.GetStringAsync("configurations");

if (configurations is null) {
return NotFound();
return NotFound(new MessageViewModel("First setup detected.", "firstSetup"));
}

return Ok();
Expand Down
33 changes: 17 additions & 16 deletions src/Core/Houston.Application/Results/BaseResultCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Houston.Application.Results {
using AutoMapper;
using static StackExchange.Redis.Role;

namespace Houston.Application.Results {
public abstract class BaseResultCommand<TEntity, TDto> : IResultCommand where TEntity : class where TDto : class {
public HttpStatusCode StatusCode { get; protected set; }

Expand Down Expand Up @@ -49,25 +52,23 @@ public virtual async Task ExecuteResultAsync(ActionContext context) {
StatusCode = (int)StatusCode
};

if (ResponseCustomBody is not null && ResponseErrorMessage is null) {
objectResult.Value = ResponseCustomBody;
Type responseType = GetType();

var config = new MapperConfiguration(cfg => cfg.AddProfile<MapProfile>());
var mapper = new Mapper(config);

if (responseType == typeof(ErrorResultCommand)) {
objectResult.Value = ResponseCustomBody is not null ? ResponseCustomBody : new MessageViewModel(ResponseErrorMessage, ResponseErrorCode);
}

if (ResponseErrorMessage is not null) {
objectResult.Value = new MessageViewModel(ResponseErrorMessage, ResponseErrorCode);
if (responseType == typeof(SuccessResultCommand<TEntity, TDto>)) {
var dto = mapper.Map<TDto>(ResponseEntity);
objectResult.Value = dto;
}

if (ResponseEntity is not null) {
var config = new MapperConfiguration(cfg => cfg.AddProfile<MapProfile>());
var mapper = new Mapper(config);

if (typeof(IEnumerable).IsAssignableFrom(typeof(TEntity))) {
var dto = mapper.Map<List<TDto>>(ResponseEntity);
objectResult.Value = new PaginatedItemsViewModel<TDto>(ResponsePageIndex, ResponsePageSize, ResponseCount, dto);
} else {
var dto = mapper.Map<TDto>(ResponseEntity);
objectResult.Value = dto;
}
if (responseType.IsGenericType && responseType.GetGenericTypeDefinition() == typeof(PaginatedResultCommand<,>)) {
var dto = mapper.Map<List<TDto>>(ResponseEntity);
objectResult.Value = new PaginatedItemsViewModel<TDto>(ResponsePageIndex, ResponsePageSize, ResponseCount, dto);
}

await objectResult.ExecuteResultAsync(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export class AuthRepositoryService implements AuthRepositoryInterface {
constructor(private http: HttpClient) { }

refreshToken(refreshToken: string): Observable<BearerTokenViewModel> {
return this.http.get<BearerTokenViewModel>(`${environment.apiUrl}/auth/${refreshToken}`);
return this.http.get<BearerTokenViewModel>(`${environment.apiUrl}/v1/auth/${refreshToken}`);
}

signIn(body: GeneralSignInCommand): Observable<BearerTokenViewModel> {
return this.http.post<BearerTokenViewModel>(`${environment.apiUrl}/auth`, body);
return this.http.post<BearerTokenViewModel>(`${environment.apiUrl}/v1/auth`, body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ export class ConnectorFunctionRepositoryService implements ConnectorFunctionRepo
) { }

update(body: UpdateConnectorFunctionCommand): Observable<ConnectorFunctionViewModel> {
return this.http.put<ConnectorFunctionViewModel>(`${environment.apiUrl}/connectorFunction`, body);
return this.http.put<ConnectorFunctionViewModel>(`${environment.apiUrl}/v1/connectorFunction`, body);
}

delete(connectorFunctionId: string): Observable<any> {
return this.http.delete<any>(`${environment.apiUrl}/connectorFunction/${connectorFunctionId}`)
return this.http.delete<any>(`${environment.apiUrl}/v1/connectorFunction/${connectorFunctionId}`)
}

get(connectorFunctionId: string): Observable<ConnectorFunctionViewModel> {
return this.http.get<ConnectorFunctionViewModel>(`${environment.apiUrl}/connectorFunction/item/${connectorFunctionId}`);
return this.http.get<ConnectorFunctionViewModel>(`${environment.apiUrl}/v1/connectorFunction/item/${connectorFunctionId}`);
}

create(body: CreateConnectorFunctionCommand): Observable<ConnectorFunctionViewModel> {
return this.http.post<ConnectorFunctionViewModel>(`${environment.apiUrl}/connectorFunction`, body);
return this.http.post<ConnectorFunctionViewModel>(`${environment.apiUrl}/v1/connectorFunction`, body);
}

getAll(connectorId: string, pageSize: number, pageIndex: number): Observable<PaginatedItemsViewModel<ConnectorFunctionViewModel>> {
return this.http.get<PaginatedItemsViewModel<ConnectorFunctionViewModel>>(`${environment.apiUrl}/connectorFunction/${connectorId}?pageSize=${pageSize}&pageIndex=${pageIndex}`);
return this.http.get<PaginatedItemsViewModel<ConnectorFunctionViewModel>>(`${environment.apiUrl}/v1/connectorFunction/${connectorId}?connectorId=${connectorId}&pageSize=${pageSize}&pageIndex=${pageIndex}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ export class ConnectorRepositoryService implements ConnectorRepositoryInterface
) { }

update(body: UpdateConnectorCommand): Observable<ConnectorViewModel> {
return this.http.put<ConnectorViewModel>(`${environment.apiUrl}/connector`, body);
return this.http.put<ConnectorViewModel>(`${environment.apiUrl}/v1/connector`, body);
}

delete(id: string): Observable<any> {
return this.http.delete<any>(`${environment.apiUrl}/connector/${id}`);
return this.http.delete<any>(`${environment.apiUrl}/v1/connector/${id}`);
}

create(body: CreateConnectorCommand): Observable<ConnectorViewModel> {
return this.http.post<ConnectorViewModel>(`${environment.apiUrl}/connector`, body);
return this.http.post<ConnectorViewModel>(`${environment.apiUrl}/v1/connector`, body);
}

getAll(pageSize: number, pageIndex: number): Observable<PaginatedItemsViewModel<ConnectorViewModel>> {
return this.http.get<PaginatedItemsViewModel<ConnectorViewModel>>(`${environment.apiUrl}/connector?pageSize=${pageSize}&pageIndex=${pageIndex}`);
return this.http.get<PaginatedItemsViewModel<ConnectorViewModel>>(`${environment.apiUrl}/v1/connector?pageSize=${pageSize}&pageIndex=${pageIndex}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class PipelineInstructionRepositoryService implements PipelineInstruction
) { }

save(body: SavePipelineInstructionCommand): Observable<PipelineInstructionViewModel> {
return this.http.post<PipelineInstructionViewModel>(`${environment.apiUrl}/pipelineInstruction`, body);
return this.http.post<PipelineInstructionViewModel>(`${environment.apiUrl}/v1/pipelineInstruction`, body);
}

get(pipelineId: string): Observable<PipelineInstructionViewModel[]> {
return this.http.get<PipelineInstructionViewModel[]>(`${environment.apiUrl}/pipelineInstruction/${pipelineId}`);
return this.http.get<PipelineInstructionViewModel[]>(`${environment.apiUrl}/v1/pipelineInstruction/${pipelineId}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class PipelineLogRepositoryService implements PipelineLogRepositoryInterf
) { }

get(id: string): Observable<PipelineLogViewModel> {
return this.http.get<PipelineLogViewModel>(`${environment.apiUrl}/pipelineLog/item/${id}`);
return this.http.get<PipelineLogViewModel>(`${environment.apiUrl}/v1/pipelineLog/item/${id}`);
}

getAll(pipelineId: string, pageSize: number, pageIndex: number): Observable<PaginatedItemsViewModel<PipelineLogViewModel>> {
return this.http.get<PaginatedItemsViewModel<PipelineLogViewModel>>(`${environment.apiUrl}/pipelineLog/${pipelineId}?pageSize=${pageSize}&pageIndex=${pageIndex}`);
return this.http.get<PaginatedItemsViewModel<PipelineLogViewModel>>(`${environment.apiUrl}/v1/pipelineLog/${pipelineId}?pageSize=${pageSize}&pageIndex=${pageIndex}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ export class PipelineRepositoryService implements PipelineRepositoryInterface {
) { }

create(body: CreatePipelineCommand): Observable<PipelineViewModel> {
return this.http.post<PipelineViewModel>(`${environment.apiUrl}/pipeline`, body);
return this.http.post<PipelineViewModel>(`${environment.apiUrl}/v1/pipeline`, body);
}

update(body: UpdatePipelineCommand): Observable<PipelineViewModel> {
return this.http.put<PipelineViewModel>(`${environment.apiUrl}/pipeline`, body);
return this.http.put<PipelineViewModel>(`${environment.apiUrl}/v1/pipeline`, body);
}

get(id: string): Observable<PipelineViewModel> {
return this.http.get<PipelineViewModel>(`${environment.apiUrl}/pipeline/${id}`);
return this.http.get<PipelineViewModel>(`${environment.apiUrl}/v1/pipeline/${id}`);
}

getAll(pageSize: number, pageIndex: number): Observable<PaginatedItemsViewModel<PipelineViewModel>> {
return this.http.get<PaginatedItemsViewModel<PipelineViewModel>>(`${environment.apiUrl}/pipeline?pageSize=${pageSize}&pageIndex=${pageIndex}`);
return this.http.get<PaginatedItemsViewModel<PipelineViewModel>>(`${environment.apiUrl}/v1/pipeline?pageSize=${pageSize}&pageIndex=${pageIndex}`);
}

delete(id: string): Observable<any> {
return this.http.delete(`${environment.apiUrl}/pipeline/${id}`);
return this.http.delete(`${environment.apiUrl}/v1/pipeline/${id}`);
}

toggle(id: string): Observable<any> {
return this.http.patch<any>(`${environment.apiUrl}/pipeline/toggle/${id}`, {});
return this.http.patch<any>(`${environment.apiUrl}/v1/pipeline/toggle/${id}`, {});
}

run(body: RunPipelineCommand): Observable<any> {
return this.http.post<any>(`${environment.apiUrl}/pipeline/run`, body);
return this.http.post<any>(`${environment.apiUrl}/v1/pipeline/run`, body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ export class PipelineTriggerRepositoryService implements PipelineTriggerReposito
) { }

updateDeployKeys(pipelineId: string): Observable<any> {
return this.http.patch<any>(`${environment.apiUrl}/pipelineTrigger/deployKeys/${pipelineId}`, null);
return this.http.patch<any>(`${environment.apiUrl}/v1/pipelineTrigger/deployKeys/${pipelineId}`, null);
}

revealKeys(pipelineId: string): Observable<PipelineTriggerKeysViewModel> {
return this.http.get<PipelineTriggerKeysViewModel>(`${environment.apiUrl}/pipelineTrigger/deployKeys/${pipelineId}`);
return this.http.get<PipelineTriggerKeysViewModel>(`${environment.apiUrl}/v1/pipelineTrigger/deployKeys/${pipelineId}`);
}

create(body: CreatePipelineTriggerCommand): Observable<PipelineTriggerViewModel> {
return this.http.post<PipelineTriggerViewModel>(`${environment.apiUrl}/pipelineTrigger`, body);
return this.http.post<PipelineTriggerViewModel>(`${environment.apiUrl}/v1/pipelineTrigger`, body);
}

update(body: UpdatePipelineTriggerCommand): Observable<PipelineTriggerViewModel> {
return this.http.put<PipelineTriggerViewModel>(`${environment.apiUrl}/pipelineTrigger`, body);
return this.http.put<PipelineTriggerViewModel>(`${environment.apiUrl}/v1/pipelineTrigger`, body);
}

changeSecret(body: ChangeSecretPipelineTriggerCommand): Observable<any> {
return this.http.patch<any>(`${environment.apiUrl}/pipelineTrigger/changeSecret`, body);
return this.http.patch<any>(`${environment.apiUrl}/v1/pipelineTrigger/changeSecret`, body);
}

delete(pipelineTriggerId: string): Observable<any> {
return this.http.delete<any>(`${environment.apiUrl}/pipelineTrigger/${pipelineTriggerId}`);
return this.http.delete<any>(`${environment.apiUrl}/v1/pipelineTrigger/${pipelineTriggerId}`);
}

get(pipelineId: string): Observable<PipelineTriggerViewModel> {
return this.http.get<PipelineTriggerViewModel>(`${environment.apiUrl}/pipelineTrigger/${pipelineId}`);
return this.http.get<PipelineTriggerViewModel>(`${environment.apiUrl}/v1/pipelineTrigger/${pipelineId}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ export class UserRepositoryService implements UserRepositoryInterface {
constructor(private http: HttpClient) { }

getAll(pageSize: number, pageIndex: number): Observable<PaginatedItemsViewModel<UserViewModel>> {
return this.http.get<PaginatedItemsViewModel<UserViewModel>>(`${environment.apiUrl}/user?pageSize=${pageSize}&pageIndex=${pageIndex}`);
return this.http.get<PaginatedItemsViewModel<UserViewModel>>(`${environment.apiUrl}/v1/user?pageSize=${pageSize}&pageIndex=${pageIndex}`);
}

create(body: CreateUserCommand): Observable<UserViewModel> {
return this.http.post<UserViewModel>(`${environment.apiUrl}/user`, body);
return this.http.post<UserViewModel>(`${environment.apiUrl}/v1/user`, body);
}

toggleStatus(id: string): Observable<any> {
return this.http.patch<any>(`${environment.apiUrl}/user/toggleStatus/${id}`, null);
return this.http.patch<any>(`${environment.apiUrl}/v1/user/toggleStatus/${id}`, null);
}

changePassword(body: UpdatePasswordCommand): Observable<any> {
return this.http.patch<any>(`${environment.apiUrl}/user/changePassword`, body);
return this.http.patch<any>(`${environment.apiUrl}/v1/user/changePassword`, body);
}

isFirstSetup(): Observable<any> {
return this.http.get<any>(`${environment.apiUrl}/user/isFirstSetup`);
return this.http.get<any>(`${environment.apiUrl}/v1/user/isFirstSetup`);
}

firstSetup(body: CreateFirstSetupCommand): Observable<UserViewModel> {
return this.http.post<UserViewModel>(`${environment.apiUrl}/user/firstSetup`, body);
return this.http.post<UserViewModel>(`${environment.apiUrl}/v1/user/firstSetup`, body);
}

firstAccess(body: UpdateFirstAccessPasswordCommand): Observable<any> {
return this.http.patch<any>(`${environment.apiUrl}/user/firstAccess`, body);
return this.http.patch<any>(`${environment.apiUrl}/v1/user/firstAccess`, body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ <h1 class="text-2xl font-semibold">Connectors</h1>

<button type="button" class="!px-3 ml-3 btn-primary" (click)="updateConnector.open(row)" matTooltip="Edit"><fa-icon [icon]="['fas', 'pencil']"></fa-icon></button>

<button type="button" class="!px-3 ml-3 btn-primary" [class.spinner]="deleteConnectorBtn.disabled" (click)="deleteConnector(deleteConnectorBtn, row)" matTooltip="Delete" #deleteConnectorBtn>
<button type="button" class="!px-3 ml-3 btn-danger" [class.spinner]="deleteConnectorBtn.disabled" (click)="deleteConnector(deleteConnectorBtn, row)" matTooltip="Delete" #deleteConnectorBtn>
<span class="spinner-text"><fa-icon [icon]="['fas', 'trash']"></fa-icon></span>
</button>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ export class LoginComponent implements OnInit {

ngOnInit(): void {
this.userUseCase.isFirstSetup().subscribe({
error: () => Swal.fire("First setup detected", "Seems it's the first time you are here, let's start from the beginning.", "info").then(() => this.router.navigateByUrl("/first-setup")),
error: (error: HttpErrorResponse[]) => {
if (error[0].error["errorCode"] == "firstSetup") {
Swal.fire("First setup detected", "Seems it's the first time you are here, let's start from the beginning.", "info").then(() => this.router.navigateByUrl("/first-setup"))
} else {
Swal.fire("Something went wrong", "Try again later.", "error");
}
}
}).add(() => this.isLoading = false);
}

Expand Down

0 comments on commit 8bc727c

Please sign in to comment.