-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update todo/24 update todo #25
base: master
Are you sure you want to change the base?
Conversation
2. If DueDate is not given we show empty in ouput.
Refactored Validate Commands.
Refactored Validate Commands.
…ther-Discord/EasyList into UpdateTodo/24-UpdateTodo
src/EasyList/Program.cs
Outdated
{ | ||
class Program | ||
{ | ||
public static ITodoService _todoService = Factory.CreateTodoServiceDB(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to something like TodoService
and make it a readonly property.
using System.Linq; | ||
|
||
public static class Validate | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't make this static. You should create a new instance of the validator each time you want to run it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I not able to understand the reasoning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Validate class validates one object. It does so by having a field called errors. Now the errors field is not for every validated item but rather for the one being validated right now. So you use one Validator to validate an item, then you use another validator for another. Because every validator that runs has different errors due to another object meaning there should never be just one list of errors.
src/EasyList/Validate.cs
Outdated
|
||
public static bool DueDate(string? input) | ||
{ | ||
if (DateTimeOffset.TryParse(input, out DateTimeOffset tempDate)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will return true if I put in an invalid date
src/EasyList/Validate.cs
Outdated
|
||
public static class Validate | ||
{ | ||
static List<string> errors = new List<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing access modifier and underscore prefix
@@ -54,7 +54,7 @@ public static class ParseAdd | |||
string label = GetData("add", args, positions) ?? string.Empty; | |||
string description = GetData("-d", args, positions) ?? string.Empty; | |||
string dueDate = GetData("-t", args, positions) ?? string.Empty; | |||
string priority = GetData("-p", args, positions) ?? "${TodoPriority.Low}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did this get committed? Was the code not debugged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, Maybe Expecting only a silly string change I didn't check after this commit.
@@ -5,7 +5,7 @@ namespace EasyList | |||
{ | |||
class Program | |||
{ | |||
public static ITodoService _todoService = Factory.CreateTodoServiceDB(); | |||
public static ITodoService TodoService => Factory.CreateTodoServiceDB(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct naming convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a field and not a Property so _todoService ? @Anequit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually a property. This is shorthand for a read-only property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the service a static instance and inside program.cs if its not being used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the service a static instance and inside program.cs if its not being used here?
So that is becomes very easy to identify where we declared it at one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually a property. This is shorthand for a read-only property.
@valincius I meant before changing it. As you suggested last time i changed it to a read only property here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the service a static instance and inside program.cs if its not being used here?
So that is becomes very easy to identify where we declared it at one place.
What do you mean with "identify"? I have mentioned this before. You have set up a dependency inversion system with the factories, i would stick with that. You should first of all use encapsulation which is part of the OOP principles. Secondly there is no point in making a class non-static just to make it static afterwards. Also always try to keep Program.cs as clean as possible, it is only supposed to be used as the starting point of your application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
break; | ||
{ | ||
Console.WriteLine("Exiting..."); | ||
Environment.Exit(Environment.ExitCode = 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Environment.Exit(0); does the same thing
|
||
while(true) | ||
var _todoValidate = new Validate(); | ||
while (true) | ||
{ | ||
var action = Prompt.Select<TODOMENU>("Welcome to EasyList!"); | ||
//Refactor this such that adding new should not modify this input layer | ||
switch (action) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if statement would be a bit cleaner. Especially when you have logic in every case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this ? @Anequit
@@ -53,32 +53,32 @@ public void DisplayAllTodo(TodoOrder todoOrder) | |||
|
|||
public void UpdateTodo(Todo todo, TodoUpdate command) | |||
{ | |||
var _todoValidate = new Validate(); | |||
switch (command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If statement would be better here too.
todo.Label = newLabel!; | ||
} | ||
todo.Label = newLabel; | ||
_todoRepository.UpdateTodo(todo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is being repeated in every case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most of the switch statements would work better as if statements.
disable
src/EasyList/DataModels/Todo.cs (Line 47) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmu on dc if you want and we can go through the stuff together
@@ -5,7 +5,7 @@ namespace EasyList | |||
{ | |||
class Program | |||
{ | |||
public static ITodoService _todoService = Factory.CreateTodoServiceDB(); | |||
public static ITodoService TodoService => Factory.CreateTodoServiceDB(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the service a static instance and inside program.cs if its not being used here?
|
||
public static void Run() | ||
{ | ||
ITodoService _todoService = Factory.CreateTodoServiceDB(); | ||
while(true) | ||
var _todoValidate = new Validate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class is Todo specific and should be called TodoValidator, i think a name for the field should be the same name as the class
DueDate = DateTimeOffset.TryParse(parsedAdd["duedate"], out DateTimeOffset tempDate) ? tempDate : null, | ||
Priority = Enum.Parse<TodoPriority>(parsedAdd["priority"]) | ||
}; | ||
Program.TodoService.AddTodo(newTodo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TodoService should be in this class instead
|
||
case TodoUpdate.Priority: | ||
{ | ||
todo.Priority = Prompt.Select<TodoPriority>("Select new Priority."); ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service should not interact with the user, thats a job for the menu
{ | ||
public static class Utility | ||
{ | ||
public static IEnumerable<int> ToIntIds(this string[] input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not bound to ids so could use a more generic name
} | ||
Console.Clear(); | ||
var choice = Prompt.Confirm("Continue with Valid Ids ? "); | ||
Thread.Sleep(1500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont bully my cpu :(
{ | ||
public class Validate | ||
{ | ||
private static bool IsErrorFree(IEnumerable<string> errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method name implies it checks if the todo is error free but thats not what it does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you suggest ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all this method should be "PrintErrors" because the if errors.any can be checked outside the code. This method does two things, it checks if there are any errors and then prints all the errors at the same time it returns a boolean. If you do something like if(todoValidator.IsValid){todoValidator.PrintErrors}
it would make a bit more sense and also follow principles such as SRP in this case the method should only have one responsibility, one job.
Any update on this one? Looks like there haven't been any commits in 21 days |
closes #24