baby steps
This commit is contained in:
parent
4593c78532
commit
5bb78d1366
37
code/app.lua
37
code/app.lua
@ -1,9 +1,12 @@
|
|||||||
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 db = require("lapis.db")
|
||||||
|
|
||||||
local app = lapis.Application()
|
local app = lapis.Application()
|
||||||
local models = require("models")
|
|
||||||
|
local autoload = require("lapis.util").autoload
|
||||||
|
local models = autoload("models")
|
||||||
|
|
||||||
|
|
||||||
app:get("/", function(self)
|
app:get("/", function(self)
|
||||||
@ -31,6 +34,15 @@ app:match("/spl/:station", function(self)
|
|||||||
-- setup --
|
-- setup --
|
||||||
-- ----- --
|
-- ----- --
|
||||||
|
|
||||||
|
local station_id = self.params.station
|
||||||
|
|
||||||
|
local station = models.Stations:find({ station = station_id })
|
||||||
|
if not station then
|
||||||
|
print("unknown station: " .. station_id)
|
||||||
|
else
|
||||||
|
print("This is: " .. station["name"])
|
||||||
|
end
|
||||||
|
|
||||||
local artist_name = self.params.artist
|
local artist_name = self.params.artist
|
||||||
local track_name = self.params.track
|
local track_name = self.params.track
|
||||||
-- local track_length = self.params.length
|
-- local track_length = self.params.length
|
||||||
@ -40,7 +52,7 @@ app:match("/spl/:station", function(self)
|
|||||||
local release_year = self.params.year
|
local release_year = self.params.year
|
||||||
local release_country = self.params.country
|
local release_country = self.params.country
|
||||||
local label_name = self.params.label
|
local label_name = self.params.label
|
||||||
local airtime = self.params.time
|
local airtime_spl = self.params.time
|
||||||
|
|
||||||
-- we have to split the `hr:min:sec` string from SPL
|
-- we have to split the `hr:min:sec` string from SPL
|
||||||
local function Split(s, delimiter)
|
local function Split(s, delimiter)
|
||||||
@ -51,7 +63,7 @@ app:match("/spl/:station", function(self)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
local split_airtime = Split(airtime, ":")
|
local split_airtime = Split(airtime_spl, ":")
|
||||||
local airtime_hr, airtime_min, airtime_sec = split_airtime[1], split_airtime[2], split_airtime[3]
|
local airtime_hr, airtime_min, airtime_sec = split_airtime[1], split_airtime[2], split_airtime[3]
|
||||||
local airtime_stamp = os.time{year=os.date("%Y"), month=os.date("%m"), day=os.date("%d"), hour=airtime_hr, min=airtime_min, sec=airtime_sec}
|
local airtime_stamp = os.time{year=os.date("%Y"), month=os.date("%m"), day=os.date("%d"), hour=airtime_hr, min=airtime_min, sec=airtime_sec}
|
||||||
|
|
||||||
@ -70,7 +82,7 @@ app:match("/spl/:station", function(self)
|
|||||||
print("old artist.")
|
print("old artist.")
|
||||||
end
|
end
|
||||||
|
|
||||||
local track = models.Tracks:find({ name = track_name })
|
local track = models.Tracks:find({ unique_name = track_name:lower() })
|
||||||
if not track then
|
if not track then
|
||||||
print("new track: " .. track_name)
|
print("new track: " .. track_name)
|
||||||
track = models.Tracks:create({
|
track = models.Tracks:create({
|
||||||
@ -81,20 +93,13 @@ app:match("/spl/:station", function(self)
|
|||||||
print("old track.")
|
print("old track.")
|
||||||
end
|
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
|
-- airtime
|
||||||
|
|
||||||
-- local airtime = models.Airtimes:create({
|
local airtime = models.Airtimes:create({
|
||||||
-- airtime = airtime_stamp,
|
airtime = db.format_date(airtime_stamp),
|
||||||
-- tracks = track,
|
tracks = track["id"],
|
||||||
-- stations = station
|
stations = station["id"]
|
||||||
-- })
|
})
|
||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|||||||
@ -83,11 +83,11 @@ return {
|
|||||||
{"created_at", types.time},
|
{"created_at", types.time},
|
||||||
{"updated_at", types.time},
|
{"updated_at", types.time},
|
||||||
{"airtime", types.time},
|
{"airtime", types.time},
|
||||||
{"track", types.foreign_key},
|
{"tracks", types.foreign_key},
|
||||||
{"station", types.foreign_key},
|
{"stations", types.foreign_key},
|
||||||
})
|
})
|
||||||
create_index("airtimes", "airtime", "track", "station", { unique=true })
|
|
||||||
|
|
||||||
|
create_index("airtimes", "airtime", "tracks", "stations", { unique=true })
|
||||||
-- -- releases
|
-- -- releases
|
||||||
-- schema.create_table("releases", {
|
-- schema.create_table("releases", {
|
||||||
-- {"id", types.serial, { unique=true, primary_key=true }},
|
-- {"id", types.serial, { unique=true, primary_key=true }},
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
local Model = require("lapis.db.model").Model
|
-- local Model = require("lapis.db.model").Model
|
||||||
|
|
||||||
-- -- ----------- --
|
-- -- ----------- --
|
||||||
-- -- Track stuff --
|
-- -- Track stuff --
|
||||||
@ -55,12 +55,6 @@ local Model = require("lapis.db.model").Model
|
|||||||
-- User stuff --
|
-- User stuff --
|
||||||
-- ---------- --
|
-- ---------- --
|
||||||
|
|
||||||
--users
|
|
||||||
-- name/email/password/last_login
|
|
||||||
local Users = Model:extend("users", {
|
|
||||||
timestamp = true
|
|
||||||
})
|
|
||||||
|
|
||||||
-- date?
|
-- date?
|
||||||
-- local Favorite_tracks = Model:extend("favorite_tracks", {
|
-- local Favorite_tracks = Model:extend("favorite_tracks", {
|
||||||
-- relations = {
|
-- relations = {
|
||||||
@ -76,5 +70,5 @@ local Users = Model:extend("users", {
|
|||||||
-- local Favorite_labels = Model:extend("favorite_labels", {})
|
-- local Favorite_labels = Model:extend("favorite_labels", {})
|
||||||
|
|
||||||
|
|
||||||
local autoload = require("lapis.util").autoload
|
-- local autoload = require("lapis.util").autoload
|
||||||
return autoload("models")
|
-- return autoload("models")
|
||||||
@ -6,7 +6,10 @@ local Stations = Model:extend("stations", {
|
|||||||
-- "station", types.integer
|
-- "station", types.integer
|
||||||
-- "name", types.varchar
|
-- "name", types.varchar
|
||||||
|
|
||||||
timestamp = true
|
timestamp = true,
|
||||||
|
relations = {
|
||||||
|
{"airtimes", has_many = "Airtimes"}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return Stations
|
return Stations
|
||||||
@ -8,10 +8,9 @@ local Tracks = Model:extend("tracks", {
|
|||||||
-- "year", types.integer
|
-- "year", types.integer
|
||||||
|
|
||||||
timestamp = true,
|
timestamp = true,
|
||||||
-- relations = {
|
relations = {
|
||||||
-- {"copies", has_many = "Tracks"},
|
{"airtimes", has_many = "Airtimes"}
|
||||||
-- {"original", has_one = "Tracks"}
|
}
|
||||||
-- }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return Tracks
|
return Tracks
|
||||||
12
code/models/users.lua
Normal file
12
code/models/users.lua
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
local Model = require("lapis.db.model").Model
|
||||||
|
|
||||||
|
--users
|
||||||
|
-- name/email/password/last_login
|
||||||
|
local Users = Model:extend("users", {
|
||||||
|
-- "email", types.varchar
|
||||||
|
-- "name", types.varchar
|
||||||
|
-- "password", types.varchar
|
||||||
|
-- "last_login", types.time
|
||||||
|
|
||||||
|
timestamp = true
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue
Block a user