remove label api

This commit is contained in:
Ezequiel Bergamaschi 2014-01-30 04:35:48 -03:00 committed by Ezequiel Bergamaschi
parent c8e0b92ef5
commit b79930394d
5 changed files with 31 additions and 0 deletions

View File

@ -21,4 +21,6 @@ public interface LabelManager {
@Nullable
Label getLabelByTitle(@NotNull final String title, @NotNull final User user);
void removeLabel(@NotNull final Label label);
}

View File

@ -44,5 +44,10 @@ public class LabelManagerImpl extends HibernateDaoSupport
return result;
}
@Override
public void removeLabel(@NotNull Label label) {
getHibernateTemplate().delete(label);
}
}

View File

@ -93,4 +93,16 @@ public class LabelController extends BaseController {
mindmapService.updateMindmap(mindmap, false);
}
}
@RequestMapping(method = RequestMethod.DELETE, value = "/labels/{id}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteMapById(@PathVariable int id) throws WiseMappingException {
final User user = Utils.getUser();
final Label label = labelService.getLabelById(id);
if (label == null) {
throw new LabelCouldNotFoundException("Label could not be found. Id: " + id);
}
assert user != null;
labelService.removeLabel(label, user);
}
}

View File

@ -18,4 +18,6 @@ public interface LabelService {
Label getLabelById(int id);
public Label getLabelByTitle(@NotNull String title, @NotNull final User user);
void removeLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException;
}

View File

@ -40,4 +40,14 @@ public class LabelServiceImpl implements LabelService {
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
return labelManager.getLabelByTitle(title, user);
}
@Override
public void removeLabel(@NotNull Label label, @NotNull User user) throws WiseMappingException {
if (label.getCreator().equals(user)) {
labelManager.removeLabel(label);
} else {
throw new WiseMappingException("User: "+ user.getFullName() + "has no ownership on label " + label.getTitle());
}
}
}