Add Tag creation usecase

This commit is contained in:
qvalentin 2022-04-22 12:52:21 +02:00
parent 1861bdfe74
commit d6efbf757f
Signed by: qvalentin
GPG Key ID: C979FA1EAFCABF1C
3 changed files with 13 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package link;
import category.CategoryName;
import category.CategoryRepository;
import exeptions.URLIsNotReachable;
import tag.TaggingUseCase;
import user.Username;
@ -27,7 +28,9 @@ public class LinkUseCase {
public void addLink(LinkUrl url, Set<CategoryName> categoryNames, Username creator) {
OnlineCheck.of(url);
if (!OnlineCheck.isReachable(url)) {
throw new URLIsNotReachable("The url " + url + " does not seem online. Check if it is correct and you have internet access.");
}
var categoryIds = categoryNames.stream().map(categoryRepository::getIdByName).collect(Collectors.toSet());

View File

@ -0,0 +1,8 @@
package exeptions;
public class URLIsNotReachable extends RuntimeException {
public URLIsNotReachable(String message) {
super(message);
}
}

View File

@ -5,7 +5,7 @@ import java.net.HttpURLConnection;
public class OnlineCheck {
static Boolean of(LinkUrl url) {
static Boolean isReachable(LinkUrl url) {
int responseCode = getResponseCode(url);
return (responseCode < 400 || responseCode == 401 || responseCode == 403);
}