From a505b23bb120cff6af7a7f347953292c7e0ffde9 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Sun, 10 Nov 2019 22:31:30 +0300 Subject: [PATCH] Fix empty profile check --- src/dayoff/app.cr | 6 +++++- src/dayoff/profile.cr | 4 ++++ src/handlers.cr | 4 +--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dayoff/app.cr b/src/dayoff/app.cr index 9dd5641..0ba57d0 100644 --- a/src/dayoff/app.cr +++ b/src/dayoff/app.cr @@ -4,7 +4,11 @@ module Dayoff end def profile?(profile_id : ProfileId) : Bool - Dir.exists? File.join(@base_path, profile_id.to_s) + if profile_id.empty? + false + else + Dir.exists? File.join(@base_path, profile_id.to_s) + end end def profile(profile_id : ProfileId) : Profile diff --git a/src/dayoff/profile.cr b/src/dayoff/profile.cr index 684961d..b7ae78d 100644 --- a/src/dayoff/profile.cr +++ b/src/dayoff/profile.cr @@ -3,6 +3,10 @@ module Dayoff def initialize(@id : String) end + def empty? : Bool + @id.empty? + end + def to_s : String @id end diff --git a/src/handlers.cr b/src/handlers.cr index bcfc7e9..1c7a56f 100644 --- a/src/handlers.cr +++ b/src/handlers.cr @@ -7,7 +7,6 @@ class CheckProfileHandler < Kemal::Handler def call(env) path = env.request.path - puts "run check profile" if /^\/api/.match(path) profile_id = get_profile_id env if @app.profile? profile_id @@ -26,7 +25,6 @@ class CheckProfileHandler < Kemal::Handler private def get_profile_id(env) : Dayoff::ProfileId profile_id = env.params.query[QUERY_PARAM]? || env.request.headers[HEADER_PARAM]? || "" - puts "PROFILE_ID", profile_id - Dayoff::ProfileId.new profile_id + Dayoff::ProfileId.new profile_id.strip end end