From a61e820b5ecbe9bcd450c9e14389086d4bc87757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemek=20Draga=C5=84czuk?= Date: Fri, 14 Feb 2020 19:43:45 +0100 Subject: [PATCH] Fix all urls and empty shortUrl check --- src/main/java/tk/draganczuk/url/Routes.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/tk/draganczuk/url/Routes.java b/src/main/java/tk/draganczuk/url/Routes.java index 32d206e..dad75b8 100644 --- a/src/main/java/tk/draganczuk/url/Routes.java +++ b/src/main/java/tk/draganczuk/url/Routes.java @@ -1,19 +1,15 @@ package tk.draganczuk.url; -import java.io.IOException; -import java.util.List; -import java.util.UUID; - -import org.eclipse.jetty.util.log.Log; - import spark.Request; import spark.Response; +import java.io.IOException; + public class Routes { private static UrlFile urlFile; - static{ + static { try { urlFile = new UrlFile(); } catch (IOException e) { @@ -21,17 +17,17 @@ public class Routes { } } - public static List getAll(Request req, Response res) throws IOException{ - return urlFile.getAll(); + public static String getAll(Request req, Response res) throws IOException { + return String.join("\n", urlFile.getAll()); } public static String addUrl(Request req, Response res) { String longUrl = req.queryParams("long"); String shortUrl = req.queryParams("short"); - if (shortUrl == null) { - shortUrl = Utils.randomString(); - } + if (shortUrl == null || shortUrl.isBlank()) { + shortUrl = Utils.randomString(); + } return urlFile.addUrl(longUrl, shortUrl); }