Add created

This commit is contained in:
Kasper Juul Hermansen 2021-11-20 00:37:20 +01:00
parent 2506324cfd
commit 4f3b19891a
Signed by: kjuulh
GPG Key ID: DCD9397082D97069
8 changed files with 27 additions and 12 deletions

View File

@ -40,7 +40,8 @@ public record CreateTodoCommand(
request.TodoTitle,
request.TodoProject,
request.TodoDescription,
userId);
userId,
DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
await _mediator.Publish(
new TodoCreated(todo.Id),

View File

@ -6,7 +6,8 @@ public record TodoViewModel(
bool Status,
string AuthorId,
string? Project,
string? Description
string? Description,
long Created
)
{
internal static TodoViewModel From(Entities.Todo t) => new(
@ -15,5 +16,6 @@ public record TodoViewModel(
t.Status,
t.AuthorId,
t.Project,
t.Description);
t.Description,
t.Created);
}

View File

@ -8,4 +8,5 @@ public record Todo
public string? Project { get; init; }
public string AuthorId { get; init; }
public string? Description { get; init; }
public long Created { get; init; }
}

View File

@ -6,7 +6,8 @@ public interface ITodoRepository
string title,
string? projectName,
string? description,
string userId);
string userId,
long created);
Task<IEnumerable<Entities.Todo>> GetTodosAsync();

View File

@ -19,4 +19,5 @@ public record MongoTodo
public string? ProjectName { get; set; } = string.Empty;
public string AuthorId { get; set; }
public long Created { get; set; } = 0;
}

View File

@ -18,16 +18,18 @@ public class TodoRepository : ITodoRepository
public async Task<Core.Entities.Todo> CreateTodoAsync(
string title,
string projectName,
string? projectName,
string? description,
string userId)
string userId,
long created)
{
var todo = new MongoTodo
{
Title = title,
ProjectName = projectName,
AuthorId = userId,
Description = description
Description = description,
Created = created
};
await _todosCollection.InsertOneAsync(todo);
return new Core.Entities.Todo
@ -37,7 +39,8 @@ public class TodoRepository : ITodoRepository
Status = false,
Project = todo.ProjectName,
Description = todo.Description,
AuthorId = todo.AuthorId
AuthorId = todo.AuthorId,
Created = todo.Created
};
}
@ -55,7 +58,8 @@ public class TodoRepository : ITodoRepository
Status = t.Status,
Project = t.ProjectName,
Description = t.Description,
AuthorId = t.AuthorId
AuthorId = t.AuthorId,
Created = t.Created
});
}
@ -88,7 +92,8 @@ public class TodoRepository : ITodoRepository
Status = todo.Status,
Title = todo.Title,
Description = todo.Description,
AuthorId = todo.AuthorId
AuthorId = todo.AuthorId,
Created = todo.Created
};
}
@ -104,7 +109,8 @@ public class TodoRepository : ITodoRepository
Title = todo.Title,
ProjectName = todo.Project,
AuthorId = todo.AuthorId,
Description = todo.Description
Description = todo.Description,
Created = todo.Created
});
return new Core.Entities.Todo
@ -114,7 +120,8 @@ public class TodoRepository : ITodoRepository
Status = updatedTodo.Status,
Title = updatedTodo.Title,
AuthorId = updatedTodo.AuthorId,
Description = updatedTodo.Description
Description = updatedTodo.Description,
Created = updatedTodo.Created
};
}
}

View File

@ -20,6 +20,7 @@ export const TodoList = (props: {
return t.status == false;
})
.sort((a, b) => a.created - b.created)
.map((t, i) => (
<li key={i}>
<TodoItem

View File

@ -13,6 +13,7 @@ export interface Todo {
status: StatusState;
project?: string;
authorId?: string;
created: number;
}
export const asTodo = (item: Todo): Todo => {