spring-boot-realworld-examp.../src/main/java/io/spring/application/profile/ProfileQueryService.java

37 lines
1.3 KiB
Java
Raw Normal View History

2017-08-16 14:58:51 +07:00
package io.spring.application.profile;
import io.spring.application.user.UserData;
import io.spring.application.user.UserReadService;
import io.spring.core.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class ProfileQueryService {
private UserReadService userReadService;
private UserRelationshipQueryService userRelationshipQueryService;
@Autowired
public ProfileQueryService(UserReadService userReadService, UserRelationshipQueryService userRelationshipQueryService) {
this.userReadService = userReadService;
this.userRelationshipQueryService = userRelationshipQueryService;
}
public Optional<ProfileData> findByUsername(String username, User currentUser) {
UserData userData = userReadService.findByUsername(username);
if (userData == null) {
return Optional.empty();
} else {
ProfileData profileData = new ProfileData(
userData.getId(),
userData.getUsername(),
userData.getBio(),
userData.getImage(),
userRelationshipQueryService.isUserFollowing(currentUser.getId(), userData.getId()));
return Optional.of(profileData);
}
}
}