Worked web app

This commit is contained in:
2019-11-09 19:15:58 +03:00
parent 639888d227
commit 988d4b24b4
12 changed files with 197 additions and 294 deletions

View File

@ -27,11 +27,7 @@ end
get "/api/status" do |env|
profile = app.profile Dayoff::ProfileId.new(env.get("profile_id").to_s)
rem_span = profile.remaining_time now
data = {
started: profile.started?,
hours: rem_span.total_hours.to_i32,
minutes: rem_span.minutes.to_i32,
}
data = Dayoff::StatusResponse.new(profile.started?, rem_span)
env.response.content_type = "application/json"
data.to_json
end

View File

@ -79,4 +79,23 @@ module Dayoff
end
end
end
STATUS_UPTIME = "uptime"
STATUS_OVERTIME = "overtime"
class StatusResponse
JSON.mapping(
started: Bool,
status: String,
hours: Int32,
minutes: Int32,
)
def initialize(@started : Bool, ts : Time::Span)
zero = Time::Span.zero
@status = ts < zero ? STATUS_OVERTIME : STATUS_UPTIME
@hours = ts.abs.total_hours.to_i32
@minutes = ts.abs.minutes.to_i32
end
end
end