Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/main/java/com/codzilla/backend/MatchRoom/MatchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.codzilla.backend.MatchRoom.dto.MatchHistoryEntryDTO;
import com.codzilla.backend.PreMatch.model.Category;
import com.codzilla.backend.PreMatch.model.ProblemType;
import com.codzilla.backend.User.User;
import com.codzilla.backend.judge.problem.ProblemService;
import org.springframework.http.HttpStatusCode;
Expand All @@ -11,7 +12,6 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import lombok.RequiredArgsConstructor;

import java.util.UUID;
import java.util.List;
Expand Down Expand Up @@ -39,11 +39,21 @@ ResponseEntity<?> getMatchOptions(@AuthenticationPrincipal User user, @PathVaria
return ResponseEntity.status(HttpStatusCode.valueOf(404)).build();
}
try {
var statement = problemService.getStatementOfProblem(match.getProblem().getId());
var problem = problemService.getArtefactsOfProblem(match.getProblem().getId());
var options = match.getOptions();
var response = new MatchOptions(problem.getName(), statement, options.get(Category.Language), options.get(Category.ProblemType), options.get(Category.ProblemLevel));
return ResponseEntity.ok(response);
if (match.getOptions().get(Category.ProblemType).equals(ProblemType.SQL.name())) {
var artefacts = problemService.getArtefactsOfSqlProblem(match.getProblem().getExternalId());
var response = new MatchOptions(artefacts.getName(),
artefacts.getDescription(), "SQL",
"SQL",
match.getOptions().get(Category.ProblemLevel));
return ResponseEntity.ok(response);
} else {
var statement = problemService.getStatementOfAlgoProblem(match.getProblem().getId());
var problem = problemService.getArtefactsOfAlgoProblem(match.getProblem().getId());
var options = match.getOptions();
var response = new MatchOptions(problem.getName(), statement, options.get(Category.Language), options.get(Category.ProblemType), options.get(Category.ProblemLevel));
return ResponseEntity.ok(response);
}

} catch (RuntimeException e) {
return ResponseEntity.notFound().build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codzilla.backend.judge.client;

import com.codzilla.backend.judge.problem.ProblemSqlResponseDTO;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -111,6 +112,29 @@ public RandomSqlTaskResponse getRandomTask(String level) {
}
}

public ProblemSqlResponseDTO getArtefactsOfSqlProblem(Long problemId) {
try {
String raw = restClient.get()
.uri("/sqlservice/tasks/" + problemId)
.retrieve()
.body(String.class);

JsonNode root = objectMapper.readTree(raw);
if (!root.get("success").asBoolean()) {
String error = root.has("error") ? root.get("error").asText() : "Unknown error";
throw new RuntimeException("SqlService error: " + error);
}
JsonNode data = root.get("data");

ProblemSqlResponseDTO response = new ProblemSqlResponseDTO();
response.setName(data.get("title").asText());
response.setDescription(data.get("description").asText());
return response;
} catch (Exception e) {
throw new RuntimeException("Failed to get artefacts of problem: {}" , e);
}
}



@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ public Problem getOrCreateRandomSqlProblem(String level) {
throw new RuntimeException("No SQL tasks found at any level (EASY, MEDIUM, HARD)");
}

public ProblemResponseDTO getArtefactsOfProblem(Long problemId) {
public ProblemResponseDTO getArtefactsOfAlgoProblem(Long problemId) {
return artefactik0Client.getProblem(problemId);
}

public String getStatementOfProblem(Long problemId) {
public String getStatementOfAlgoProblem(Long problemId) {
return artefactik0Client.getStatement(problemId);
}

public ProblemSqlResponseDTO getArtefactsOfSqlProblem(Long problemId) {
return sqlServiceClient.getArtefactsOfSqlProblem(problemId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codzilla.backend.judge.problem;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ProblemSqlResponseDTO {
String name;
String description;
}
Loading