Skip to content

Commit d2f7323

Browse files
Merge pull request #337 from COS301-SE-2023/hotfix/v1.0.0-beta
2 parents f3f23d0 + 10a5a54 commit d2f7323

File tree

47 files changed

+402
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+402
-411
lines changed

apps/api/src/main/java/com/fridgetoplate/controller/RecipeController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public List<RecipeFrontendModel> findRecipesByRecipename(@PathVariable(value = "
3636
return recipeService.getRecipesByRecipeName(recipename);
3737
}
3838

39-
@PutMapping("/update-ratingAndViews/{id}")
40-
public RecipeFrontendModel updateRatingAndViews(@PathVariable(value = "id") String id, @RequestBody RecipeFrontendModel recipe){
41-
return recipeService.updateRatingAndViews(recipe);
39+
@PutMapping("/increaseViews/{id}")
40+
public RecipeFrontendModel updateRatingAndViews(@PathVariable(value = "id") String id){
41+
return recipeService.increaseViews(id);
4242
}
4343

4444
@PutMapping("/{id}")

apps/api/src/main/java/com/fridgetoplate/model/NotificationModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import lombok.Data;
99

10-
@Data
1110
@DynamoDBTable(tableName = "notifications")
11+
@Data
1212
public class NotificationModel {
1313

1414
String notificationId;
@@ -51,7 +51,7 @@ public String getType(){
5151
}
5252

5353
@DynamoDBAttribute(attributeName = "metadata")
54-
public String getMetaData(){
54+
public String getMetadata(){
5555
return metadata;
5656
}
5757
}

apps/api/src/main/java/com/fridgetoplate/repository/NotificationsRepository.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
package com.fridgetoplate.repository;
22

3-
import java.util.ArrayList;
4-
import java.util.HashMap;
53
import java.util.List;
64

75
import org.springframework.beans.factory.annotation.Autowired;
86
import org.springframework.stereotype.Repository;
97

108
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
119
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
12-
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
13-
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList;
1410
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
15-
import com.fridgetoplate.frontendmodels.NotificationsResponseModel;
16-
import com.fridgetoplate.model.IngredientModel;
1711
import com.fridgetoplate.model.NotificationModel;
1812

1913
import graphql.com.google.common.collect.ImmutableMap;
@@ -37,6 +31,10 @@ public List<NotificationModel> findAllByUser(String userId){
3731
return dynamoDBMapper.query(NotificationModel.class, query);
3832
}
3933

34+
public void delete(NotificationModel notification){
35+
dynamoDBMapper.delete(notification);
36+
}
37+
4038
public void deleteAll(List<NotificationModel> notifications){
4139
dynamoDBMapper.batchDelete(notifications);
4240
}

apps/api/src/main/java/com/fridgetoplate/repository/RecipeRepository.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22
package com.fridgetoplate.repository;
33
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
44
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
5-
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression;
65
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
7-
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList;
86
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
97
import com.amazonaws.services.dynamodbv2.model.ComparisonOperator;
108
import com.amazonaws.services.dynamodbv2.model.Condition;
11-
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue;
12-
import com.fridgetoplate.frontendmodels.RecipeFrontendModel;
13-
import com.fridgetoplate.frontendmodels.RecipePreferencesFrontendModel;
149
import com.fridgetoplate.interfaces.Explore;
15-
import com.fridgetoplate.interfaces.RecipeDesc;
16-
import com.fridgetoplate.model.Ingredient;
1710
import com.fridgetoplate.model.IngredientModel;
1811
import com.fridgetoplate.model.RecipeModel;
19-
import com.fridgetoplate.model.Review;
2012

2113
import graphql.com.google.common.collect.ImmutableMap;
2214

23-
import java.util.ArrayList;
2415
import java.util.HashMap;
2516
import java.util.List;
2617
import java.util.Map;
@@ -165,5 +156,4 @@ public List<RecipeModel> filterSearch(Explore explore){
165156

166157
}
167158

168-
169159
}

apps/api/src/main/java/com/fridgetoplate/service/NotificationService.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import com.fridgetoplate.interfaces.RecipeDesc;
1414
import com.fridgetoplate.model.NotificationModel;
1515
import com.fridgetoplate.repository.NotificationsRepository;
16-
import com.fridgetoplate.repository.ProfileRepository;
1716
import com.fridgetoplate.model.ProfileModel;
18-
import com.fridgetoplate.utils.NotificationsUtils;
1917
@Service
2018
public class NotificationService {
2119

@@ -28,8 +26,6 @@ public class NotificationService {
2826
@Autowired
2927
private ExploreService exploreService;
3028

31-
private NotificationsUtils utils = new NotificationsUtils();
32-
3329
Random random = new Random();
3430

3531
public NotificationModel save(NotificationModel notification){
@@ -71,19 +67,18 @@ public String clearAllNotificationOfType(String userId, String type){
7167

7268
List<NotificationModel> notifications = notificationsRepository.findAllByUser(userId);
7369

74-
List<NotificationModel> deletableNotifications = new ArrayList<>();
7570
for (NotificationModel notificationModel : notifications) {
7671
if (notificationModel.getType().equals(type)) {
77-
deletableNotifications.add(notificationModel);
72+
System.out.println(notificationModel.toString());
73+
notificationsRepository.delete(notificationModel);
7874
}
7975
}
8076

81-
notificationsRepository.deleteAll(deletableNotifications);
8277
return "Successfully cleared all " + type + " notifications";
8378

8479
}
8580

86-
@Scheduled(cron = "0 0 8 * * ?")
81+
@Scheduled(cron = "0 30 6 * * *")
8782
public void breakfastNotificationsPush(){
8883
random.setSeed(System.currentTimeMillis());
8984

@@ -92,7 +87,7 @@ public void breakfastNotificationsPush(){
9287

9388
//1. Get random users
9489
for(; selectedUsers.size() < allUsers.size() * 0.6 ;){
95-
int index = random.nextInt(0, allUsers.size());
90+
int index = random.nextInt(allUsers.size());
9691
ProfileModel currentProfile = allUsers.get(index);
9792

9893
if(!selectedUsers.contains(currentProfile)){
@@ -110,7 +105,7 @@ public void breakfastNotificationsPush(){
110105
// 3. Create notifications
111106
for(int i = 0; i < selectedUsers.size(); i++){
112107

113-
int index = random.nextInt(0, allUsers.size());
108+
int index = random.nextInt(allUsers.size());
114109
RecipeDesc currRecipeDesc = recipes.get(index);
115110

116111
ProfileModel currentUser = selectedUsers.get(i);
@@ -120,15 +115,15 @@ public void breakfastNotificationsPush(){
120115
newNotification.setUserId(currentUser.getUsername());
121116
newNotification.setNotificationPic(currRecipeDesc.getRecipeImage());
122117
newNotification.setType("recommendation");
123-
newNotification.setTitle("We recommend " + currRecipeDesc.getRecipeImage() + " for breakfast today");
118+
newNotification.setTitle("We recommend " + currRecipeDesc.getName() + " for breakfast today");
124119
newNotification.setBody("Good time to try a new breakfast recipe! Explore our collection and find something delicious to kickstart your day.");
120+
newNotification.setMetadata("/recipe/" + currRecipeDesc.getRecipeId());
125121

126-
System.out.println(newNotification.toString());
127122
this.save(newNotification);
128123
}
129124
}
130125

131-
@Scheduled(cron = "0 0 12 * * ?")
126+
@Scheduled(cron = "0 0 12 * * *")
132127
public void lunchtimeNotificationsPush() {
133128
random.setSeed(System.currentTimeMillis());
134129

@@ -137,7 +132,7 @@ public void lunchtimeNotificationsPush() {
137132

138133
//1. Get random users
139134
for(; selectedUsers.size() < allUsers.size() * 0.6 ;){
140-
int index = random.nextInt(0, allUsers.size());
135+
int index = random.nextInt(allUsers.size());
141136
ProfileModel currentProfile = allUsers.get(index);
142137

143138
if(!selectedUsers.contains(currentProfile)){
@@ -155,7 +150,7 @@ public void lunchtimeNotificationsPush() {
155150
// 3. Create notifications
156151
for(int i = 0; i < selectedUsers.size(); i++){
157152

158-
int index = random.nextInt(0, allUsers.size());
153+
int index = random.nextInt(allUsers.size());
159154
RecipeDesc currRecipeDesc = recipes.get(index);
160155

161156
ProfileModel currentUser = selectedUsers.get(i);
@@ -165,15 +160,15 @@ public void lunchtimeNotificationsPush() {
165160
newNotification.setUserId(currentUser.getUsername());
166161
newNotification.setNotificationPic(currRecipeDesc.getRecipeImage());
167162
newNotification.setType("recommendation");
168-
newNotification.setTitle("Have a delicious " + currRecipeDesc.getRecipeImage() + " for lunch today");
163+
newNotification.setTitle("Have a delicious " + currRecipeDesc.getName() + " for lunch today");
169164
newNotification.setBody("Lunch hour is approaching! Discover a tasty lunch recipe from our selection and enjoy a flavorful midday meal.");
165+
newNotification.setMetadata("/recipe/" + currRecipeDesc.getRecipeId());
170166

171-
System.out.println(newNotification.toString());
172167
this.save(newNotification);
173168
}
174169
}
175170

176-
@Scheduled(cron = "0 16 * * * ?")
171+
@Scheduled(cron = "0 0 17 * * *")
177172
public void dinnertimeNotificationsPush() {
178173
random.setSeed(System.currentTimeMillis());
179174

@@ -182,7 +177,7 @@ public void dinnertimeNotificationsPush() {
182177

183178
//1. Get random users
184179
for(; selectedUsers.size() < allUsers.size() * 0.6 ;){
185-
int index = random.nextInt(0, allUsers.size());
180+
int index = random.nextInt(allUsers.size());
186181
ProfileModel currentProfile = allUsers.get(index);
187182

188183
if(!selectedUsers.contains(currentProfile)){
@@ -200,7 +195,7 @@ public void dinnertimeNotificationsPush() {
200195
// 3. Create notifications
201196
for(int i = 0; i < selectedUsers.size(); i++){
202197

203-
int index = random.nextInt(0, allUsers.size());
198+
int index = random.nextInt(allUsers.size());
204199
RecipeDesc currRecipeDesc = recipes.get(index);
205200

206201
ProfileModel currentUser = selectedUsers.get(i);
@@ -210,10 +205,10 @@ public void dinnertimeNotificationsPush() {
210205
newNotification.setUserId(currentUser.getUsername());
211206
newNotification.setNotificationPic(currRecipeDesc.getRecipeImage());
212207
newNotification.setType("recommendation");
213-
newNotification.setTitle("Why not try " + currRecipeDesc.getRecipeImage() + " for dinner today");
208+
newNotification.setTitle("Why not try " + currRecipeDesc.getName() + " for dinner today");
214209
newNotification.setBody("Dinnertime is here! Explore our variety of dinner recipes and cook up something special for your evening.");
210+
newNotification.setMetadata("/recipe/" + currRecipeDesc.getRecipeId());
215211

216-
System.out.println(newNotification.toString());
217212
this.save(newNotification);
218213
}
219214
}

0 commit comments

Comments
 (0)