Skip to content

Commit

Permalink
Merge pull request #337 from COS301-SE-2023/hotfix/v1.0.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbasiltrickett authored Sep 21, 2023
2 parents f3f23d0 + 10a5a54 commit d2f7323
Show file tree
Hide file tree
Showing 47 changed files with 402 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public List<RecipeFrontendModel> findRecipesByRecipename(@PathVariable(value = "
return recipeService.getRecipesByRecipeName(recipename);
}

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

@PutMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import lombok.Data;

@Data
@DynamoDBTable(tableName = "notifications")
@Data
public class NotificationModel {

String notificationId;
Expand Down Expand Up @@ -51,7 +51,7 @@ public String getType(){
}

@DynamoDBAttribute(attributeName = "metadata")
public String getMetaData(){
public String getMetadata(){
return metadata;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package com.fridgetoplate.repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.fridgetoplate.frontendmodels.NotificationsResponseModel;
import com.fridgetoplate.model.IngredientModel;
import com.fridgetoplate.model.NotificationModel;

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

public void delete(NotificationModel notification){
dynamoDBMapper.delete(notification);
}

public void deleteAll(List<NotificationModel> notifications){
dynamoDBMapper.batchDelete(notifications);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
package com.fridgetoplate.repository;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ComparisonOperator;
import com.amazonaws.services.dynamodbv2.model.Condition;
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue;
import com.fridgetoplate.frontendmodels.RecipeFrontendModel;
import com.fridgetoplate.frontendmodels.RecipePreferencesFrontendModel;
import com.fridgetoplate.interfaces.Explore;
import com.fridgetoplate.interfaces.RecipeDesc;
import com.fridgetoplate.model.Ingredient;
import com.fridgetoplate.model.IngredientModel;
import com.fridgetoplate.model.RecipeModel;
import com.fridgetoplate.model.Review;

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -165,5 +156,4 @@ public List<RecipeModel> filterSearch(Explore explore){

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import com.fridgetoplate.interfaces.RecipeDesc;
import com.fridgetoplate.model.NotificationModel;
import com.fridgetoplate.repository.NotificationsRepository;
import com.fridgetoplate.repository.ProfileRepository;
import com.fridgetoplate.model.ProfileModel;
import com.fridgetoplate.utils.NotificationsUtils;
@Service
public class NotificationService {

Expand All @@ -28,8 +26,6 @@ public class NotificationService {
@Autowired
private ExploreService exploreService;

private NotificationsUtils utils = new NotificationsUtils();

Random random = new Random();

public NotificationModel save(NotificationModel notification){
Expand Down Expand Up @@ -71,19 +67,18 @@ public String clearAllNotificationOfType(String userId, String type){

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

List<NotificationModel> deletableNotifications = new ArrayList<>();
for (NotificationModel notificationModel : notifications) {
if (notificationModel.getType().equals(type)) {
deletableNotifications.add(notificationModel);
System.out.println(notificationModel.toString());
notificationsRepository.delete(notificationModel);
}
}

notificationsRepository.deleteAll(deletableNotifications);
return "Successfully cleared all " + type + " notifications";

}

@Scheduled(cron = "0 0 8 * * ?")
@Scheduled(cron = "0 30 6 * * *")
public void breakfastNotificationsPush(){
random.setSeed(System.currentTimeMillis());

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

//1. Get random users
for(; selectedUsers.size() < allUsers.size() * 0.6 ;){
int index = random.nextInt(0, allUsers.size());
int index = random.nextInt(allUsers.size());
ProfileModel currentProfile = allUsers.get(index);

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

int index = random.nextInt(0, allUsers.size());
int index = random.nextInt(allUsers.size());
RecipeDesc currRecipeDesc = recipes.get(index);

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

System.out.println(newNotification.toString());
this.save(newNotification);
}
}

@Scheduled(cron = "0 0 12 * * ?")
@Scheduled(cron = "0 0 12 * * *")
public void lunchtimeNotificationsPush() {
random.setSeed(System.currentTimeMillis());

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

//1. Get random users
for(; selectedUsers.size() < allUsers.size() * 0.6 ;){
int index = random.nextInt(0, allUsers.size());
int index = random.nextInt(allUsers.size());
ProfileModel currentProfile = allUsers.get(index);

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

int index = random.nextInt(0, allUsers.size());
int index = random.nextInt(allUsers.size());
RecipeDesc currRecipeDesc = recipes.get(index);

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

System.out.println(newNotification.toString());
this.save(newNotification);
}
}

@Scheduled(cron = "0 16 * * * ?")
@Scheduled(cron = "0 0 17 * * *")
public void dinnertimeNotificationsPush() {
random.setSeed(System.currentTimeMillis());

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

//1. Get random users
for(; selectedUsers.size() < allUsers.size() * 0.6 ;){
int index = random.nextInt(0, allUsers.size());
int index = random.nextInt(allUsers.size());
ProfileModel currentProfile = allUsers.get(index);

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

int index = random.nextInt(0, allUsers.size());
int index = random.nextInt(allUsers.size());
RecipeDesc currRecipeDesc = recipes.get(index);

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

System.out.println(newNotification.toString());
this.save(newNotification);
}
}
Expand Down
Loading

0 comments on commit d2f7323

Please sign in to comment.