package com.flowable.local.work.rest;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.flowable.local.work.service.UserService;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
Examples:
http://localhost:8090/custom-api/current-user-groups
http://localhost:8090/custom-api/user-groups/{userId}
*/

@RestController
@RequestMapping("/custom-api")
@Validated
public class UserController {

    protected final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping(value = {"/current-user-groups"}, produces = {"application/json"})
    public ResponseEntity<ArrayNode> getCurrentUserGroups() {
        return ResponseEntity.ok(this.userService.getCurrentUserGroups());
    }

    @GetMapping(value = {"/user-groups/{userId}"}, produces = {"application/json"})
    public ResponseEntity<ArrayNode> getUserGroups(@PathVariable String userId) {
        return ResponseEntity.ok(this.userService.getUserGroups(userId));
    }
}
