<%#
 Copyright 2022 the original author or authors from the PyHipster project.

 This file is part of the PyHipster project, see https://github.com/pyhipster/generator-pyhipster
 for more information.

 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

      https://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.
-%>
from flask_restx import Resource, fields, Namespace
from domain.User import User
from schema.UserSchema import PublicUserSchema
from domain.Authority import Authority
from schema.Authority import AuthoritySchema
import logging


logging.basicConfig(format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')


public_user_list_ns = Namespace('public-user-resource', path="/users")

public_user_list_schema = PublicUserSchema(many=True)


class PublicUserResourceList(Resource):
    def get(self):
        logging.info("GET request received on PublicUserResourceList")
        all_users = User.get_all_users()
        return public_user_list_schema.dump(all_users), 200


authority_list_ns = Namespace('public-user-resource', path="/authorities")

authority_list_schema = AuthoritySchema(many=True)


class AuthorityResourceList(Resource):
    def get(self):
        logging.info("GET request received on AuthorityResourceList")
        all_users = Authority.get_all_authorities()
        return authority_list_schema.dump(all_users), 200