This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Getter | |
public enum NotificationTopic { | |
ITEM_SAVED, | |
ITEM_DELETED; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
@RequiredArgsConstructor | |
public class ItemService { | |
private final NotificationService notificationService; | |
... | |
/** | |
* Listen to all saved items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping(value = "/items") | |
public class ItemController { | |
private final ItemService itemService; | |
... | |
@GetMapping("/events") | |
public Flux<ServerSentEvent<Event>> listenToEvents() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
@RequiredArgsConstructor | |
@Slf4j | |
public class NotificationService { | |
private final ConnectionFactory connectionFactory; | |
private final Set<NotificationTopic> watchedTopics = new HashSet<>(); | |
private PostgresqlConnection connection; | |
private ObjectMapper objectMapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION notify_item_deleted() | |
RETURNS TRIGGER | |
AS | |
BEGIN | |
PERFORM pg_notify('ITEM_DELETED', row_to_json(OLD)::text); | |
RETURN NULL; | |
END; | |
CREATE TRIGGER item_deleted_trigger | |
AFTER DELETE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION notify_item_saved() | |
RETURNS TRIGGER | |
AS | |
BEGIN | |
PERFORM pg_notify('ITEM_SAVED', row_to_json(NEW)::text); | |
RETURN NULL; | |
END; | |
CREATE TRIGGER item_saved_trigger | |
AFTER INSERT OR UPDATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Data | |
@Accessors(chain = true) | |
public class ItemPatchResource { | |
private Optional<@NotBlank @Size(max=4000) String> description; | |
private Optional<@NotNull ItemStatus> status; | |
private Optional<Long> assigneeId; | |
private Optional<Set<Long>> tagIds; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping(value = "/items") | |
public class ItemController { | |
private final ItemService itemService; | |
private final ItemMapper itemMapper; | |
... | |
@ApiOperation("Patch an existing item following the patch merge RCF (https://tools.ietf.org/html/rfc7396)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
@RequiredArgsConstructor | |
public class ItemService { | |
private final ItemRepository itemRepository; | |
private final ItemTagRepository itemTagRepository; | |
private final TagMapper tagMapper; | |
/** | |
* Update an Item |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Data | |
@Accessors(chain = true) | |
public class ItemUpdateResource { | |
@NotBlank | |
@Size(max=4000) | |
private String description; | |
@NotNull | |
private ItemStatus status; |
NewerOlder