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
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CodeReviewLock {
String prefix();
String prefix();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CodeReviewLockAspect {

private final LockManager lockManager;

@Around("@annotation(org.ezcode.codetest.application.submission.aop.CodeReviewLock)")
public Object lock(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
String prefix = signature.getMethod().getAnnotation(CodeReviewLock.class).prefix();
Object[] args = joinPoint.getArgs();

Long problemId = null;
Long userId = null;

for (Object arg : args) {
if (arg instanceof Long) {
problemId = (Long) arg;
} else if (arg instanceof AuthUser) {
userId = ((AuthUser)arg).getId();
}
}

if (problemId == null || userId == null) {
throw new CodeReviewException(CodeReviewExceptionCode.REQUIRED_ARGS_NOT_FOUND);
}

boolean locked = lockManager.tryLock(prefix, userId, problemId);
if (!locked) {
throw new CodeReviewException(CodeReviewExceptionCode.ALREADY_REVIEWING);
}

try {
return joinPoint.proceed();
} finally {
lockManager.releaseLock(prefix, userId, problemId);
}
}
private final LockManager lockManager;

@Around("@annotation(org.ezcode.codetest.application.submission.aop.CodeReviewLock)")
public Object lock(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature)joinPoint.getSignature();
String prefix = signature.getMethod().getAnnotation(CodeReviewLock.class).prefix();
Object[] args = joinPoint.getArgs();

Long problemId = null;
Long userId = null;

for (Object arg : args) {
if (arg instanceof Long) {
problemId = (Long)arg;
} else if (arg instanceof AuthUser) {
userId = ((AuthUser)arg).getId();
}
}

if (problemId == null || userId == null) {
throw new CodeReviewException(CodeReviewExceptionCode.REQUIRED_ARGS_NOT_FOUND);
}

boolean locked = lockManager.tryLock(prefix, userId, problemId);
if (!locked) {
throw new CodeReviewException(CodeReviewExceptionCode.ALREADY_REVIEWING);
}

try {
return joinPoint.proceed();
} finally {
lockManager.releaseLock(prefix, userId, problemId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

public record CodeCompileRequest(

String source_code,
String source_code,

Long language_id,
Long language_id,

String stdin
String stdin

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
@Schema(description = "언어 업데이트 요청")
public record LanguageUpdateRequest(

@Schema(description = "Judge0에서 사용하는 언어 ID", example = "62")
@NotNull(message = "Judge0 아이디는 필수 입력 값입니다.")
Long judge0Id
@Schema(description = "Judge0에서 사용하는 언어 ID", example = "62")
@NotNull(message = "Judge0 아이디는 필수 입력 값입니다.")
Long judge0Id

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
@Schema(description = "코드 리뷰 요청 DTO")
public record CodeReviewRequest(

@Schema(description = "언어 ID", example = "62")
@NotNull(message = "언어 번호는 필수 입력 값입니다.")
Long languageId,
@Schema(description = "언어 ID", example = "62")
@NotNull(message = "언어 번호는 필수 입력 값입니다.")
Long languageId,

@Schema(
description = "소스 코드",
example = "public class Main { public static void main(String[] args) { System.out.println(\"Hello\"); } }"
)
@NotBlank(message = "소스 코드는 필수 입력 값입니다.")
String sourceCode,
@Schema(
description = "소스 코드",
example = "public class Main { public static void main(String[] args) { System.out.println(\"Hello\"); } }"
)
@NotBlank(message = "소스 코드는 필수 입력 값입니다.")
String sourceCode,

@Schema(description = "정답 여부", example = "true")
@NotNull(message = "정답 여부는 필수 입력 값입니다.")
Boolean isCorrect
@Schema(description = "정답 여부", example = "true")
@NotNull(message = "정답 여부는 필수 입력 값입니다.")
Boolean isCorrect

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

public record ReviewPayload(

String problemDescription,
String problemDescription,

String languageName,
String languageName,

String sourceCode,
String sourceCode,

boolean isCorrect
boolean isCorrect

) {
public static ReviewPayload of(Problem problem, Language language, CodeReviewRequest request) {
return new ReviewPayload(
problem.getDescription(),
language.getName(),
request.sourceCode(),
request.isCorrect()
);
}
public static ReviewPayload of(Problem problem, Language language, CodeReviewRequest request) {
return new ReviewPayload(
problem.getDescription(),
language.getName(),
request.sourceCode(),
request.isCorrect()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
@Schema(description = "코드 제출 요청 DTO")
public record CodeSubmitRequest(

@Schema(description = "언어 ID", example = "1")
@NotNull(message = "언어 번호는 필수 입력 값입니다.")
Long languageId,
@Schema(description = "언어 ID", example = "1")
@NotNull(message = "언어 번호는 필수 입력 값입니다.")
Long languageId,

@Schema(
description = "소스 코드",
example = "public class Main { public static void main(String[] args) { System.out.println(\"Hello World\"); } }"
)
@NotBlank(message = "소스 코드는 필수 입력 값입니다.")
String sourceCode
@Schema(
description = "소스 코드",
example = "public class Main { public static void main(String[] args) { System.out.println(\"Hello World\"); } }"
)
@NotBlank(message = "소스 코드는 필수 입력 값입니다.")
String sourceCode

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@

public record ExecutionResultResponse(

String stdout,
String stdout,

Double time,
Double time,

Long memory,
Long memory,

String stderr,
String stderr,

String token,
String token,

String compile_output,
String compile_output,

int exit_code,
int exit_code,

ExecutionStatus status
ExecutionStatus status

) {

public long getMemory() {
return this.memory == null ? 0L : memory;
}
public long getMemory() {
return this.memory == null ? 0L : memory;
}

public double getTime() {
return this.time == null ? 0.0 : time;
}
public double getTime() {
return this.time == null ? 0.0 : time;
}

public record ExecutionStatus(
public record ExecutionStatus(

int id,
int id,

String description
String description

) {}
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "언어 응답 정보")
public record LanguageResponse (
public record LanguageResponse(

@Schema(description = "언어 ID", example = "1")
Long id,
@Schema(description = "언어 ID", example = "1")
Long id,

@Schema(description = "언어 이름", example = "Java")
String name,
@Schema(description = "언어 이름", example = "Java")
String name,

@Schema(description = "언어 버전", example = "17")
String version,
@Schema(description = "언어 버전", example = "17")
String version,

@Schema(description = "Judge0에서 사용하는 언어 ID", example = "62")
Long judge0Id
@Schema(description = "Judge0에서 사용하는 언어 ID", example = "62")
Long judge0Id

){
public static LanguageResponse from(Language language) {
return new LanguageResponse(
language.getId(), language.getName(), language.getVersion(), language.getJudge0Id()
);
}
) {
public static LanguageResponse from(Language language) {
return new LanguageResponse(
language.getId(), language.getName(), language.getVersion(), language.getJudge0Id()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
@Schema(description = "코드 리뷰 응답 DTO")
public record CodeReviewResponse(

@Schema(description = "리뷰 내용", example = "변수명이 명확하지 않습니다. 의미 있는 이름을 사용해주세요.")
String reviewContent
@Schema(description = "리뷰 내용", example = "변수명이 명확하지 않습니다. 의미 있는 이름을 사용해주세요.")
String reviewContent

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
@Schema(description = "최종 채점 결과 응답 DTO")
public class FinalResultResponse {

@Schema(description = "전체 테스트케이스 수", example = "5")
private final int totalCount;
@Schema(description = "전체 테스트케이스 수", example = "5")
private final int totalCount;

@Schema(description = "통과한 테스트케이스 수", example = "5")
private final int passedCount;
@Schema(description = "통과한 테스트케이스 수", example = "5")
private final int passedCount;

@Schema(description = "전체 통과 여부", example = "true")
private final boolean isCorrect;
@Schema(description = "전체 통과 여부", example = "true")
private final boolean isCorrect;

@Schema(description = "메시지", example = "Accepted")
private final String message;
@Schema(description = "메시지", example = "Accepted")
private final String message;

public FinalResultResponse(int totalCount, int passedCount, String message) {
this.totalCount = totalCount;
this.passedCount = passedCount;
this.isCorrect = totalCount == passedCount;
this.message = message;
}
public FinalResultResponse(int totalCount, int passedCount, String message) {
this.totalCount = totalCount;
this.passedCount = passedCount;
this.isCorrect = totalCount == passedCount;
this.message = message;
}
}
Loading