getting somewhere

This commit is contained in:
dreamer 2020-09-20 17:11:42 +02:00
parent b53b91efc0
commit 4593c78532
2 changed files with 40 additions and 22 deletions

View File

@ -1,20 +1,18 @@
local lapis = require("lapis") local lapis = require("lapis")
local config = require("lapis.config").get() local config = require("lapis.config").get()
local to_json = require("lapis.util").to_json 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 app = lapis.Application()
local models = require("models")
app:get("/", function()
app:get("/", function(self)
-- return "Welcome to Lapis " .. require("lapis.version") -- return "Welcome to Lapis " .. require("lapis.version")
return config.greeting .. " from port " .. config.postgres.password return config.greeting .. " from port " .. config.postgres.password
end) end)
app:match("/station/", function(self) app:match("/spl/:station", function(self)
-- print( to_json(self.params)) -- print( to_json(self.params))
-- artist=%a& -- artist=%a&
@ -62,25 +60,43 @@ app:match("/station/", function(self)
-- queries -- -- 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 local track = models.Tracks:find({ name = track_name })
-- print("new artist!") if not track then
-- artist = models.Artists:create({ print("new track: " .. track_name)
-- name = artist_name track = models.Tracks:create({
-- }) name = track_name,
-- else unique_name = track_name:lower()
-- print("old artist.") })
-- end else
print("old track.")
end
-- local track = models.Tracks:select("where name = ?", track_name) local station = models.Stations:find({ station = self.params.station })
if not station then
-- if track == nil then print("unknown station: " .. self.params.station)
-- track = models.Tracks:create({ else
-- name = track_name print("This is: " .. station["name"])
-- }) end
-- end
-- airtime
-- local airtime = models.Airtimes:create({
-- airtime = airtime_stamp,
-- tracks = track,
-- stations = station
-- })
end) end)
return app return app

View File

@ -3,12 +3,14 @@ error_log stderr notice;
daemon off; daemon off;
pid logs/nginx.pid; pid logs/nginx.pid;
events { events {
worker_connections 1024; worker_connections 1024;
} }
http { http {
include mime.types; include mime.types;
resolver 127.0.0.11;
server { server {
listen ${{PORT}}; listen ${{PORT}};