aboutsummaryrefslogtreecommitdiff
path: root/api/umosapi.h
blob: fbdc755730b40c150dbb9ed7a1892a59e88dc7a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef UmosapiService_H_
#define UmosapiService_H_

#include <restbed>

#include <nlohmann/json.hpp>

namespace UmosapiService {

struct tag {
     std::string name;
     std::string description;
};

struct Propertie {

    std::string name;
    std::string format;
    std::string type;
    std::string required;
};

struct Definition {

    std::string name;
    std::string type;
    std::vector<Propertie> props;
};

struct Definitions {
    std::vector<Definition> defs;
};

struct HttpWord {
    std::string name;
};

struct Path {
    std::string name;
    std::vector<HttpWord> words;
};

struct Paths {
    std::vector<Path> paths;
};

class Api {
    public:

        Api();
        virtual ~Api() {};

        void init();

        void start(int, int);
        restbed::Service _service;
        nlohmann::json _swagger;
        std::vector<tag> _tags;

    private:
        void desc(std::string route, std::string http_word, const std::function< void ( const std::shared_ptr< restbed::Session > ) >& callback, const std::function< void(int, const std::exception&, std::shared_ptr< restbed::Session >) >& error_callback, tag tags[]);
        void createResource();

        static void retrieveAll( const std::shared_ptr< restbed::Session > session );
        static void addUObject( const std::shared_ptr< restbed::Session > session );
        static void deleteUObject( const std::shared_ptr< restbed::Session > session );
        static void searchUObjectByKeyValue( const std::shared_ptr< restbed::Session > session );
        static void swaggerEndpoint( const std::shared_ptr< restbed::Session > session );
        static void swaggerEndpointResources( const std::shared_ptr< restbed::Session > session );
        static void swaggerEndpointApi( const std::shared_ptr< restbed::Session > session );

        std::shared_ptr< restbed::Resource> _resource;
        Definition _definition;
        Definitions _definitions;
        Path _path;
        Paths _paths;
        void set_path();
        void set_path(std::string route);
        void set_method_handler(std::string http_word, const std::function< void ( const std::shared_ptr< restbed::Session > ) >& callback);
        void set_error_handler(const std::function< void(int, const std::exception&, std::shared_ptr<restbed::Session>) >& error_callback);
        void produce(std::string);
        void consume(std::string);
        void parameter(std::string, std::string, std::string);
        void response(std::string err_code, std::string description, std::string schema, std::string type);
        void publish();
        void basePath(std::string basePath);
        void description(std::string description);
        void title(std::string title);
        void version(std::string version);
        void host(std::string host);
        void atag(std::string name, std::string description);
        void scheme(std::string scheme);

        void definition(std::string name, std::string type);
        void propertie(std::string name, std::string format, std::string type, std::string required);
        void swagger(std::string ui_path, std::string swagger_dir, std::string api_path);

};
}
#endif