Beispiel #1
0
        [FunctionName(HTTP.Endpoints.GET)]  /* API Endpoint: /api/get?type=players&id=1, /api/get?type=systems&id=22 */
        public static async Task <string> Get([HttpTrigger(AuthorizationLevel.Anonymous, HTTP.GET, Route = HTTP.Endpoints.GET)] HttpRequest req)
        {
            try {
                /* Returns formatted result of selection query */

                string type = req.Query[HTTP.Endpoints.Parameters.TYPE];
                string id   = req.Query[HTTP.Endpoints.Parameters.ID];

                switch (type)
                {
                case Ships.ALIAS:
                    return(SQLHandler.Select(new Dictionary <string, string> {
                        { SQL.COLUMNS, SQL.ALL },
                        { SQL.TABLE, Ships.ALIAS },
                        { SQL.CONDITION, Ships.ID + SQL.EQUALS + id }
                    }));

                case Systems.ALIAS:
                    return(String.Format(
                               "{{\n\t\"system\": \"{0}\",\n\t\"planets\": \"{1}\",\n\t\"asteroids\": \"{2}\",\n\t\"ships\": \"{3}\"\n}}",
                               SQLHandler.Select(SQL.ALL, Systems.ALIAS, SQLHandler.Equals(Systems.ID, id)),
                               SQLHandler.Select(SQL.ALL, Planets.ALIAS, SQLHandler.Equals(Planets.SYSTEM_ID, id)),
                               SQLHandler.Select(SQL.ALL, Asteroids.ALIAS, SQLHandler.Equals(Asteroids.SYSTEM_ID, id)),
                               SQLHandler.Select(SQL.ALL, Ships.ALIAS, SQLHandler.Equals(Ships.SYSTEM_ID, id))
                               ));

                case Galaxies.ALIAS:
                    //We only want the:
                    //  - System locations
                    //  - System connections
                    //  - any parameters relevant to rendering the two items above
                    return(String.Format(
                               "{{\n\t\"galaxy\": \"{0}\",\n\t\"systems\": \"{1}\"\n}}", //,\n\t\"system_connections\": \"{2}\"\n}}",
                               SQLHandler.Select(SQL.ALL, Galaxies.ALIAS, SQLHandler.Equals(Galaxies.ID, id)),
                               SQLHandler.Select(SQL.ALL, Systems.ALIAS, SQLHandler.Equals(Systems.GALAXY_ID, id))
                               ));

                    //Will also likely want
                    //All System's position_x, position_y
                    //All Systems' links

                    return(String.Format("{id:1, seed:99, systems: { id:1, seed:99, connected_systems: {1, 2, 3, 4}, position_x: 123, position_y: 234 } }"));

                case "fun-facts":
                    return("to be implemented");
                    // return ExecuteQuery (
                    // "To be determined... complex, fun facts sort of queries to satisfy requirements for DB project"
                    // );
                }
            } catch (Exception ex) {
                return(ex.ToString());
            }
            return(new InvalidOperationException().ToString());
        }