Skip to content

Commit

Permalink
fix some issues raised by mentor
Browse files Browse the repository at this point in the history
  • Loading branch information
TihomirovPavel committed Sep 5, 2018
1 parent d248106 commit f6987ae
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void setStatusAchieved(@PathParam("id") Long goalId) {
Optional<Goal> goal = goalStore.getGoalById(goalId);
if (goal.isPresent()) {
Goal g = goal.get();
if (g.getUser() == user) {
if (g.getUser().equals(user)) {
g.setStatus(GoalStatus.ACHIEVED);
} else {
throw new ValidationException("Current Goal does not belong to you so you can not Edit Status");
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/lv/ctco/javaschool/goal/control/GoalStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public List<Goal> getGoalsListFor(User user) {

private List<Goal> CheckStatus(List<Goal> goals) {
List<Goal> goalsToReturn = new ArrayList<>();
LocalDate localDateNow = LocalDate.now();
for (Goal goal : goals) {
if ((goal.getDeadlineDate().isBefore(LocalDate.now())
|| goal.getDeadlineDate().isEqual(LocalDate.now()))
if ((goal.getDeadlineDate().isBefore(localDateNow)
|| goal.getDeadlineDate().isEqual(localDateNow))
&& goal.getStatus() != GoalStatus.ACHIEVED) {
goal.setStatus(GoalStatus.OVERDUE);
}
Expand Down
45 changes: 37 additions & 8 deletions src/main/java/lv/ctco/javaschool/goal/entity/domain/Goal.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ public class Goal {
@Enumerated(EnumType.STRING)
private GoalStatus status;

public GoalStatus getStatus() {
return status;
}

public void setStatus(GoalStatus status) {
this.status = status;
}

public Goal() {
}

Expand All @@ -56,6 +48,14 @@ public Goal(Long id, User user, Set<Tag> tags, String goalMessage, LocalDate dea
this.registeredDate = registeredDate;
}

public GoalStatus getStatus() {
return status;
}

public void setStatus(GoalStatus status) {
this.status = status;
}

public Set<Tag> getTags() {
return tags;
}
Expand Down Expand Up @@ -103,4 +103,33 @@ public LocalDateTime getRegisteredDate() {
public void setRegisteredDate(LocalDateTime registeredDate) {
this.registeredDate = registeredDate;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Goal goal = (Goal) o;

if (id != null ? !id.equals(goal.id) : goal.id != null) return false;
if (user != null ? !user.equals(goal.user) : goal.user != null) return false;
if (tags != null ? !tags.equals(goal.tags) : goal.tags != null) return false;
if (goalMessage != null ? !goalMessage.equals(goal.goalMessage) : goal.goalMessage != null) return false;
if (deadlineDate != null ? !deadlineDate.equals(goal.deadlineDate) : goal.deadlineDate != null) return false;
if (registeredDate != null ? !registeredDate.equals(goal.registeredDate) : goal.registeredDate != null)
return false;
return status == goal.status;
}

@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (user != null ? user.hashCode() : 0);
result = 31 * result + (tags != null ? tags.hashCode() : 0);
result = 31 * result + (goalMessage != null ? goalMessage.hashCode() : 0);
result = 31 * result + (deadlineDate != null ? deadlineDate.hashCode() : 0);
result = 31 * result + (registeredDate != null ? registeredDate.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
return result;
}
}
4 changes: 0 additions & 4 deletions src/main/webapp/app/js/findgoals-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function findUserByName() {
var dto = {
"usersearch": username.value
};
console.log(JSON.stringify(dto));
fetch("/api/goal/search-user", {
"method": "POST",
headers: {
Expand All @@ -34,7 +33,6 @@ function findUserByName() {
}).then(function (response) {
return response.json();
}).then(function (users) {
console.log(users);
if (users.length > 0) {
var tabledata = {'users': users};
document.getElementById("Users-List").classList.remove("w3-hide");
Expand All @@ -49,7 +47,6 @@ function findGoalsByTag() {
var dto = {
"goalsearch": tag.value
};
console.log(JSON.stringify(dto));
fetch("/api/goal/search-goals", {
"method": "POST",
headers: {
Expand All @@ -60,7 +57,6 @@ function findGoalsByTag() {
}).then(function (response) {
return response.json();
}).then(function (goals) {
console.log(goals);
if (goals.length > 0) {
var tabledata = {'goals': goals};
document.getElementById("Goals-List").classList.remove("w3-hide");
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/app/js/goal-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ function setStatusAchieved(id) {
if (response.status === 204) {
onLoad();
} else {
console.log(response);
alert("Something went wrong! error: " + response.status.toString());
return false;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/app/js/start-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function showUserGoals() {
return response.json();
}).then(function (goals) {
goalList = goals;
console.log(goals);
var tabledata;
if (goals.length > 0) {
tabledata = {"goals": goals};
Expand Down
2 changes: 0 additions & 2 deletions src/main/webapp/app/js/user-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ function loadUser() {
function setDataToFields(userDto) {
var list = userDto.goalList;
var tabledata;
console.log(userDto);
w3.displayObject("title", userDto);
w3.displayObject("username", userDto);
w3.displayObject("email-and-phone", userDto);
if (list.length > 0) {
tabledata = {"goals": list};
console.log(tabledata);
w3DisplayData("goals-list", tabledata);
} else {
document.getElementById("hidden").classList.remove("w3-hide");
Expand Down

0 comments on commit f6987ae

Please sign in to comment.