// Path: src/main/java/se/omegapoint/facepalm/client/adapters/UserAdapter.java
// @Adapter
// public class UserAdapter {
// 
//     private final UserService userService;
// 
//     @Autowired
//     public UserAdapter(final UserService userService) {
//         this.userService = notNull(userService);
//     }
// 
//     public OperationResult registerNewUser(final RegisterCredentials credentials) {
//         notNull(credentials);
// 
//         final Result<UserSuccess, UserFailure> result = userService.registerUser(credentials.getUsername(), credentials.getEmail(), credentials.getFirstname(),
//                 credentials.getLastname(), credentials.getPassword());
//         return result.isSuccess() ? success() : failure("User already exists"); // TODO [dh] Proper error mapping!
//     }
// 
//     public Optional<Profile> profileFor(final String username) {
//         final Result<User, UserFailure> result = userService.getUserWith(username);
//         return result.isSuccess() ? Optional.of(new Profile(result.success())) : Optional.empty();
//     }
// 
//     public Profile profileForCurrentUser() {
//         final AuthenticatedUser authenticatedUser = (AuthenticatedUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//         final Result<User, UserFailure> result = userService.getUserWith(authenticatedUser.userName);
//         return new Profile(result.success());
//     }
// }
// 
// Path: src/main/java/se/omegapoint/facepalm/client/models/Profile.java
// public class Profile {
//     public String email;
//     public String username;
//     public String firstname;
//     public String lastname;
// 
//     public Profile(final User user) {
//         notNull(user);
//         this.username = user.username;
//         this.email = user.email;
//         this.firstname = user.firstname;
//         this.lastname = user.lastname;
//     }
// }


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import se.omegapoint.facepalm.client.adapters.UserAdapter;
import se.omegapoint.facepalm.client.models.Profile;
import java.util.Optional;
import static org.apache.commons.lang3.Validate.notNull;
/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package se.omegapoint.facepalm.client.controllers;




@Controller
public class ProfileController {
    public static final String PATH = "/profile";

// Path: src/main/java/se/omegapoint/facepalm/client/adapters/UserAdapter.java
// @Adapter
// public class UserAdapter {
// 
//     private final UserService userService;
// 
//     @Autowired
//     public UserAdapter(final UserService userService) {
//         this.userService = notNull(userService);
//     }
// 
//     public OperationResult registerNewUser(final RegisterCredentials credentials) {
//         notNull(credentials);
// 
//         final Result<UserSuccess, UserFailure> result = userService.registerUser(credentials.getUsername(), credentials.getEmail(), credentials.getFirstname(),
//                 credentials.getLastname(), credentials.getPassword());
//         return result.isSuccess() ? success() : failure("User already exists"); // TODO [dh] Proper error mapping!
//     }
// 
//     public Optional<Profile> profileFor(final String username) {
//         final Result<User, UserFailure> result = userService.getUserWith(username);
//         return result.isSuccess() ? Optional.of(new Profile(result.success())) : Optional.empty();
//     }
// 
//     public Profile profileForCurrentUser() {
//         final AuthenticatedUser authenticatedUser = (AuthenticatedUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//         final Result<User, UserFailure> result = userService.getUserWith(authenticatedUser.userName);
//         return new Profile(result.success());
//     }
// }
// 
// Path: src/main/java/se/omegapoint/facepalm/client/models/Profile.java
// public class Profile {
//     public String email;
//     public String username;
//     public String firstname;
//     public String lastname;
// 
//     public Profile(final User user) {
//         notNull(user);
//         this.username = user.username;
//         this.email = user.email;
//         this.firstname = user.firstname;
//         this.lastname = user.lastname;
//     }
// }


// Path: src/main/java/se/omegapoint/facepalm/client/controllers/ProfileController.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import se.omegapoint.facepalm.client.adapters.UserAdapter;
import se.omegapoint.facepalm.client.models.Profile;
import java.util.Optional;
import static org.apache.commons.lang3.Validate.notNull;

/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package se.omegapoint.facepalm.client.controllers;




@Controller
public class ProfileController {
    public static final String PATH = "/profile";

    private final UserAdapter userAdapter;