Skip to content

Commit 546c126

Browse files
authored
Merge pull request #99 from AZIRARM/feat/redis-notifications
Feat/redis notifications
2 parents 355f7b2 + 166207e commit 546c126

30 files changed

+507
-281
lines changed

itexpert-content-core/src/main/java/com/itexpert/content/core/endpoints/NodeEndPoint.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,17 @@ public Flux<Node> deploy(@PathVariable String code,
365365
log.debug("[EXPORT] Node to import: code={}, status={}",
366366
node.getCode(), node.getStatus());
367367

368+
node.setModifiedBy(authentication.getPrincipal().toString());
369+
368370
// Log chaque ContentNode à l'intérieur de Node
369371
Optional.ofNullable(node.getContents()).orElse(List.of())
370-
.forEach(contentNode -> log.debug(
372+
.forEach(contentNode -> {
373+
log.debug(
371374
"[EXPORT] ContentNode: code={}, status={}",
372-
contentNode.getCode(), contentNode.getStatus()));
375+
contentNode.getCode(), contentNode.getStatus());
376+
377+
contentNode.setModifiedBy(authentication.getPrincipal().toString());
378+
});
373379
});
374380

375381
return this.importNodes(nodes, environmentCode, false);

itexpert-content-core/src/main/java/com/itexpert/content/core/endpoints/NotificationEndPoint.java

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.extern.slf4j.Slf4j;
77
import org.springframework.http.HttpStatus;
88
import org.springframework.http.ResponseEntity;
9+
import org.springframework.security.core.Authentication;
910
import org.springframework.web.bind.annotation.*;
1011
import reactor.core.publisher.Flux;
1112
import reactor.core.publisher.Mono;
@@ -19,75 +20,25 @@
1920
public class NotificationEndPoint {
2021
private final NotificationHandler notificationHandler;
2122

22-
@GetMapping("/")
23-
public Flux<Notification> findAll() {
24-
return notificationHandler.findAll();
23+
@GetMapping(value = "/unreaded")
24+
public Flux<Notification> unreadedByUserId(@RequestParam(name = "currentPage", required = true) Integer currentPage,
25+
@RequestParam(name = "limit", required = false, defaultValue = "50") Integer limit,
26+
Authentication authentication) {
27+
return notificationHandler.unreadedByUser(authentication.getPrincipal().toString(), currentPage, limit);
2528
}
2629

27-
@GetMapping(value = "/id/{id}")
28-
public Mono<ResponseEntity<Notification>> findById(@PathVariable String id) {
29-
return notificationHandler.findById(UUID.fromString(id))
30-
.map(ResponseEntity::ok)
31-
.defaultIfEmpty(new ResponseEntity<>(HttpStatus.NOT_FOUND));
32-
33-
}
34-
35-
// @RolesAllowed("ADMIN")
36-
@PostMapping("/")
37-
public Mono<ResponseEntity<Notification>> save(@RequestBody(required = true) Notification notification) {
38-
return notificationHandler.save(notification)
39-
.map(ResponseEntity::ok);
40-
}
41-
42-
@DeleteMapping(value = "/id/{id}")
43-
public Mono<ResponseEntity<Boolean>> delete(@PathVariable String id) {
44-
return notificationHandler.delete(UUID.fromString(id))
45-
.map(ResponseEntity::ok);
46-
}
47-
48-
@GetMapping(value = "/user/id/{userId}/count/unreaded")
49-
public Mono<ResponseEntity<Long>> countUnreadedByUserId(@PathVariable String userId) {
50-
return notificationHandler.countUnreaded(userId)
51-
.map(ResponseEntity::ok)
52-
.defaultIfEmpty(new ResponseEntity<>(HttpStatus.NOT_FOUND));
53-
54-
}
55-
56-
@GetMapping(value = "/user/id/{userId}/unreaded")
57-
public Flux<Notification> unreadedByUserId(@PathVariable String userId,
58-
@RequestParam(name = "currentPage", required = true) Integer currentPage,
59-
@RequestParam(name = "limit", required = false, defaultValue = "50") Integer limit) {
60-
return notificationHandler.unreadedByUserId(userId, currentPage, limit);
61-
}
62-
@GetMapping(value = "/user/id/{userId}/readed")
63-
public Flux<Notification> readedByUserId(@PathVariable String userId,
64-
@RequestParam(name = "currentPage", required = true) Integer currentPage,
65-
@RequestParam(name = "limit", required = false, defaultValue = "50") Integer limit) {
66-
return notificationHandler.readedByUserId(userId, currentPage, limit);
67-
}
68-
69-
@PostMapping(value = "/id/{notificationId}/user/id/{userId}/markread")
70-
public Mono<Notification> markread(@PathVariable UUID notificationId, @PathVariable String userId) {
71-
return notificationHandler.markread(notificationId, userId);
72-
}
73-
74-
@PostMapping(value = "/id/{notificationId}/user/id/{userId}/markunread")
75-
public Mono<Notification> markunread(@PathVariable UUID notificationId, @PathVariable String userId) {
76-
return notificationHandler.markunread(notificationId, userId);
77-
}
78-
79-
@PostMapping(value = "/user/id/{userId}/markAllAsRead")
80-
public Flux<Notification> markAllAsRead(@PathVariable String userId) {
81-
return notificationHandler.markAllAsRead(userId);
30+
@GetMapping(value = "/countUnreaded")
31+
public Mono<Long> countUnreaded(Authentication authentication) {
32+
return notificationHandler.countUnreaded(authentication.getPrincipal().toString());
8233
}
8334

84-
@GetMapping(value = "/user/id/{userId}/countUnreaded")
85-
public Mono<Long> countUnreaded(@PathVariable String userId) {
86-
return notificationHandler.countUnreaded(userId);
35+
@PostMapping(value = "/id/{notificationId}/markread")
36+
public Mono<Notification> markread(@PathVariable UUID notificationId, Authentication authentication) {
37+
return notificationHandler.markRead(authentication.getPrincipal().toString(), notificationId);
8738
}
8839

89-
@GetMapping(value = "/user/id/{userId}/countReaded")
90-
public Mono<Long> countReaded(@PathVariable String userId) {
91-
return notificationHandler.countReaded(userId);
40+
@PostMapping(value = "/markAllAsRead")
41+
public Flux<Notification> markAllAsRead(Authentication authentication) {
42+
return notificationHandler.markAllAsRead(authentication.getPrincipal().toString());
9243
}
9344
}

itexpert-content-core/src/main/java/com/itexpert/content/core/handlers/AccessRoleHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Flux<AccessRole> saveAll(List<AccessRole> roles) {
6464
public Mono<AccessRole> notify(AccessRole model, NotificationEnum type) {
6565
return Mono.just(model).flatMap(accessRole -> {
6666
return notificationHandler
67-
.create(type, accessRole.getCode(), null, "ACCESS_ROLE", model.getCode(), null)
67+
.create(type, accessRole.getCode(), null, "ACCESS_ROLE", model.getCode(), null, Boolean.TRUE)
6868
.map(notification -> model);
6969
});
7070
}

itexpert-content-core/src/main/java/com/itexpert/content/core/handlers/ContentNodeHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ public Mono<ContentNode> notify(ContentNode model, NotificationEnum type) {
274274
model.getModifiedBy(),
275275
"CONTENT_NODE",
276276
model.getCode(),
277-
model.getVersion())
277+
model.getVersion(),
278+
Boolean.TRUE)
278279
.map(notification -> contentNode);
279280
});
280281
}

itexpert-content-core/src/main/java/com/itexpert/content/core/handlers/EnvironmentHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Mono<Environment> findByNodeCode(String nodeParentCode) {
8484
public Mono<Environment> notify(Environment model, NotificationEnum type) {
8585
return Mono.just(model).flatMap(environment -> {
8686
return notificationHandler
87-
.create(type, environment.getCode(), null, "ENVIRONMENT", model.getCode(), null)
87+
.create(type, environment.getCode(), null, "ENVIRONMENT", model.getCode(), null, Boolean.TRUE)
8888
.map(notification -> model);
8989
});
9090
}

itexpert-content-core/src/main/java/com/itexpert/content/core/handlers/FeedbackHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private Flux<Feedback> getDistinctContentCodesWithEvaluations(UserPost userPost)
140140
public Mono<Feedback> notify(Feedback model, NotificationEnum type) {
141141
return Mono.just(model).flatMap(feedback -> {
142142
return notificationHandler
143-
.create(type, feedback.getContentCode() + ", evaluation : " + feedback.getEvaluation(), null, "FEEDBACK", model.getContentCode(), null)
143+
.create(type, feedback.getContentCode() + ", evaluation : " + feedback.getEvaluation(), null, "FEEDBACK", model.getContentCode(), null, Boolean.TRUE)
144144
.map(notification -> model);
145145
});
146146
}

itexpert-content-core/src/main/java/com/itexpert/content/core/handlers/LanguageHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Mono<Language> save(Language language) {
4444
public Mono<Language> notify(Language model, NotificationEnum type) {
4545
return Mono.just(model).flatMap(language -> {
4646
return notificationHandler
47-
.create(type, language.getCode(), null, "LANGUAGE", model.getCode(), null)
47+
.create(type, language.getCode(), null, "LANGUAGE", model.getCode(), null, Boolean.TRUE)
4848
.map(notification -> model);
4949
});
5050
}

itexpert-content-core/src/main/java/com/itexpert/content/core/handlers/NodeHandler.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ public Mono<Node> notify(Node model, NotificationEnum type) {
333333
model.getModifiedBy(),
334334
"NODE",
335335
model.getCode(),
336-
model.getVersion())
336+
model.getVersion(),
337+
Boolean.TRUE)
337338
.map(notification -> node);
338339
});
339340
}
@@ -691,17 +692,27 @@ public Mono<Boolean> publishVersion(String code, String version, String user) {
691692
published.setStatus(StatusEnum.ARCHIVE);
692693
published.setModifiedBy(user);
693694
published.setModificationDate(Instant.now().toEpochMilli());
694-
return nodeRepository.save(published);
695+
696+
return nodeRepository.save(published)
697+
.flatMap(saved ->
698+
this.notify(nodeMapper.fromEntity(saved), NotificationEnum.ARCHIVING)
699+
)
700+
.thenReturn(published);
695701
})
696702
.then(Mono.defer(() -> {
697703
archived.setStatus(StatusEnum.PUBLISHED);
698704
archived.setModifiedBy(user);
699705
archived.setModificationDate(Instant.now().toEpochMilli());
700-
return nodeRepository.save(archived);
706+
707+
return nodeRepository.save(archived)
708+
.flatMap(saved ->
709+
this.notify(nodeMapper.fromEntity(saved), NotificationEnum.DEPLOYMENT_VERSION)
710+
)
711+
.thenReturn(archived);
701712
}))
702713
.thenReturn(true)
703714
)
704-
.defaultIfEmpty(false); // si la version n’existe pas
715+
.defaultIfEmpty(false);
705716
}
706717

707718
}

0 commit comments

Comments
 (0)