implemented deletion of tags upon deletion of task
This commit is contained in:
@@ -93,7 +93,18 @@ CREATE TABLE IF NOT EXISTS "{0}" (
|
||||
.execute(db);
|
||||
return tag;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException("Failed to save tag {0}",tag);
|
||||
throw new UmbrellaException("Failed to delete tag {0}",tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEntity(String module, long entityId) {
|
||||
try {
|
||||
Query.delete().from(TABLE_TAGS)
|
||||
.where(MODULE,equal(module)).where(ID,equal(entityId))
|
||||
.execute(db);
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException("Failed to save tags ({0} {1})",module,entityId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,14 +127,15 @@ CREATE TABLE IF NOT EXISTS "{0}" (
|
||||
}
|
||||
|
||||
@Override
|
||||
public String save(Collection<Long> userIds, String module, long entityId, String tag) {
|
||||
public void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags) {
|
||||
try {
|
||||
var query = replaceInto(TABLE_TAGS,USER_ID,MODULE,ID,TAG);
|
||||
for (var userId : userIds) query.values(userId,module,entityId,tag);
|
||||
for (var userId : userIds) {
|
||||
for (var tag : tags) query.values(userId,module,entityId,tag);
|
||||
}
|
||||
query.execute(db).close();
|
||||
return tag;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException("Failed to save tag {0}",tag);
|
||||
throw new UmbrellaException("Failed to save tags: {0}",String.join(", ",tags));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public interface TagDB {
|
||||
Object delete(long userId, String module, long entityId, String tag);
|
||||
String delete(long userId, String module, long entityId, String tag);
|
||||
|
||||
void deleteEntity(String module, long entityId);
|
||||
|
||||
Set<String> list(long id, String module, long entityId);
|
||||
|
||||
String save(Collection<Long> userIds, String module, long entityId, String tag);
|
||||
void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,11 @@ import de.srsoftware.umbrella.core.api.TagService;
|
||||
import de.srsoftware.umbrella.core.api.UserService;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
public class TagModule extends BaseHandler implements TagService {
|
||||
private final SqliteDb tagDb;
|
||||
@@ -36,6 +35,11 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
users = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEntity(String module, long entityId) {
|
||||
tagDb.deleteEntity(module,entityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
@@ -67,8 +71,7 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
if (module == null) throw unprocessable("Module missing in path.");
|
||||
var head = path.pop();
|
||||
long entityId = Long.parseLong(head);
|
||||
var tags = tagDb.list(user.get().id(),module,entityId);
|
||||
return sendContent(ex, tags);
|
||||
return sendContent(ex, getTags(module,entityId,user.get()));
|
||||
} catch (NumberFormatException e){
|
||||
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path.");
|
||||
} catch (UmbrellaException e){
|
||||
@@ -99,7 +102,7 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
arr.toList().stream().filter(elem -> elem instanceof Number).map(elem -> (Number) elem).map(Number::longValue).toList()
|
||||
: List.of(user.get().id());
|
||||
if (userList.isEmpty()) throw missingFieldException(USER_LIST);
|
||||
tag = tagDb.save(userList, module, entityId, tag);
|
||||
tag = save(module, entityId, userList, tag);
|
||||
return sendContent(ex, tag);
|
||||
} catch (NumberFormatException e) {
|
||||
return sendContent(ex, HTTP_UNPROCESSABLE, "Entity id missing in path.");
|
||||
@@ -108,5 +111,18 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> getTags(String module, long entityId, UmbrellaUser user) throws UmbrellaException{
|
||||
return tagDb.list(user.id(),module,entityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(String module, long entityId, Collection<Long> userIds, Collection<String> tags) {
|
||||
tagDb.save(userIds,module,entityId,tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String save(String module, long entityId, Collection<Long> userIds, String tag) {
|
||||
save(module,entityId,userIds,List.of(tag));
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user