package io.fundrequest.platform.tweb.infrastructure.thymeleaf;

import io.fundrequest.platform.profile.profile.ProfileService;
import io.fundrequest.platform.profile.profile.dto.UserProfile;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Optional;
import java.util.function.Function;

@Component
public class ProfilesExpressionObject {

    private final ProfileService profileService;

    public ProfilesExpressionObject(final ProfileService profileService) {
        this.profileService = profileService;
    }

    public Optional<UserProfile> findByUserId(final String userId) {
        return StringUtils.isBlank(userId) ? Optional.empty() : Optional.ofNullable(profileService.getUserProfile(() -> userId));
    }

    public Function<UserProfile, String> getName() {
        return UserProfile::getName;
    }
}
@@ -229,16 +229,73 @@
 gUtils;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -335,16 +335,16 @@
 ponent;%0A
-
 %0Aimport 
@@ -452,16 +452,115 @@
 ject %7B%0A%0A
+    private static final Logger LOGGER = LoggerFactory.getLogger(ProfilesExpressionObject.class);%0A%0A
     priv
@@ -794,24 +794,42 @@
 g userId) %7B%0A
+        try %7B%0A    
         retu
@@ -946,16 +946,174 @@
 erId));%0A
+        %7D catch (Exception e) %7B%0A            LOGGER.error(%22Error getting profile for: %5C%22%22 + userId + %22%5C%22%22, e);%0A            return Optional.empty();%0A        %7D%0A%0A
     %7D%0A%0A 

handle exceptions