Add Tag creation usecase
This commit is contained in:
parent
1861bdfe74
commit
d6efbf757f
|
@ -2,6 +2,7 @@ package link;
|
||||||
|
|
||||||
import category.CategoryName;
|
import category.CategoryName;
|
||||||
import category.CategoryRepository;
|
import category.CategoryRepository;
|
||||||
|
import exeptions.URLIsNotReachable;
|
||||||
import tag.TaggingUseCase;
|
import tag.TaggingUseCase;
|
||||||
import user.Username;
|
import user.Username;
|
||||||
|
|
||||||
|
@ -27,7 +28,9 @@ public class LinkUseCase {
|
||||||
|
|
||||||
public void addLink(LinkUrl url, Set<CategoryName> categoryNames, Username creator) {
|
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());
|
var categoryIds = categoryNames.stream().map(categoryRepository::getIdByName).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
8
3-Domain/src/main/java/exeptions/URLIsNotReachable.java
Normal file
8
3-Domain/src/main/java/exeptions/URLIsNotReachable.java
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package exeptions;
|
||||||
|
|
||||||
|
public class URLIsNotReachable extends RuntimeException {
|
||||||
|
|
||||||
|
public URLIsNotReachable(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import java.net.HttpURLConnection;
|
||||||
|
|
||||||
public class OnlineCheck {
|
public class OnlineCheck {
|
||||||
|
|
||||||
static Boolean of(LinkUrl url) {
|
static Boolean isReachable(LinkUrl url) {
|
||||||
int responseCode = getResponseCode(url);
|
int responseCode = getResponseCode(url);
|
||||||
return (responseCode < 400 || responseCode == 401 || responseCode == 403);
|
return (responseCode < 400 || responseCode == 401 || responseCode == 403);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue