diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index db721c1..68b7196 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -992,6 +992,49 @@ getAddUserR = do return $ Bool True Nothing -> return $ Bool False +addUserApi :: Swagger +addUserApi = spec & definitions .~ defs + where + (defs, spec) = runDeclare declareAddUserApi mempty + +declareAddUserApi :: Declare (Definitions Schema) Swagger +declareAddUserApi = do + -- param schemas + response <- declareResponse (Proxy :: Proxy Bool) + + return $ mempty + & paths .~ + fromList [ ("/api/add-user", + mempty & DS.get ?~ (mempty + & parameters .~ [ ] + & produces ?~ MimeList ["application/json"] + & description ?~ "Creates a new user" + & at 200 ?~ Inline response)) + ] + + +userInfoApi :: Swagger +userInfoApi = spec & definitions .~ defs + where + (defs, spec) = runDeclare declareUserInfoApi mempty + +declareUserInfoApi :: Declare (Definitions Schema) Swagger +declareUserInfoApi = do + -- param schemas + response <- declareResponse (Proxy :: Proxy String) + + return $ mempty + & paths .~ + fromList [ ("/api/user-info", + mempty & DS.get ?~ (mempty + & parameters .~ [ ] + & produces ?~ MimeList ["application/json"] + & description ?~ "Returns the identifier of the user" + & at 200 ?~ Inline response)) + ] + + + declareAllSubmissionsApi :: String -> String -> Declare (Definitions Schema) Swagger declareAllSubmissionsApi q d = do -- param schemas diff --git a/Handler/Swagger.hs b/Handler/Swagger.hs index ff51042..d5ecd2f 100644 --- a/Handler/Swagger.hs +++ b/Handler/Swagger.hs @@ -17,6 +17,8 @@ getSwaggerR = return $ toJSON apiDescription apiDescription :: Swagger apiDescription = generalApi + <> addUserApi + <> userInfoApi <> listChallengesApi <> leaderboardApi <> allSubmissionsApi diff --git a/README.md b/README.md index 9de55fc..a5c7df1 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,8 @@ If you create a new user, you need to run `/api/add-info` GET end-point. No parameters are needed it just read the user's data from the token and adds a record to the Gonito database. +You can simulate a front-end by going to `/static/test-gonito-as-backend.html`. + Gonito & git ------------ diff --git a/static/test-gonito-as-backend.html b/static/test-gonito-as-backend.html index 1e012d1..a84d3f9 100644 --- a/static/test-gonito-as-backend.html +++ b/static/test-gonito-as-backend.html @@ -8,7 +8,7 @@ keycloak = new Keycloak({ url: 'http://127.0.0.1:8080/auth', realm: 'master', - clientId: 'myapp', + clientId: 'gonito', "enable-cors": true }) keycloak.init({ @@ -23,7 +23,7 @@ var loadData = function (target) { - var url = 'http://127.0.0.1:3000/api/' + target; + var url = '/api/' + target; var req = new XMLHttpRequest(); req.open('GET', url, true); @@ -60,12 +60,11 @@ } xhr.setRequestHeader('Authorization', 'Bearer ' + keycloak.token); - //xhr.setRequestHeader('Xyz', 'Blabla'); xhr.setRequestHeader('Accept', 'application/json'); return xhr; }; - var url = 'http://127.0.0.1:3000/api/list-challenges'; + var url = '/api/list-challenges'; var method = 'GET'; var xhr = createCORSRequest(method, url); @@ -86,9 +85,10 @@

-

+

-

+