diff --git a/code/app.lua b/code/app.lua index c9701ce..981f4e4 100644 --- a/code/app.lua +++ b/code/app.lua @@ -1,20 +1,18 @@ local lapis = require("lapis") local config = require("lapis.config").get() local to_json = require("lapis.util").to_json -local models = require("models") - --- print("models has type: " .. type(models)) --- print(to_json(models)) local app = lapis.Application() +local models = require("models") -app:get("/", function() + +app:get("/", function(self) -- return "Welcome to Lapis " .. require("lapis.version") return config.greeting .. " from port " .. config.postgres.password end) -app:match("/station/", function(self) +app:match("/spl/:station", function(self) -- print( to_json(self.params)) -- artist=%a& @@ -62,25 +60,43 @@ app:match("/station/", function(self) -- queries -- -- ------- -- - -- local artist = models.Artists:select("where name = ?", artist_name) + local artist = models.Artists:find({ name = artist_name }) + if not artist then + print("new artist: " .. artist_name) + artist = models.Artists:create({ + name = artist_name + }) + else + print("old artist.") + end - -- if not artist then - -- print("new artist!") - -- artist = models.Artists:create({ - -- name = artist_name - -- }) - -- else - -- print("old artist.") - -- end + local track = models.Tracks:find({ name = track_name }) + if not track then + print("new track: " .. track_name) + track = models.Tracks:create({ + name = track_name, + unique_name = track_name:lower() + }) + else + print("old track.") + end - -- local track = models.Tracks:select("where name = ?", track_name) - - -- if track == nil then - -- track = models.Tracks:create({ - -- name = track_name - -- }) - -- end + local station = models.Stations:find({ station = self.params.station }) + if not station then + print("unknown station: " .. self.params.station) + else + print("This is: " .. station["name"]) + end + -- airtime + + -- local airtime = models.Airtimes:create({ + -- airtime = airtime_stamp, + -- tracks = track, + -- stations = station + -- }) + + end) return app diff --git a/code/nginx.conf b/code/nginx.conf index f7cd845..852ef70 100644 --- a/code/nginx.conf +++ b/code/nginx.conf @@ -3,12 +3,14 @@ error_log stderr notice; daemon off; pid logs/nginx.pid; + events { worker_connections 1024; } http { include mime.types; + resolver 127.0.0.11; server { listen ${{PORT}};