diff --git a/RestySqlite.http b/RestySqlite.http deleted file mode 100644 index 7ba43b6..0000000 --- a/RestySqlite.http +++ /dev/null @@ -1,6 +0,0 @@ -@RestySqlite_HostAddress = http://localhost:5063 - -GET {{RestySqlite_HostAddress}}/weatherforecast/ -Accept: application/json - -### diff --git a/Utils.cs b/Utils.cs index 30985f5..0d4bbd5 100644 --- a/Utils.cs +++ b/Utils.cs @@ -4,8 +4,35 @@ namespace RestySqlite { public class Utils { - public static dynamic ReadConfig(string key, string? category = null) + public static dynamic? ReadConfig(string key, string? category = null) { + if (!File.Exists("conf.toml")) + { + TomlTable toml = new TomlTable + { + ["title"] = "Configuration file for API", + + ["api"] = + { + ["port"] = 5417, + ["handle"] = "api", + }, + ["sql"] = + { + ["database"] = "" + } + }; + + using(StreamWriter writer = File.CreateText("conf.toml")) + { + toml.WriteTo(writer); + // Remember to flush the data if needed! + writer.Flush(); + } + + Console.WriteLine("Config created please check it."); + return null; + } using(StreamReader reader = File.OpenText("conf.toml")) { TomlTable table = TOML.Parse(reader); diff --git a/WebApi.cs b/WebApi.cs index f439d07..e5aa89e 100644 --- a/WebApi.cs +++ b/WebApi.cs @@ -17,6 +17,12 @@ namespace RestySqlite return; } + if (!File.Exists($"{dbName}.db")) + { + Console.WriteLine($"Database {dbName}.db not found in folder!"); + return; + } + string handle = Utils.ReadConfig("handle", "api"); int port = Utils.ReadConfig("port", "api"); diff --git a/conf.toml b/conf.toml index fe52cca..0520ad1 100644 --- a/conf.toml +++ b/conf.toml @@ -1,8 +1,8 @@ title = "Configuration file for API" [api] - port=5417 - handle="api" +port = 5417 +handle = "api" [sql] - database="test" \ No newline at end of file +database = "test" diff --git a/test.db b/test.db deleted file mode 100644 index 14ac18b..0000000 Binary files a/test.db and /dev/null differ