TagService.publish
This commit is contained in:
parent
ea0aa3e00a
commit
3970a9a142
@ -1,8 +1,10 @@
|
|||||||
package de.ph87.home.tag;
|
package de.ph87.home.tag;
|
||||||
|
|
||||||
|
import de.ph87.home.common.crud.CrudAction;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -14,9 +16,21 @@ public class TagService {
|
|||||||
|
|
||||||
private final TagRepository tagRepository;
|
private final TagRepository tagRepository;
|
||||||
|
|
||||||
|
private final ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public TagDto create(final @NonNull String slug, @NonNull final String name) {
|
public TagDto create(final @NonNull String slug, @NonNull final String name) {
|
||||||
return new TagDto(tagRepository.save(new Tag(slug, name)));
|
final Tag tag = tagRepository.save(new Tag(slug, name));
|
||||||
|
return publish(tag, CrudAction.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@SuppressWarnings("SameParameterValue")
|
||||||
|
private TagDto publish(@NonNull final Tag tag, @NonNull final CrudAction action) {
|
||||||
|
final TagDto dto = new TagDto(tag);
|
||||||
|
log.info("Tag {}: {}", action, dto);
|
||||||
|
applicationEventPublisher.publishEvent(dto);
|
||||||
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user