Skip to content

Commit 1b815f2

Browse files
committed
jooby-apt: remove DELETE check for setting NO_CONTENT response code
1 parent 54bc840 commit 1b815f2

File tree

1 file changed

+30
-11
lines changed
  • modules/jooby-apt/src/main/java/io/jooby/internal/apt

1 file changed

+30
-11
lines changed

modules/jooby-apt/src/main/java/io/jooby/internal/apt/MvcRoute.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,40 @@ public List<String> generateHandlerCall(boolean kt) {
209209
throwsException ? "throws Exception {" : "{"));
210210
}
211211
if (returnType.isVoid()) {
212-
if (kt) {
213-
buffer.add(
214-
statement(
215-
indent(2),
216-
"ctx.setResponseCode(if (ctx.getRoute().getMethod().equals(",
217-
string("DELETE"),
218-
")) io.jooby.StatusCode.NO_CONTENT else io.jooby.StatusCode.OK)"));
212+
String statusCode;
213+
if (annotationMap.size() == 1) {
214+
statusCode =
215+
annotationMap.keySet().iterator().next().getSimpleName().toString().equals("DELETE")
216+
? "NO_CONTENT"
217+
: "OK";
219218
} else {
219+
statusCode = null;
220+
}
221+
if (statusCode != null) {
220222
buffer.add(
221223
statement(
222224
indent(2),
223-
"ctx.setResponseCode(ctx.getRoute().getMethod().equals(",
224-
string("DELETE"),
225-
") ? io.jooby.StatusCode.NO_CONTENT: io.jooby.StatusCode.OK)",
226-
semicolon(false)));
225+
"ctx.setResponseCode(io.jooby.StatusCode.",
226+
statusCode,
227+
")",
228+
semicolon(kt)));
229+
} else {
230+
if (kt) {
231+
buffer.add(
232+
statement(
233+
indent(2),
234+
"ctx.setResponseCode(if (ctx.getRoute().getMethod().equals(",
235+
string("DELETE"),
236+
")) io.jooby.StatusCode.NO_CONTENT else io.jooby.StatusCode.OK)"));
237+
} else {
238+
buffer.add(
239+
statement(
240+
indent(2),
241+
"ctx.setResponseCode(ctx.getRoute().getMethod().equals(",
242+
string("DELETE"),
243+
") ? io.jooby.StatusCode.NO_CONTENT: io.jooby.StatusCode.OK)",
244+
semicolon(false)));
245+
}
227246
}
228247
buffer.add(
229248
statement(

0 commit comments

Comments
 (0)