Skip to content

Instantly share code, notes, and snippets.

@mayankchoubey
Created June 30, 2021 06:29
Show Gist options
  • Save mayankchoubey/22c2cf4b51045caccb6b37db0231c5db to your computer and use it in GitHub Desktop.
Save mayankchoubey/22c2cf4b51045caccb6b37db0231c5db to your computer and use it in GitHub Desktop.
URL shortener - controller.ts
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