2017-08-18 16:08:27 +07:00
|
|
|
package io.spring.application;
|
2017-08-16 14:58:51 +07:00
|
|
|
|
2017-08-18 16:08:27 +07:00
|
|
|
import io.spring.application.data.ProfileData;
|
|
|
|
import io.spring.application.data.UserData;
|
|
|
|
import io.spring.infrastructure.mybatis.readservice.UserReadService;
|
2017-08-16 14:58:51 +07:00
|
|
|
import io.spring.core.user.User;
|
2017-08-18 16:08:27 +07:00
|
|
|
import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService;
|
2017-08-16 14:58:51 +07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|