Skip to content
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

Status goals #56

Merged
merged 7 commits into from
Sep 6, 2018
Merged

Status goals #56

merged 7 commits into from
Sep 6, 2018

Conversation

TihomirovPavel
Copy link
Contributor

Checklist

  • I've run mvn test from the root directory to see all new and existing tests pass
  • I've followed code style and run and ensured the code style is valid
  • I've created new tests if necessary.

Motivation and Context

#52

Description

this functionality is required for tracking goals statuses.

@@ -152,7 +154,6 @@ public void editGoal(@PathParam("id") Long goalId, GoalFormDto newGoalDto) {
}

@POST
@RolesAllowed({"ADMIN", "USER"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this removed? Do you want to allow users without these roles to use these methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they were moved to the top of the GoalApi because that all the methods are allowed to all users in GoalApi .

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Did not see the class-level annotation at first, due to GitHub collapsing unchanged code.

Optional<Goal> goal = goalStore.getGoalById(goalId);
if (goal.isPresent()) {
Goal g = goal.get();
if (g.getUser() == user) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Only primitives, Strings and Enums may be compared this way. Never use == to compare objects unless you are explicitly comparing references to the same object. Use equals() (making sure the class implements both equals() and hashCode()), or compare user IDs.

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be possible that they are the same object due to entity persistence framework (Hibernate), however we cannot rely on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added equals() and hashCode()

liptons333
liptons333 previously approved these changes Sep 5, 2018
private List<Goal> CheckStatus(List<Goal> goals) {
List<Goal> goalsToReturn = new ArrayList<>();
for (Goal goal : goals) {
if ((goal.getDeadlineDate().isBefore(LocalDate.now())
Copy link
Contributor

Choose a reason for hiding this comment

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

Please extract LocalDate.now() to a variable and place it outside the for loop, to ensure consistent comparison of all goals against a single date and to reduce the amount of calls to LocalDate.now().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

extracted thank you.

if (response.status === 204) {
onLoad();
} else {
console.log(response);
Copy link
Contributor

@olegvm olegvm Sep 5, 2018

Choose a reason for hiding this comment

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

Might be worth it to extract console.log() and alert() to a single function which reports the error (e.g. displayError(response), and reuse that function over the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alert() extracted to function displayErrors() and removed all console.log()

liptons333
liptons333 previously approved these changes Sep 6, 2018
return false;
}
displayError(response, 200);
return response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this return work as intended in case of error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, displayError() does redirect in case of error so the rest of the code will not start.

@@ -6,10 +6,10 @@ function logout() {
});
}
function redirectToGoalsAndComments(id) {
if (id >= 0) {
location.href = path + "/app/goal.jsp?id=" + id;
if (id === "-9999") {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reason is on the main page if you do not have a any goals it will create a fake entry which on-click redirects to add page using this id.

}

function displayError(response, expected) {
if (response.status === expected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The if condition should be inverted to avoid an empty block, i.e.:

if (response.status !== expected) {
    ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will do.

if (response.status === expected) {
} else {
alert("Something went wrong! error: " + response.status.toString());
history.go(-1);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for automatically going back to the previous page in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no reason to stay on page where there is no data so you will be redirected to your last page. The question is should i redirect to some error page or not? because there is a warning with error already.

@olegvm olegvm merged commit 0622e14 into master Sep 6, 2018
@olegvm olegvm deleted the status-goals branch September 6, 2018 08:51
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.

3 participants