1313import com .fridgetoplate .interfaces .RecipeDesc ;
1414import com .fridgetoplate .model .NotificationModel ;
1515import com .fridgetoplate .repository .NotificationsRepository ;
16- import com .fridgetoplate .repository .ProfileRepository ;
1716import com .fridgetoplate .model .ProfileModel ;
18- import com .fridgetoplate .utils .NotificationsUtils ;
1917@ Service
2018public 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