-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix swagger generated response, use a specific class
- Loading branch information
1 parent
1850050
commit 0f73ab1
Showing
38 changed files
with
749 additions
and
412 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/com/cp/compiler/contract/BaseRemoteCodeCompilerResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.cp.compiler.contract; | ||
|
||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@EqualsAndHashCode | ||
public class BaseRemoteCodeCompilerResponse { | ||
|
||
@ApiModelProperty(notes = "The error message") | ||
private String error; | ||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/com/cp/compiler/contract/RemoteCodeCompilerExecutionResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.cp.compiler.contract; | ||
|
||
import com.cp.compiler.contract.testcases.TestCaseResult; | ||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
// Note: Before changing this class make sure it will not introduce a breaking change for users!! | ||
|
||
/** | ||
* The type Response. | ||
* This represents the response returned to the user. | ||
* | ||
* @author Zakaria Maaraki | ||
*/ | ||
@Getter | ||
@NoArgsConstructor | ||
@EqualsAndHashCode | ||
@ApiModel(description = "The returned response") | ||
public class RemoteCodeCompilerExecutionResponse | ||
{ | ||
|
||
/** | ||
* Instantiates a new Response. | ||
* | ||
* @param verdict the statusResponse | ||
* @param statusCode the status code | ||
* @param error the error | ||
* @param testCasesResult the test cases result | ||
* @param compilationDuration the compilation duration | ||
* @param timeLimit the time limit | ||
* @param memoryLimit the memory limit | ||
* @param language the language | ||
* @param localDateTime the local date time | ||
*/ | ||
public RemoteCodeCompilerExecutionResponse(String verdict, | ||
int statusCode, | ||
String error, | ||
LinkedHashMap<String, TestCaseResult> testCasesResult, | ||
int compilationDuration, | ||
int timeLimit, | ||
int memoryLimit, | ||
Language language, | ||
LocalDateTime localDateTime) { | ||
this.verdict = verdict; | ||
this.statusCode = statusCode; | ||
this.error = error; | ||
this.testCasesResult = testCasesResult; | ||
this.compilationDuration = compilationDuration; | ||
this.timeLimit = timeLimit * 1000; // convert timeLimit to milliSec | ||
this.memoryLimit = memoryLimit; | ||
this.language = language; | ||
this.dateTime = localDateTime; | ||
this.averageExecutionDuration = computeTheAverageExecutionDuration(testCasesResult); | ||
} | ||
|
||
@ApiModelProperty(notes = "The statusResponse") | ||
private String verdict; | ||
|
||
@ApiModelProperty(notes = "The corresponding status code of the statusResponse") | ||
private int statusCode; | ||
|
||
@ApiModelProperty(notes = "An error if it occurs") | ||
private String error; | ||
|
||
@ApiModelProperty(notes = "The result of each test case") | ||
private LinkedHashMap<String, TestCaseResult> testCasesResult; // Should be returned in order | ||
|
||
@ApiModelProperty(notes = "The compilation duration") | ||
private int compilationDuration; | ||
|
||
@ApiModelProperty(notes = "The average execution duration") | ||
private float averageExecutionDuration; | ||
|
||
@ApiModelProperty(notes = "The execution time limit") | ||
private int timeLimit; | ||
|
||
@ApiModelProperty(notes = "The execution memory limit") | ||
private int memoryLimit; | ||
|
||
@ApiModelProperty(notes = "The programming language") | ||
private Language language; | ||
|
||
@EqualsAndHashCode.Exclude | ||
@ApiModelProperty(notes = "The dateTime of the execution") | ||
private LocalDateTime dateTime; | ||
|
||
private float computeTheAverageExecutionDuration(Map<String, TestCaseResult> testCasesResult) { | ||
float sum = 0; | ||
for (TestCaseResult testCaseResult : testCasesResult.values()) { | ||
if (testCaseResult.getExecutionDuration() == 0) { | ||
continue; | ||
} | ||
sum += testCaseResult.getExecutionDuration(); | ||
} | ||
return sum / testCasesResult.size(); | ||
} | ||
} |
97 changes: 5 additions & 92 deletions
97
src/main/java/com/cp/compiler/contract/RemoteCodeCompilerResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,17 @@ | ||
package com.cp.compiler.contract; | ||
|
||
import com.cp.compiler.contract.Language; | ||
import com.cp.compiler.contract.testcases.TestCaseResult; | ||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
// Note: Before changing this class make sure it will not introduce a breaking change for users!! | ||
|
||
/** | ||
* The type Response. | ||
* This represents the response returned to the user. | ||
* | ||
* @author Zakaria Maaraki | ||
*/ | ||
@Getter | ||
@NoArgsConstructor | ||
@EqualsAndHashCode | ||
@ApiModel(description = "The returned response") | ||
public class RemoteCodeCompilerResponse { | ||
|
||
/** | ||
* Instantiates a new Response. | ||
* | ||
* @param verdict the statusResponse | ||
* @param statusCode the status code | ||
* @param error the error | ||
* @param testCasesResult the test cases result | ||
* @param compilationDuration the compilation duration | ||
* @param timeLimit the time limit | ||
* @param memoryLimit the memory limit | ||
* @param language the language | ||
* @param localDateTime the local date time | ||
*/ | ||
public RemoteCodeCompilerResponse(String verdict, | ||
int statusCode, | ||
String error, | ||
LinkedHashMap<String, TestCaseResult> testCasesResult, | ||
int compilationDuration, | ||
int timeLimit, | ||
int memoryLimit, | ||
Language language, | ||
LocalDateTime localDateTime) { | ||
this.verdict = verdict; | ||
this.statusCode = statusCode; | ||
this.error = error; | ||
this.testCasesResult = testCasesResult; | ||
this.compilationDuration = compilationDuration; | ||
this.timeLimit = timeLimit * 1000; // convert timeLimit to milliSec | ||
this.memoryLimit = memoryLimit; | ||
this.language = language; | ||
this.dateTime = localDateTime; | ||
this.averageExecutionDuration = computeTheAverageExecutionDuration(testCasesResult); | ||
} | ||
|
||
@ApiModelProperty(notes = "The statusResponse") | ||
private String verdict; | ||
|
||
@ApiModelProperty(notes = "The corresponding status code of the statusResponse") | ||
private int statusCode; | ||
|
||
@ApiModelProperty(notes = "An error if it occurs") | ||
private String error; | ||
|
||
@ApiModelProperty(notes = "The result of each test case") | ||
private LinkedHashMap<String, TestCaseResult> testCasesResult; // Should be returned in order | ||
|
||
@ApiModelProperty(notes = "The compilation duration") | ||
private int compilationDuration; | ||
|
||
@ApiModelProperty(notes = "The average execution duration") | ||
private float averageExecutionDuration; | ||
|
||
@ApiModelProperty(notes = "The execution time limit") | ||
private int timeLimit; | ||
|
||
@ApiModelProperty(notes = "The execution memory limit") | ||
private int memoryLimit; | ||
|
||
@ApiModelProperty(notes = "The programming language") | ||
private Language language; | ||
|
||
@EqualsAndHashCode.Exclude | ||
@ApiModelProperty(notes = "The dateTime of the execution") | ||
private LocalDateTime dateTime; | ||
@AllArgsConstructor | ||
public class RemoteCodeCompilerResponse extends BaseRemoteCodeCompilerResponse { | ||
|
||
private float computeTheAverageExecutionDuration(Map<String, TestCaseResult> testCasesResult) { | ||
float sum = 0; | ||
for (TestCaseResult testCaseResult : testCasesResult.values()) { | ||
if (testCaseResult.getExecutionDuration() == 0) { | ||
continue; | ||
} | ||
sum += testCaseResult.getExecutionDuration(); | ||
} | ||
return sum / testCasesResult.size(); | ||
} | ||
@ApiModelProperty(notes = "The execution response") | ||
private RemoteCodeCompilerExecutionResponse execution; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.