Skip to content

Commit

Permalink
♻️ Remove PriorityLevelDto and just use LookupDto.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontaylordev committed Jun 27, 2023
1 parent d21f01b commit ec394cb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
3 changes: 2 additions & 1 deletion src/Application/TodoLists/Queries/GetTodos/GetTodos.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CleanArchitecture.Application.Common.Interfaces;
using CleanArchitecture.Application.Common.Models;
using CleanArchitecture.Application.Common.Security;
using CleanArchitecture.Domain.Enums;

Expand All @@ -24,7 +25,7 @@ public async Task<TodosVm> Handle(GetTodosQuery request, CancellationToken cance
{
PriorityLevels = Enum.GetValues(typeof(PriorityLevel))
.Cast<PriorityLevel>()
.Select(p => new PriorityLevelDto { Value = (int)p, Name = p.ToString() })
.Select(p => new LookupDto { Id = (int)p, Title = p.ToString() })
.ToList(),

Lists = await _context.TodoLists
Expand Down

This file was deleted.

6 changes: 4 additions & 2 deletions src/Application/TodoLists/Queries/GetTodos/TodosVm.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace CleanArchitecture.Application.TodoLists.Queries.GetTodos;
using CleanArchitecture.Application.Common.Models;

namespace CleanArchitecture.Application.TodoLists.Queries.GetTodos;

public class TodosVm
{
public IReadOnlyCollection<PriorityLevelDto> PriorityLevels { get; init; } = Array.Empty<PriorityLevelDto>();
public IReadOnlyCollection<LookupDto> PriorityLevels { get; init; } = Array.Empty<LookupDto>();

public IReadOnlyCollection<TodoListDto> Lists { get; init; } = Array.Empty<TodoListDto>();
}
2 changes: 1 addition & 1 deletion src/WebUI/ClientApp/src/app/todo/todo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h4 class="modal-title pull-left">Item Details</h4>
<div class="form-group">
<label for="priority">Priority</label>
<select class="form-control" [(ngModel)]="itemDetailsEditor.priority">
<option [ngValue]="level.value" *ngFor="let level of priorityLevels">{{ level.name }}</option>
<option [ngValue]="level.id" *ngFor="let level of priorityLevels">{{ level.title }}</option>
</select>
</div>
<div class="form-group">
Expand Down
6 changes: 3 additions & 3 deletions src/WebUI/ClientApp/src/app/todo/todo.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, TemplateRef, OnInit } from '@angular/core';
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
import { TodoListsClient, TodoItemsClient,
TodoListDto, TodoItemDto, PriorityLevelDto,
TodoListDto, TodoItemDto, LookupDto,
CreateTodoListCommand, UpdateTodoListCommand,
CreateTodoItemCommand, UpdateTodoItemCommand, UpdateTodoItemDetailCommand
} from '../web-api-client';
Expand All @@ -14,7 +14,7 @@ import { TodoListsClient, TodoItemsClient,
export class TodoComponent implements OnInit {
debug = false;
lists: TodoListDto[];
priorityLevels: PriorityLevelDto[];
priorityLevels: LookupDto[];
selectedList: TodoListDto;
selectedItem: TodoItemDto;
newListEditor: any = {};
Expand Down Expand Up @@ -161,7 +161,7 @@ export class TodoComponent implements OnInit {
const item = {
id: 0,
listId: this.selectedList.id,
priority: this.priorityLevels[0].value,
priority: this.priorityLevels[0].id,
title: '',
done: false
} as TodoItemDto;
Expand Down
32 changes: 16 additions & 16 deletions src/WebUI/ClientApp/src/app/web-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ export enum PriorityLevel {
}

export class TodosVm implements ITodosVm {
priorityLevels?: PriorityLevelDto[];
priorityLevels?: LookupDto[];
lists?: TodoListDto[];

constructor(data?: ITodosVm) {
Expand All @@ -1013,7 +1013,7 @@ export class TodosVm implements ITodosVm {
if (Array.isArray(_data["priorityLevels"])) {
this.priorityLevels = [] as any;
for (let item of _data["priorityLevels"])
this.priorityLevels!.push(PriorityLevelDto.fromJS(item));
this.priorityLevels!.push(LookupDto.fromJS(item));
}
if (Array.isArray(_data["lists"])) {
this.lists = [] as any;
Expand Down Expand Up @@ -1047,15 +1047,15 @@ export class TodosVm implements ITodosVm {
}

export interface ITodosVm {
priorityLevels?: PriorityLevelDto[];
priorityLevels?: LookupDto[];
lists?: TodoListDto[];
}

export class PriorityLevelDto implements IPriorityLevelDto {
value?: number;
name?: string | undefined;
export class LookupDto implements ILookupDto {
id?: number;
title?: string | undefined;

constructor(data?: IPriorityLevelDto) {
constructor(data?: ILookupDto) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
Expand All @@ -1066,29 +1066,29 @@ export class PriorityLevelDto implements IPriorityLevelDto {

init(_data?: any) {
if (_data) {
this.value = _data["value"];
this.name = _data["name"];
this.id = _data["id"];
this.title = _data["title"];
}
}

static fromJS(data: any): PriorityLevelDto {
static fromJS(data: any): LookupDto {
data = typeof data === 'object' ? data : {};
let result = new PriorityLevelDto();
let result = new LookupDto();
result.init(data);
return result;
}

toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["value"] = this.value;
data["name"] = this.name;
data["id"] = this.id;
data["title"] = this.title;
return data;
}
}

export interface IPriorityLevelDto {
value?: number;
name?: string | undefined;
export interface ILookupDto {
id?: number;
title?: string | undefined;
}

export class TodoListDto implements ITodoListDto {
Expand Down
8 changes: 4 additions & 4 deletions src/WebUI/wwwroot/api/specification.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
"priorityLevels": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PriorityLevelDto"
"$ref": "#/components/schemas/LookupDto"
}
},
"lists": {
Expand All @@ -596,15 +596,15 @@
}
}
},
"PriorityLevelDto": {
"LookupDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"value": {
"id": {
"type": "integer",
"format": "int32"
},
"name": {
"title": {
"type": "string",
"nullable": true
}
Expand Down

0 comments on commit ec394cb

Please sign in to comment.