Skip to content

Commit 2c5ee36

Browse files
committed
Created endpont to query for active notifications
1 parent 4cdca5b commit 2c5ee36

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/main/java/edu/tamu/app/controller/NotificationController.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
import static edu.tamu.framework.enums.BusinessValidationType.NONEXISTS;
88
import static edu.tamu.framework.enums.BusinessValidationType.UPDATE;
99

10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
import org.apache.tools.ant.taskdefs.condition.Not;
1014
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.web.bind.annotation.RequestParam;
1116
import org.springframework.web.bind.annotation.RestController;
1217

18+
import edu.tamu.app.enums.NotificationLocation;
1319
import edu.tamu.app.model.Notification;
1420
import edu.tamu.app.model.repo.NotificationRepo;
1521
import edu.tamu.framework.aspect.annotation.ApiMapping;
@@ -61,4 +67,23 @@ public ApiResponse remove(@ApiValidatedModel Notification notification) {
6167
notificationRepo.delete(notification);
6268
return new ApiResponse(SUCCESS);
6369
}
70+
71+
@ApiMapping("/active")
72+
@Auth(role="ROLE_ANONYMOUS")
73+
public ApiResponse getActiveNotifications(@RequestParam(value = "location", defaultValue = "ALL") String locationString) {
74+
String notificationString = "";
75+
List<Notification> notificationList;
76+
if (locationString.equals("ALL")) {
77+
notificationList = notificationRepo.findByIsActive(true);
78+
} else {
79+
notificationList = notificationRepo.findByIsActiveAndLocations(true, NotificationLocation.valueOf(locationString));
80+
81+
}
82+
for (Notification notification : notificationList) {
83+
notificationString += "<p>" + notification.getBody() + "</p>";
84+
}
85+
86+
return new ApiResponse(SUCCESS, "", notificationString);
87+
}
88+
6489
}

0 commit comments

Comments
 (0)