Skip to content
Snippets Groups Projects
Commit aeb09e76 authored by Zink Hannah's avatar Zink Hannah
Browse files

adding easteregg to default-plants.json, whowing user error when one occurs...

adding easteregg to default-plants.json, whowing user error when one occurs while fetching data in Grandma.tsx, adding Javadoc in GrandmaService
parent 68250a56
No related branches found
No related tags found
1 merge request!55Resolve #51 Connection Grandma-Backend with Frontend
...@@ -88,6 +88,7 @@ function Grandma() { ...@@ -88,6 +88,7 @@ function Grandma() {
const response = await bc.getPlantsReadyToGrow(); const response = await bc.getPlantsReadyToGrow();
if(response.err) { if(response.err) {
setError(response.err); setError(response.err);
window.alert(error);
} else { } else {
const plants: Plant[] = response.value ?? []; const plants: Plant[] = response.value ?? [];
if (plants.length === 0) { if (plants.length === 0) {
...@@ -114,6 +115,7 @@ function Grandma() { ...@@ -114,6 +115,7 @@ function Grandma() {
const response = await bc.getPlantsNeedingWatering(); const response = await bc.getPlantsNeedingWatering();
if(response.err) { if(response.err) {
setError(response.err); setError(response.err);
window.alert(error);
} else { } else {
const plants: Plant[] = response.value ?? []; const plants: Plant[] = response.value ?? [];
if(plants.length === 0) { if(plants.length === 0) {
...@@ -141,6 +143,7 @@ function Grandma() { ...@@ -141,6 +143,7 @@ function Grandma() {
const response = await bc.getPlantsReadyToHarvest(); const response = await bc.getPlantsReadyToHarvest();
if(response.err) { if(response.err) {
setError(response.err); setError(response.err);
window.alert(error);
} else { } else {
const plants: Plant[] = response.value ?? []; const plants: Plant[] = response.value ?? [];
if(plants.length === 0) { if(plants.length === 0) {
......
...@@ -7,16 +7,22 @@ import hdm.mi.growbros.models.plant.WaterDemand; ...@@ -7,16 +7,22 @@ import hdm.mi.growbros.models.plant.WaterDemand;
import hdm.mi.growbros.models.user.User; import hdm.mi.growbros.models.user.User;
import hdm.mi.growbros.repositories.GardenRepository; import hdm.mi.growbros.repositories.GardenRepository;
import hdm.mi.growbros.repositories.WishListRepository; import hdm.mi.growbros.repositories.WishListRepository;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields; import java.time.temporal.WeekFields;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Random;
/**
* The GrandmaService class provides various gardening-related services for the users.
* It includes methods for generating daily gardening tips, retrieving plants ready to grow,
* identifying plants in the garden needing watering, and finding plants ready to harvest.
*/
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class GrandmaService { public class GrandmaService {
...@@ -25,6 +31,12 @@ public class GrandmaService { ...@@ -25,6 +31,12 @@ public class GrandmaService {
private final GardenService gardenService; private final GardenService gardenService;
private final GardenRepository gardenRepository; private final GardenRepository gardenRepository;
/**
* Generates a daily gardening tip for the user based on their planted plants.
*
* @param user The user for whom the tip is generated.
* @return A string containing the daily gardening tip.
*/
public String growingTippDesTages(User user) { public String growingTippDesTages(User user) {
List<Plant> usersPlants = gardenService.getUserPlants(user , null); List<Plant> usersPlants = gardenService.getUserPlants(user , null);
String tipDesTages; String tipDesTages;
...@@ -38,6 +50,12 @@ public class GrandmaService { ...@@ -38,6 +50,12 @@ public class GrandmaService {
return tipDesTages; return tipDesTages;
} }
/**
* Retrieves a list of plants ready to grow for the user in the current planting week.
*
* @param user The user for whom the list is retrieved.
* @return A list of plants ready to grow.
*/
public List<Plant> getPlantsReadyToGrow( User user) { public List<Plant> getPlantsReadyToGrow( User user) {
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
...@@ -56,6 +74,12 @@ public class GrandmaService { ...@@ -56,6 +74,12 @@ public class GrandmaService {
return plantsReadyToGrow; return plantsReadyToGrow;
} }
/**
* Retrieves a list of plants in the user's garden that need watering based on their water demand.
*
* @param user The user for whom the list is retrieved.
* @return A list of plants needing watering.
*/
public List<Plant> getPlantsInGardenNeedingWatering(User user) { public List<Plant> getPlantsInGardenNeedingWatering(User user) {
List<Plant> plantsNeedingWatering = new ArrayList<>(); List<Plant> plantsNeedingWatering = new ArrayList<>();
List<GardenEntry> plantsInUsersGarden = gardenRepository.findByUser(user); List<GardenEntry> plantsInUsersGarden = gardenRepository.findByUser(user);
...@@ -92,15 +116,12 @@ public class GrandmaService { ...@@ -92,15 +116,12 @@ public class GrandmaService {
return plantsNeedingWatering; return plantsNeedingWatering;
} }
/**
private long getDaysSinceLastWatering(LocalDate lastWateringDate) { * Retrieves a list of plants in the user's garden that are ready to harvest based on their harvest weeks.
if (lastWateringDate != null) { *
LocalDate currentDate = LocalDate.now(); * @param user The user for whom the list is retrieved.
return ChronoUnit.DAYS.between(lastWateringDate, currentDate); * @return A list of plants ready to harvest.
} */
return 0;
}
public List<Plant> getPlantsReadyToHarvest (User user){ public List<Plant> getPlantsReadyToHarvest (User user){
List<Plant> plantsReadyToHarvest = new ArrayList<>(); List<Plant> plantsReadyToHarvest = new ArrayList<>();
List<GardenEntry> plantsInUsersGarden = gardenRepository.findByUser(user); List<GardenEntry> plantsInUsersGarden = gardenRepository.findByUser(user);
...@@ -134,4 +155,11 @@ public class GrandmaService { ...@@ -134,4 +155,11 @@ public class GrandmaService {
return plantsReadyToHarvest; return plantsReadyToHarvest;
} }
private long getDaysSinceLastWatering(LocalDate lastWateringDate) {
if (lastWateringDate != null) {
LocalDate currentDate = LocalDate.now();
return ChronoUnit.DAYS.between(lastWateringDate, currentDate);
}
return 0;
}
} }
source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment