Added option to delete a URL

This commit is contained in:
Przemek Dragańczuk
2020-02-16 16:52:54 +01:00
parent f47afab80b
commit 6d7b065e98
5 changed files with 62 additions and 6 deletions

View File

@@ -54,4 +54,17 @@ public class Routes {
return "";
}
public static String delete(Request req, Response res) {
String shortUrl = req.params("shortUrl");
var longUrlOpt = urlFile
.findForShortUrl(shortUrl);
if (longUrlOpt.isEmpty()) {
res.status(404);
return "";
}
urlFile.deleteEntry(String.format("%s,%s", shortUrl, longUrlOpt.get()));
return "";
}
}