Commit b2b5f46a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

pluginDataEntry.delete implemented

parent b22dfcc7
......@@ -120,15 +120,12 @@ public class PluginController extends BaseController {
}
@DeleteMapping(value = "/{hash}/data/users/{key}")
public Map<String, Object> deletePluginDataEntry(
public Object deletePluginDataEntry(
Authentication authentication,
@PathVariable(value = "hash") String hash,
@PathVariable(value = "key") String key) throws QueryException {
User user = userService.getUserByLogin(authentication.getName());
pluginRest.deletePluginDataEntry(hash, user, key);
Map<String, Object> result = new HashMap<>();
result.put("status", "ok");
return result;
return deletePluginDataEntry(hash, user, key);
}
@PostMapping(value = "/{hash}/data/global/{key}")
......@@ -140,13 +137,10 @@ public class PluginController extends BaseController {
}
@DeleteMapping(value = "/{hash}/data/global/{key}")
public Map<String, Object> deletePluginDataEntry(
public Object deletePluginDataEntry(
@PathVariable(value = "hash") String hash,
@PathVariable(value = "key") String key) throws QueryException {
pluginRest.deletePluginDataEntry(hash, null, key);
Map<String, Object> result = new HashMap<>();
result.put("status", "ok");
return result;
return deletePluginDataEntry(hash, null, key);
}
@GetMapping(value = "/{hash}/data/users/{key}")
......@@ -165,7 +159,7 @@ public class PluginController extends BaseController {
return getPluginDataEntry(hash, null, key);
}
public PluginDataEntry getPluginDataEntry(String hash, User user, String key) throws ObjectNotFoundException {
private PluginDataEntry getPluginDataEntry(String hash, User user, String key) throws ObjectNotFoundException {
Plugin plugin = pluginService.getByHash(hash);
if (plugin == null) {
throw new ObjectNotFoundException("Plugin doesn't exist");
......@@ -178,4 +172,21 @@ public class PluginController extends BaseController {
return entry;
}
private Object deletePluginDataEntry(String hash, User user, String key) throws QueryException {
Plugin plugin = pluginService.getByHash(hash);
if (plugin == null) {
throw new ObjectNotFoundException("Plugin doesn't exist");
}
PluginDataEntry entry = pluginService.getEntryByKey(plugin, key, user);
if (entry == null) {
throw new ObjectNotFoundException("Data entry not found");
} else {
pluginService.delete(entry);
}
Map<String, Object> result = new HashMap<>();
result.put("status", "ok");
return result;
}
}
\ No newline at end of file
......@@ -102,20 +102,6 @@ public class PluginRestImpl extends BaseRestImpl {
return entry;
}
public void deletePluginDataEntry(String hash, User user, String key) throws QueryException {
Plugin plugin = pluginDao.getByHash(hash);
if (plugin == null) {
throw new ObjectNotFoundException("Plugin doesn't exist");
}
PluginDataEntry entry = pluginDataEntryDao.getByKey(plugin, key, user);
if (entry == null) {
throw new ObjectNotFoundException("Data entry not found");
} else {
pluginDataEntryDao.delete(entry);
}
}
public Plugin updatePlugin(String hash, Map<String, Object> data) throws QueryException {
Plugin plugin = pluginDao.getByHash(hash);
if (plugin == null) {
......
......@@ -60,4 +60,9 @@ public class PluginService implements IPluginService {
Hibernate.initialize(result.getUser());
return result;
}
@Override
public void delete(PluginDataEntry entry) {
pluginDataEntryDao.delete(entry);
}
}
......@@ -16,4 +16,6 @@ public interface IPluginService {
PluginDataEntry getEntryByKey(Plugin plugin, String key, User user);
void delete(PluginDataEntry entry);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment