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 config = require("lapis.config").get()
|
||||
local to_json = require("lapis.util").to_json
|
||||
local db = require("lapis.db")
|
||||
|
||||
local app = lapis.Application()
|
||||
local models = require("models")
|
||||
|
||||
local autoload = require("lapis.util").autoload
|
||||
local models = autoload("models")
|
||||
|
||||
|
||||
app:get("/", function(self)
|
||||
@ -31,6 +34,15 @@ app:match("/spl/:station", function(self)
|
||||
-- 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 track_name = self.params.track
|
||||
-- local track_length = self.params.length
|
||||
@ -40,7 +52,7 @@ app:match("/spl/:station", function(self)
|
||||
local release_year = self.params.year
|
||||
local release_country = self.params.country
|
||||
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
|
||||
local function Split(s, delimiter)
|
||||
@ -51,7 +63,7 @@ app:match("/spl/:station", function(self)
|
||||
return result
|
||||
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_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.")
|
||||
end
|
||||
|
||||
local track = models.Tracks:find({ name = track_name })
|
||||
local track = models.Tracks:find({ unique_name = track_name:lower() })
|
||||
if not track then
|
||||
print("new track: " .. track_name)
|
||||
track = models.Tracks:create({
|
||||
@ -80,21 +92,14 @@ app:match("/spl/:station", function(self)
|
||||
else
|
||||
print("old track.")
|
||||
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
|
||||
-- })
|
||||
local airtime = models.Airtimes:create({
|
||||
airtime = db.format_date(airtime_stamp),
|
||||
tracks = track["id"],
|
||||
stations = station["id"]
|
||||
})
|
||||
|
||||
|
||||
end)
|
||||
|
||||
@ -83,11 +83,11 @@ return {
|
||||
{"created_at", types.time},
|
||||
{"updated_at", types.time},
|
||||
{"airtime", types.time},
|
||||
{"track", types.foreign_key},
|
||||
{"station", types.foreign_key},
|
||||
{"tracks", types.foreign_key},
|
||||
{"stations", types.foreign_key},
|
||||
})
|
||||
create_index("airtimes", "airtime", "track", "station", { unique=true })
|
||||
|
||||
|
||||
create_index("airtimes", "airtime", "tracks", "stations", { unique=true })
|
||||
-- -- releases
|
||||
-- schema.create_table("releases", {
|
||||
-- {"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 --
|
||||
@ -55,12 +55,6 @@ local Model = require("lapis.db.model").Model
|
||||
-- User stuff --
|
||||
-- ---------- --
|
||||
|
||||
--users
|
||||
-- name/email/password/last_login
|
||||
local Users = Model:extend("users", {
|
||||
timestamp = true
|
||||
})
|
||||
|
||||
-- date?
|
||||
-- local Favorite_tracks = Model:extend("favorite_tracks", {
|
||||
-- relations = {
|
||||
@ -76,5 +70,5 @@ local Users = Model:extend("users", {
|
||||
-- local Favorite_labels = Model:extend("favorite_labels", {})
|
||||
|
||||
|
||||
local autoload = require("lapis.util").autoload
|
||||
return autoload("models")
|
||||
-- local autoload = require("lapis.util").autoload
|
||||
-- return autoload("models")
|
||||
@ -6,7 +6,10 @@ local Stations = Model:extend("stations", {
|
||||
-- "station", types.integer
|
||||
-- "name", types.varchar
|
||||
|
||||
timestamp = true
|
||||
timestamp = true,
|
||||
relations = {
|
||||
{"airtimes", has_many = "Airtimes"}
|
||||
}
|
||||
})
|
||||
|
||||
return Stations
|
||||
@ -8,10 +8,9 @@ local Tracks = Model:extend("tracks", {
|
||||
-- "year", types.integer
|
||||
|
||||
timestamp = true,
|
||||
-- relations = {
|
||||
-- {"copies", has_many = "Tracks"},
|
||||
-- {"original", has_one = "Tracks"}
|
||||
-- }
|
||||
relations = {
|
||||
{"airtimes", has_many = "Airtimes"}
|
||||
}
|
||||
})
|
||||
|
||||
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