/*
 * Copyright (c) 2013 Lucas Holt
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

package com.justjournal.ctl.api;

import com.justjournal.model.Journal;
import com.justjournal.model.User;
import com.justjournal.repository.UserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author Lucas Holt
 */
@Slf4j
@RestController
@RequestMapping("/api/members")
public class MembersController {

    private final UserRepository userRepository;

    @Autowired
    public MembersController(final UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    /**
     * All moods usable by blogs
     *
     * @return mood list
     */
    @Transactional
    @Cacheable("members")
    @RequestMapping(method = RequestMethod.GET, headers = "Accept=*/*", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResponseEntity<List<User>> list() {

        try {
            final List<User> publicMembers = userRepository.getPublicUsers();
            return ResponseEntity.ok().eTag(Integer.toString(publicMembers.hashCode())).body(publicMembers);
        } catch (final Exception e) {
            log.error(e.getMessage(), e);
        }

         return new ResponseEntity<>(Collections.<User>emptyList(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

@@ -1394,33 +1394,47 @@
 com.
-justjournal.model.Journal
+fasterxml.jackson.annotation.JsonIgnore
 ;%0Aim
@@ -1516,16 +1516,33 @@
 sitory;%0A
+import lombok.*;%0A
 import l
@@ -2151,22 +2151,23 @@
 ava.
-util.ArrayList
+io.Serializable
 ;%0Aim
@@ -2181,26 +2181,25 @@
 va.util.
-Collection
+ArrayList
 ;%0Aimport
@@ -2843,18 +2843,26 @@
 ty%3CList%3C
-Us
+PublicMemb
 er%3E%3E lis
@@ -2915,56 +2915,290 @@
 er%3E 
-publicMembers = userRepository.getPublicUsers();
+users = userRepository.getPublicUsers();%0A            final List%3CPublicMember%3E publicMembers = new ArrayList%3C%3E();%0A            for (final User user : users) %7B%0A                publicMembers.add(new PublicMember(user.getUsername(), user.getFirstName(), user.getSince()));%0A            %7D%0A
 %0A   
@@ -3444,18 +3444,26 @@
 ctions.%3C
-Us
+PublicMemb
 er%3Eempty
@@ -3510,11 +3510,347 @@
 );%0A    %7D
+%0A%0A    @EqualsAndHashCode%0A    @Getter%0A    @Setter%0A    @NoArgsConstructor%0A    @AllArgsConstructor%0A    class PublicMember implements Serializable %7B%0A%0A        @JsonIgnore%0A        private static final long serialVersionUID = -877596710940098083L;%0A%0A        private String username;%0A        private String name;%0A        private int since;%0A    %7D
 %0A%7D%0A

stop information leakage.