I would split this into two handlers – one for the "get all programs" case and one for the "get this specific program" case. You are not reusing anything between conditionals here, so it makes sense to break it into two smaller functions.