mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 07:38:36 -06:00
Fix all urls and empty shortUrl check
This commit is contained in:
parent
0f41363740
commit
a61e820b5e
1 changed files with 8 additions and 12 deletions
|
@ -1,19 +1,15 @@
|
||||||
package tk.draganczuk.url;
|
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.Request;
|
||||||
import spark.Response;
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Routes {
|
public class Routes {
|
||||||
|
|
||||||
private static UrlFile urlFile;
|
private static UrlFile urlFile;
|
||||||
|
|
||||||
static{
|
static {
|
||||||
try {
|
try {
|
||||||
urlFile = new UrlFile();
|
urlFile = new UrlFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -21,17 +17,17 @@ public class Routes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getAll(Request req, Response res) throws IOException{
|
public static String getAll(Request req, Response res) throws IOException {
|
||||||
return urlFile.getAll();
|
return String.join("\n", urlFile.getAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String addUrl(Request req, Response res) {
|
public static String addUrl(Request req, Response res) {
|
||||||
String longUrl = req.queryParams("long");
|
String longUrl = req.queryParams("long");
|
||||||
String shortUrl = req.queryParams("short");
|
String shortUrl = req.queryParams("short");
|
||||||
|
|
||||||
if (shortUrl == null) {
|
if (shortUrl == null || shortUrl.isBlank()) {
|
||||||
shortUrl = Utils.randomString();
|
shortUrl = Utils.randomString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return urlFile.addUrl(longUrl, shortUrl);
|
return urlFile.addUrl(longUrl, shortUrl);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue