Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit 5d915ba

Browse files
committed
respond with 204 for successful delete
1 parent e94040c commit 5d915ba

File tree

7 files changed

+43
-19
lines changed

7 files changed

+43
-19
lines changed

src/main/java/org/brapi/test/BrAPITestServer/controller/core/BrAPIController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ public <R, T extends BrAPIResponse<R>> ResponseEntity<T> responseOK(T response,
173173
return responseOK(response, result, generateEmptyMetadata());
174174
}
175175

176+
public <T> ResponseEntity<T> responseNoContent() {
177+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
178+
}
179+
176180
public <R, T extends BrAPIResponse<R>> ResponseEntity<T> responseOK(T response, R result, Metadata metadata) {
177181
response.setMetadata(metadata);
178182
response.setResult(result);

src/main/java/org/brapi/test/BrAPITestServer/controller/core/ListsApiController.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import io.swagger.model.core.ListsSingleResponse;
1414
import io.swagger.api.core.ListsApi;
1515

16+
import org.apache.http.HttpResponse;
17+
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
1618
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
1719
import org.brapi.test.BrAPITestServer.model.entity.SearchRequestEntity;
1820
import org.brapi.test.BrAPITestServer.model.entity.SearchRequestEntity.SearchRequestTypes;
@@ -21,6 +23,7 @@
2123
import org.slf4j.Logger;
2224
import org.slf4j.LoggerFactory;
2325
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.http.HttpStatus;
2427
import org.springframework.http.ResponseEntity;
2528
import org.springframework.stereotype.Controller;
2629
import org.springframework.web.bind.annotation.CrossOrigin;
@@ -134,17 +137,17 @@ public ResponseEntity<ListsSingleResponse> listsListDbIdDelete(
134137
@Valid @RequestParam(value = "hardDelete", defaultValue = "false" ,required = false) boolean hardDelete,
135138
@RequestHeader(value = "Authorization", required = false) String authorization) throws BrAPIServerException {
136139

137-
log.debug("Request: " + request.getRequestURI());
138-
validateSecurityContext(request, "ROLE_USER");
139-
validateAcceptHeader(request);
140+
log.debug("Request: " + request.getRequestURI());
141+
validateSecurityContext(request, "ROLE_USER");
142+
validateAcceptHeader(request);
140143

141-
if (hardDelete) {
142-
listService.deleteList(listDbId);
143-
return responseOK(new ListsSingleResponse(), null);
144-
}
144+
if (hardDelete) {
145+
listService.deleteList(listDbId);
146+
return responseNoContent();
147+
}
145148

146-
listService.softDeleteList(listDbId);
147-
return responseOK(new ListsSingleResponse(), null);
149+
listService.softDeleteList(listDbId);
150+
return responseNoContent();
148151
}
149152

150153
@CrossOrigin

src/main/java/org/brapi/test/BrAPITestServer/controller/core/TrialsApiController.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,25 @@ public ResponseEntity<TrialSingleResponse> trialsTrialDbIdGet(@PathVariable("tri
9999
Trial data = trialService.getTrial(trialDbId);
100100
return responseOK(new TrialSingleResponse(), data);
101101
}
102-
@CrossOrigin
102+
103+
@CrossOrigin
103104
@Override
104105
public ResponseEntity<TrialSingleResponse> trialsTrialDbIdDelete(
105106
@PathVariable("trialDbId") String trialDbId,
106107
@Valid @RequestParam(value = "hardDelete", defaultValue = "false", required = false) boolean hardDelete,
107108
@RequestHeader(value = "Authorization", required = false) String authorization) throws BrAPIServerException {
109+
108110
log.debug("Request: " + request.getRequestURI());
109111
validateSecurityContext(request, "ROLE_USER");
110112
validateAcceptHeader(request);
111-
if (hardDelete) {
112-
trialService.deleteTrial(trialDbId);
113-
return responseOK(new TrialSingleResponse(), null);
114-
}
113+
114+
if (hardDelete) {
115+
trialService.deleteTrial(trialDbId);
116+
return responseNoContent();
117+
}
115118

116119
trialService.softDeleteTrial(trialDbId);
117-
return responseOK(new TrialSingleResponse(), null);
120+
return responseNoContent();
118121
}
119122

120123
@CrossOrigin

src/main/java/org/brapi/test/BrAPITestServer/controller/geno/SamplesApiController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,18 @@ public ResponseEntity<SampleSingleResponse> samplesSampleDbIdDelete(
124124
@PathVariable("sampleDbId") String sampleDbId,
125125
@Valid @RequestParam(value = "hardDelete", defaultValue = "false", required = false) boolean hardDelete,
126126
@RequestHeader(value = "Authorization", required = false) String authorization) throws BrAPIServerException {
127+
127128
log.debug("Request: " + request.getRequestURI());
128129
validateSecurityContext(request, "ROLE_USER");
129130
validateAcceptHeader(request);
131+
130132
if (hardDelete) {
131133
sampleService.deleteSample(sampleDbId);
132-
return responseOK(new SampleSingleResponse(), null);
134+
return responseNoContent();
133135
}
134136

135137
sampleService.softDeleteSample(sampleDbId);
136-
return responseOK(new SampleSingleResponse(), null);
138+
return responseNoContent();
137139
}
138140

139141
@CrossOrigin

src/main/java/org/brapi/test/BrAPITestServer/service/core/ListService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,17 @@ public void softDeleteListBatch(List<String> listDbIds) {
149149
}
150150

151151
public void deleteList(String listDbId) throws BrAPIServerException {
152+
// Soft delete the list first since the method throws a 404 exception if the list is not found
153+
softDeleteList(listDbId);
154+
155+
// Hard delete the list
152156
listRepository.deleteAllByIdInBatch(Arrays.asList(listDbId));
153157
}
154158

155159
public void softDeleteList(String listDbId) throws BrAPIServerDbIdNotFoundException {
156160
int updatedCount = listRepository.updateSoftDeletedStatus(listDbId, true);
157161
if (updatedCount == 0) {
158-
throw new BrAPIServerDbIdNotFoundException("List with id " + listDbId + " not found", HttpStatus.NOT_FOUND);
162+
throw new BrAPIServerDbIdNotFoundException("list", listDbId, "list database ID", HttpStatus.NOT_FOUND);
159163
}
160164
}
161165

src/main/java/org/brapi/test/BrAPITestServer/service/core/TrialService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,15 @@ public void softDeleteTrialBatch(List<String> trialDbIds) {
166166
public void softDeleteTrial(String trialDbId) throws BrAPIServerDbIdNotFoundException {
167167
int updatedCount = trialRepository.updateSoftDeletedStatus(trialDbId, true);
168168
if (updatedCount == 0) {
169-
throw new BrAPIServerDbIdNotFoundException("Trial with id " + trialDbId + " not found", HttpStatus.NOT_FOUND);
169+
throw new BrAPIServerDbIdNotFoundException("trial", trialDbId, "trial database ID", HttpStatus.NOT_FOUND);
170170
}
171171
}
172172

173173
public void deleteTrial(String trialDbId) throws BrAPIServerException {
174+
// Soft delete the trial first since the method throws a 404 exception if the trial is not found
175+
softDeleteTrial(trialDbId);
176+
177+
// Hard delete the trial
174178
trialRepository.deleteAllByIdInBatch(Arrays.asList(trialDbId));
175179
}
176180

src/main/java/org/brapi/test/BrAPITestServer/service/geno/SampleService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public void softDeleteSampleBatch(List<String> sampleDbIds) {
156156
}
157157

158158
public void deleteSample(String sampleDbId) throws BrAPIServerException {
159+
// Soft delete the sample first since the method throws a 404 exception if the sample is not found
160+
softDeleteSample(sampleDbId);
161+
162+
// Hard delete the sample
159163
sampleRepository.deleteAllByIdInBatch(Arrays.asList(sampleDbId));
160164
}
161165

0 commit comments

Comments
 (0)