Created
          June 30, 2021 06:29 
        
      - 
      
- 
        Save mayankchoubey/22c2cf4b51045caccb6b37db0231c5db to your computer and use it in GitHub Desktop. 
    URL shortener - controller.ts
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import {Status} from "https://deno.land/std/http/http_status.ts" | |
| import {sendResponseCode, sendResponseRedirect, sendResponseShortenedUrl} from "./utils.ts"; | |
| import {get,add} from "./service.ts"; | |
| export function getTarget(resp: any, urlCode: string) { | |
| const target=get(urlCode); | |
| if(!target) | |
| return sendResponseCode(resp, Status.NotFound); | |
| sendResponseRedirect(resp, target); | |
| } | |
| export function addTarget(resp: any, target: string|null) { | |
| if(!target) | |
| return sendResponseCode(resp, Status.BadRequest); | |
| const urlCode=add(target); | |
| sendResponseShortenedUrl(resp, urlCode); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment