User event handler to OAuth user
This commit is contained in:
@@ -1,4 +1,21 @@
|
|||||||
package io.bluemoon.testservice.service.user;
|
package io.bluemoon.testservice.service.user;
|
||||||
|
|
||||||
|
import io.bluemoon.testservice.domain.user.User;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.event.TransactionPhase;
|
||||||
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class UserEventListener {
|
public class UserEventListener {
|
||||||
|
|
||||||
|
@Async
|
||||||
|
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, classes = UserServiceImpl.UserCreateEvent.class)
|
||||||
|
public void handle(UserServiceImpl.UserCreateEvent event) throws IOException {
|
||||||
|
User user = event.getUser();
|
||||||
|
|
||||||
|
// oauth
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
package io.bluemoon.testservice.service.user;
|
package io.bluemoon.testservice.service.user;
|
||||||
|
|
||||||
|
import io.bluemoon.testservice.domain.user.User;
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
|
|
||||||
|
User createUser(User user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,44 @@
|
|||||||
package io.bluemoon.testservice.service.user;
|
package io.bluemoon.testservice.service.user;
|
||||||
|
|
||||||
public class UserServiceImpl {
|
import io.bluemoon.testservice.domain.user.User;
|
||||||
|
import io.bluemoon.testservice.domain.user.UserRepository;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.context.ApplicationEventPublisherAware;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl implements UserService, ApplicationEventPublisherAware {
|
||||||
|
|
||||||
|
private UserRepository userRepository;
|
||||||
|
private ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
|
public UserServiceImpl(
|
||||||
|
UserRepository userRepository
|
||||||
|
) {
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User createUser(User user) {
|
||||||
|
|
||||||
|
userRepository.save(user);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||||
|
this.eventPublisher = applicationEventPublisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class UserCreateEvent {
|
||||||
|
@Getter
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
private UserCreateEvent(@NonNull User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user