
package com.jumeirah.api.app.controller;

import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * Hello World Controller
 *
 **/
@Slf4j
@Api(value = "Hello World2", tags = {"APP Hello World2"})
@RestController
@RequestMapping("/app")
//@Module("api-app")
public class AppHelloWorldController {

    /**
     * Hello World
     *
     * @return
     * @throws IOException
     */
    @GetMapping(value = "/world")
    @OperationLog(name = "helloWorld")
    @ApiOperation(value = "helloWorld", response = String.class)
    public ApiResult<String> helloWorld() throws IOException {
        log.debug("Hello World...app");
        return ApiResult.ok("Hello World app");
    }


    @GetMapping(value = "/needRole")
    @OperationLog(name = "needRole")
    @ApiOperation(value = "needRole", response = String.class)
    public ApiResult<String> needRole() throws IOException {
        log.debug("Hello World...app");
        return ApiResult.ok("Hello World app");
    }
    @GetMapping(value = "/needRoleAdmin")
    @OperationLog(name = "needRoleAdmin")
    @ApiOperation(value = "needRoleAdmin", response = String.class)
    @RequiresRoles("app:admin")
    public ApiResult<String> needRoleAdmin() throws IOException {
        log.debug("Hello World...app");
        return ApiResult.ok("Hello World needRoleAdmin");
    }

    @GetMapping(value = "/needRoleAll")
    @OperationLog(name = "needRoleAll")
    @ApiOperation(value = "needRoleAll", response = String.class)
    @RequiresRoles("app:all")
    public ApiResult<String> needRoleAll() throws IOException {
        log.debug("Hello World...app");
        return ApiResult.ok("Hello World needRoleAll");
    }

    @GetMapping(value = "/noRole")
    @OperationLog(name = "noRole")
    @ApiOperation(value = "noRole", response = String.class)
    public ApiResult<String> noRole() throws IOException {
        log.debug("Hello World...app");
        return ApiResult.ok("Hello World app noRole");
    }

}
