|
7 | 7 | import static edu.tamu.framework.enums.BusinessValidationType.NONEXISTS; |
8 | 8 | import static edu.tamu.framework.enums.BusinessValidationType.UPDATE; |
9 | 9 |
|
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import org.apache.tools.ant.taskdefs.condition.Not; |
10 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | +import org.springframework.web.bind.annotation.RequestParam; |
11 | 16 | import org.springframework.web.bind.annotation.RestController; |
12 | 17 |
|
| 18 | +import edu.tamu.app.enums.NotificationLocation; |
13 | 19 | import edu.tamu.app.model.Notification; |
14 | 20 | import edu.tamu.app.model.repo.NotificationRepo; |
15 | 21 | import edu.tamu.framework.aspect.annotation.ApiMapping; |
@@ -61,4 +67,23 @@ public ApiResponse remove(@ApiValidatedModel Notification notification) { |
61 | 67 | notificationRepo.delete(notification); |
62 | 68 | return new ApiResponse(SUCCESS); |
63 | 69 | } |
| 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 | + |
64 | 89 | } |
0 commit comments