Skip to content

Conversation

@18-F-cali
Copy link
Contributor

closes #24

@18-F-cali 18-F-cali self-assigned this Aug 12, 2021
@18-F-cali 18-F-cali requested review from Anequit and chrisK00 and removed request for Anequit August 12, 2021 17:15
@chrisK00 chrisK00 requested review from valincius and removed request for chrisK00 August 12, 2021 17:41
@18-F-cali 18-F-cali requested review from Anequit and chrisK00 August 12, 2021 17:53
{
class Program
{
public static ITodoService _todoService = Factory.CreateTodoServiceDB();
Copy link
Member

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
{
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.


public static bool DueDate(string? input)
{
if (DateTimeOffset.TryParse(input, out DateTimeOffset tempDate))
Copy link
Member

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


public static class Validate
{
static List<string> errors = new List<string>();
Copy link
Contributor

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

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}";
Copy link
Contributor

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?

Copy link
Contributor Author

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.

class Program
{
public static ITodoService _todoService = Factory.CreateTodoServiceDB();
public static ITodoService TodoService => Factory.CreateTodoServiceDB();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct naming convention.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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

{
var action = Prompt.Select<TODOMENU>("Welcome to EasyList!");
//Refactor this such that adding new should not modify this input layer
switch (action)
Copy link
Contributor

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.

Copy link
Contributor Author

@18-F-cali 18-F-cali Aug 20, 2021

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
image

public void UpdateTodo(Todo todo, TodoUpdate command)
{
var _todoValidate = new Validate();
switch (command)
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

@Anequit Anequit left a 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.

@chrisK00
Copy link
Contributor

disable
enable?

#nullable enable

src/EasyList/DataModels/Todo.cs (Line 47)

Copy link
Contributor

@chrisK00 chrisK00 left a 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

class Program
{
public static ITodoService _todoService = Factory.CreateTodoServiceDB();
public static ITodoService TodoService => Factory.CreateTodoServiceDB();
Copy link
Contributor

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?

{
ITodoService _todoService = Factory.CreateTodoServiceDB();
while(true)
var _todoValidate = new Validate();
Copy link
Contributor

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);
Copy link
Contributor

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."); ;
Copy link
Contributor

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)
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest ?

Copy link
Contributor

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.

@valincius
Copy link
Member

Any update on this one? Looks like there haven't been any commits in 21 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide Functionality to Edit a Todo.

4 participants