Fix empty profile check

This commit is contained in:
Anton Vakhrushev 2019-11-10 22:31:30 +03:00
parent 076e4ca4fb
commit a505b23bb1
3 changed files with 10 additions and 4 deletions

View File

@ -4,8 +4,12 @@ module Dayoff
end end
def profile?(profile_id : ProfileId) : Bool def profile?(profile_id : ProfileId) : Bool
if profile_id.empty?
false
else
Dir.exists? File.join(@base_path, profile_id.to_s) Dir.exists? File.join(@base_path, profile_id.to_s)
end end
end
def profile(profile_id : ProfileId) : Profile def profile(profile_id : ProfileId) : Profile
storage = FileStorage.new File.join(@base_path, profile_id.to_s) storage = FileStorage.new File.join(@base_path, profile_id.to_s)

View File

@ -3,6 +3,10 @@ module Dayoff
def initialize(@id : String) def initialize(@id : String)
end end
def empty? : Bool
@id.empty?
end
def to_s : String def to_s : String
@id @id
end end

View File

@ -7,7 +7,6 @@ class CheckProfileHandler < Kemal::Handler
def call(env) def call(env)
path = env.request.path path = env.request.path
puts "run check profile"
if /^\/api/.match(path) if /^\/api/.match(path)
profile_id = get_profile_id env profile_id = get_profile_id env
if @app.profile? profile_id if @app.profile? profile_id
@ -26,7 +25,6 @@ class CheckProfileHandler < Kemal::Handler
private def get_profile_id(env) : Dayoff::ProfileId private def get_profile_id(env) : Dayoff::ProfileId
profile_id = env.params.query[QUERY_PARAM]? || profile_id = env.params.query[QUERY_PARAM]? ||
env.request.headers[HEADER_PARAM]? || "" env.request.headers[HEADER_PARAM]? || ""
puts "PROFILE_ID", profile_id Dayoff::ProfileId.new profile_id.strip
Dayoff::ProfileId.new profile_id
end end
end end