Commit 64c818db authored by Piotr Gawron's avatar Piotr Gawron
Browse files

delete background endpoint implement

parent 95f5a108
......@@ -768,7 +768,7 @@ public class ProjectRestImpl extends BaseRestImpl {
public ProjectBackground getBackgroundById(String projectId, Integer backgroundId) throws ObjectNotFoundException {
List<ProjectBackground> backgrounds = getProjectByProjectId(projectId).getProjectBackgrounds();
for (ProjectBackground projectBackground : backgrounds) {
if (projectBackground.getId()==backgroundId) {
if (projectBackground.getId() == backgroundId) {
Hibernate.initialize(projectBackground.getProjectBackgroundImageLayer());
return projectBackground;
}
......@@ -776,8 +776,16 @@ public class ProjectRestImpl extends BaseRestImpl {
throw new ObjectNotFoundException("Background does not exist");
}
public Map<String, Object> removeBackground(String projectId, Integer backgroundId) {
throw new NotImplementedException();
public Map<String, Object> removeBackground(String projectId, Integer backgroundId) throws ObjectNotFoundException {
Project project = getProjectByProjectId(projectId);
for (ProjectBackground projectBackground : project.getProjectBackgrounds()) {
if (projectBackground.getId() == backgroundId) {
project.removeProjectBackground(projectBackground);
projectDao.update(project);
return okStatus();
}
}
throw new ObjectNotFoundException("Background does not exist");
}
public ProjectBackground updateOverlay(String projectId, Integer overlayId, Map<String, Object> data) {
......
......@@ -477,10 +477,12 @@ abstract public class ControllerIntegrationTest {
try {
dbUtils.createSessionForCurrentThread();
fun.run();
return null;
} catch (Throwable e) {
e.printStackTrace();
} finally {
dbUtils.closeSessionForCurrentThread();
}
return null;
}
}));
} catch (InterruptedException e) {
......
......@@ -1054,10 +1054,13 @@ public class ProjectControllerIntegrationTest extends ControllerIntegrationTest
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful())
.andDo(document("projects/project_data/delete_background",
projectPathParameters(),
backgroundPathParameters(),
responseFields()));
assertEquals(project.getProjectBackgrounds().size() - 1,
projectDao.getById(project.getId()).getProjectBackgrounds().size());
int backgrounds = callInSeparateThread(() -> {
return projectDao.getById(project.getId()).getProjectBackgrounds().size();
});
assertEquals(project.getProjectBackgrounds().size() - 1, backgrounds);
}
private PathParametersSnippet projectPathParameters() {
......
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