Skip to content
Snippets Groups Projects
Commit e107071d authored by Hisham's avatar Hisham
Browse files

delete account und task User id

parent d190f2e1
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import de.hbrs.demo.accountservice.restservice.RestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -69,10 +70,20 @@ public class AccountServiceController {
@DeleteMapping("{id}")
public ResponseEntity<User> delete(@PathVariable("id") long userId){
User user = ephemeralStorage.deleteUserById(userId);
if(user == null){
//HttpDelete httpDelete = new HttpDelete("http://localhost:8080/api/v1/users/5");
//restService = new RestService(new RestTemplateBuilder());
if(user == null){ // User not found
return new ResponseEntity(HttpStatus.NOT_FOUND);
}else{
return new ResponseEntity<>(user,HttpStatus.OK);
// delete Tasks
if(restService.deleteTasksForUserWithIdFromTaskService(userId) == HttpStatus.OK){
// User und alle Tasks gelöscht
return new ResponseEntity<>(user,HttpStatus.OK);
}else{ // Tasks nicht gelöscht ==> Rollback
ephemeralStorage.addUserFromUserRequestModel(user); // user list reset
return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
......
......@@ -28,6 +28,7 @@ public class RestService {
}
public HttpStatus deleteTasksForUserWithIdFromTaskService(final long userId) {
try {
this.restTemplate.delete(taskServiceDeleteTasksForUserWithIdEndpoint, userId);
} catch (HttpStatusCodeException ex) {
......
......@@ -93,4 +93,6 @@ public class TaskServiceController {
return new ResponseEntity<>(task,HttpStatus.OK);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment