package net.thecamaras.controllers;


import net.thecamaras.domain.User;
import net.thecamaras.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by rcamara on 1/14/2016.
 */
@RestController
@RequestMapping(path = "/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/{flickrId}", method = RequestMethod.GET)
    public User getUser(@PathVariable String flickrId) {
        User user = userService.getUser(flickrId);
        if (user == null) {
            throw new IllegalArgumentException("Unknown flickrId: " + flickrId);
        }
        return user;
    }

    @RequestMapping(value = "/{flickrId}/add", method = RequestMethod.GET)
    public User addUser(@PathVariable String flickrId) {
        return userService.addUser(flickrId);
    }

    @RequestMapping(value = "/{flickrId}/ignoreSize/{value}", method = RequestMethod.GET)
    public User setIgnoreSize(@PathVariable String flickrId, @PathVariable Boolean ignoreSize) {
        User user = getUser(flickrId);
        user.setIgnoreSizeCheck(ignoreSize);
        return userService.save(user);
    }

    @RequestMapping(value = "/{flickrId}/autoDownload/{value}", method = RequestMethod.GET)
    public User setAutoDownload(@PathVariable String flickrId, @PathVariable boolean autoDownload) {
        User user = getUser(flickrId);
        user.setAutoDownload(autoDownload);
        return userService.save(user);
    }

    @RequestMapping(value = "/{flickrId}/autoGroup/{value}", method = RequestMethod.GET)
    public User setAutoDownloadGroup(@PathVariable String flickrId, @PathVariable boolean autoDownloadGroup) {
        User user = getUser(flickrId);
        user.setAutoDownloadGroup(autoDownloadGroup);
        return userService.save(user);
    }
}

@@ -1162,20 +1162,25 @@
 reSize/%7B
-valu
+ignoreSiz
 e%7D%22, met
@@ -1283,9 +1283,9 @@
 ble 
-B
+b
 oole
@@ -1486,21 +1486,28 @@
 wnload/%7B
-value
+autoDownload
 %7D%22, meth
@@ -1812,21 +1812,33 @@
 oGroup/%7B
-value
+autoDownloadGroup
 %7D%22, meth

fix bugs in user management