Skip to content

Commit

Permalink
Added delete env descriptions
Browse files Browse the repository at this point in the history
Closes #63
  • Loading branch information
geir-eilertsen committed Dec 26, 2024
1 parent 4cb6e74 commit 4b6f61f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.assetvisor.marvin.interaction.web.controllers;

import com.assetvisor.marvin.robot.application.AddEnvironmentDescriptionUseCase;
import com.assetvisor.marvin.robot.application.DeleteEnvironmentDescriptionUseCase;
import com.assetvisor.marvin.robot.application.GetEnvironmentDescriptionsUseCase;
import com.assetvisor.marvin.robot.application.InitialiseUseCase;
import com.assetvisor.marvin.robot.domain.environment.EnvironmentDescription;
import jakarta.annotation.Resource;
import java.security.Principal;
import java.util.List;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -23,6 +25,8 @@ public class WorkshopController {
private AddEnvironmentDescriptionUseCase addEnvironmentDescriptionUseCase;
@Resource
private GetEnvironmentDescriptionsUseCase getEnvironmentDescriptionsUseCase;
@Resource
private DeleteEnvironmentDescriptionUseCase deleteEnvironmentDescriptionUseCase;


@PostMapping("/initialise")
Expand All @@ -42,4 +46,12 @@ public void addEnvironmentDescription(
public List<EnvironmentDescription> getEnvironmentDescriptions(Principal principal) {
return getEnvironmentDescriptionsUseCase.all();
}

@DeleteMapping("/environment")
public void deleteEnvironmentDescription(
Principal principal,
@RequestParam(value = "id") String id
) {
deleteEnvironmentDescriptionUseCase.delete(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public void save(EnvironmentDescription description) {
environmentDescriptionRepository.save(toEnvironmentDescriptionEntry(description));
}

@Override
public void delete(String id) {
environmentDescriptionRepository.deleteById(UUID.fromString(id));
}

private EnvironmentDescription toEnvironmentDescription(EnvironmentDescriptionEntry environmentDescriptionEntry) {
return new EnvironmentDescription(
environmentDescriptionEntry.getId().toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.assetvisor.marvin.robot.application;

public interface DeleteEnvironmentDescriptionUseCase {
void delete(String id);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.assetvisor.marvin.robot.application.services;

import com.assetvisor.marvin.robot.application.AddEnvironmentDescriptionUseCase;
import com.assetvisor.marvin.robot.application.DeleteEnvironmentDescriptionUseCase;
import com.assetvisor.marvin.robot.application.GetEnvironmentDescriptionsUseCase;
import com.assetvisor.marvin.robot.domain.environment.EnvironmentDescription;
import com.assetvisor.marvin.robot.domain.environment.ForPersistingEnvironmentDescriptions;
Expand All @@ -10,7 +11,10 @@
import org.springframework.stereotype.Component;

@Component
public class EnvironmentService implements AddEnvironmentDescriptionUseCase, GetEnvironmentDescriptionsUseCase {
public class EnvironmentService implements
AddEnvironmentDescriptionUseCase,
GetEnvironmentDescriptionsUseCase,
DeleteEnvironmentDescriptionUseCase {

@Resource
private ForPersistingEnvironmentDescriptions forPersistingEnvironmentDescriptions;
Expand All @@ -29,4 +33,9 @@ public void add(String description) {
public List<EnvironmentDescription> all() {
return forPersistingEnvironmentDescriptions.all();
}

@Override
public void delete(String id) {
forPersistingEnvironmentDescriptions.delete(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
public interface ForPersistingEnvironmentDescriptions {
List<EnvironmentDescription> all();
void save(EnvironmentDescription description);
void delete(String id);
}

0 comments on commit 4b6f61f

Please sign in to comment.