forked from Microservice-API-Patterns/LakesideMutual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationInformationHolder.java
37 lines (32 loc) · 1.8 KB
/
NotificationInformationHolder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.lakesidemutual.customermanagement.interfaces;
import java.util.List;
import java.util.stream.Collectors;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lakesidemutual.customermanagement.domain.interactionlog.InteractionLogService;
import com.lakesidemutual.customermanagement.interfaces.dtos.NotificationDto;
/**
* This REST controller gives clients access the current list of unacknowledged chat notifications. It is an example of the
* <i>Information Holder Resource</i> pattern. This particular one is a special type of information holder called <i>Master Data Holder</i>.
*
* @see <a href="https://www.microservice-api-patterns.org/patterns/responsibility/endpointRoles/InformationHolderResource">Information Holder Resource</a>
* @see <a href="https://www.microservice-api-patterns.org/patterns/responsibility/informationHolderEndpointTypes/MasterDataHolder">Master Data Holder</a>
*/
@RestController
@RequestMapping("/notifications")
public class NotificationInformationHolder {
@Autowired
private InteractionLogService interactionLogService;
@Operation(summary = "Get a list of all unacknowledged notifications.")
@GetMapping
public ResponseEntity<List<NotificationDto>> getNotifications() {
final List<NotificationDto> notifications = interactionLogService.getNotifications().stream()
.map(notification -> new NotificationDto(notification.getCustomerId(), notification.getUsername(), notification.getCount()))
.collect(Collectors.toList());
return ResponseEntity.ok(notifications);
}
}