diff --git a/src/main/java/ei/algobaroapi/domain/problem/service/BojProblemServiceImpl.java b/src/main/java/ei/algobaroapi/domain/problem/service/BojProblemServiceImpl.java index a414c96..a7add1d 100644 --- a/src/main/java/ei/algobaroapi/domain/problem/service/BojProblemServiceImpl.java +++ b/src/main/java/ei/algobaroapi/domain/problem/service/BojProblemServiceImpl.java @@ -97,7 +97,7 @@ public SolveStatus checkSolveResult(ProblemSolveRequest request) { answer = result.equals(CORRECT) ? SolveStatus.SUCCESS : SolveStatus.FAIL; } catch (IOException e) { - throw CrawlingAccessException.of(ProblemErrorCode.CRAWLING_NOT_ACCESS); + return SolveStatus.FAIL; } return answer; diff --git a/src/main/java/ei/algobaroapi/domain/room/controller/RoomControllerDocImpl.java b/src/main/java/ei/algobaroapi/domain/room/controller/RoomControllerDocImpl.java index 6308ea9..7b90f65 100644 --- a/src/main/java/ei/algobaroapi/domain/room/controller/RoomControllerDocImpl.java +++ b/src/main/java/ei/algobaroapi/domain/room/controller/RoomControllerDocImpl.java @@ -50,7 +50,7 @@ public RoomDetailResponseDto createRoom( @PatchMapping("/rooms/{roomShortUuid}") public RoomResponseDto updateRoomById(@PathVariable(name = "roomShortUuid") String roomShortUuid, @RequestBody @Valid RoomUpdateRequestDto roomUpdateRequestDto) { - return roomService.updateRoomByRoomId(roomShortUuid, roomUpdateRequestDto); + return roomService.updateRoomByShortUuid(roomShortUuid, roomUpdateRequestDto); } @Override diff --git a/src/main/java/ei/algobaroapi/domain/room/domain/Room.java b/src/main/java/ei/algobaroapi/domain/room/domain/Room.java index dee2ca5..f789296 100644 --- a/src/main/java/ei/algobaroapi/domain/room/domain/Room.java +++ b/src/main/java/ei/algobaroapi/domain/room/domain/Room.java @@ -144,12 +144,20 @@ public void update(RoomUpdateRequestDto roomUpdateRequestDto) { && roomUpdateRequestDto.getTimeLimit() > 0) { this.timeLimit = roomUpdateRequestDto.getTimeLimit(); } + + if (isPublic()) { + this.password = ""; + } } public String getRoomShortUuid() { return this.roomUuid.split("-")[0]; } + public boolean isPublic() { + return this.roomAccessType == RoomAccessType.PUBLIC; + } + public boolean isRecruiting() { return this.roomStatus == RoomStatus.RECRUITING; } diff --git a/src/main/java/ei/algobaroapi/domain/room/service/RoomService.java b/src/main/java/ei/algobaroapi/domain/room/service/RoomService.java index 70253ef..2c85544 100644 --- a/src/main/java/ei/algobaroapi/domain/room/service/RoomService.java +++ b/src/main/java/ei/algobaroapi/domain/room/service/RoomService.java @@ -15,7 +15,7 @@ public interface RoomService { RoomDetailResponseDto createRoom(RoomCreateRequestDto roomCreateRequestDto, Member member); - RoomResponseDto updateRoomByRoomId(String roomShortUuid, + RoomResponseDto updateRoomByShortUuid(String roomShortUuid, RoomUpdateRequestDto roomUpdateRequestDto); RoomDetailResponseDto getRoomDetailShortUuid(String roomShortUuid); diff --git a/src/main/java/ei/algobaroapi/domain/room/service/RoomServiceImpl.java b/src/main/java/ei/algobaroapi/domain/room/service/RoomServiceImpl.java index 64c25ee..cbeadcf 100644 --- a/src/main/java/ei/algobaroapi/domain/room/service/RoomServiceImpl.java +++ b/src/main/java/ei/algobaroapi/domain/room/service/RoomServiceImpl.java @@ -64,7 +64,7 @@ public RoomDetailResponseDto createRoom(RoomCreateRequestDto roomCreateRequestDt @Override @Transactional - public RoomResponseDto updateRoomByRoomId(String roomShortUuid, + public RoomResponseDto updateRoomByShortUuid(String roomShortUuid, RoomUpdateRequestDto roomUpdateRequestDto) { Room room = getRoomByShortUuid(roomShortUuid); @@ -107,7 +107,8 @@ public RoomDetailResponseDto startCodingTest(String roomShortUuid) { @Override @Transactional public void completeSolveHistory(String roomShortUuid) { - List solveHistoryList = solveHistoryService.getSolveHistoryListByRoomShortUuid(roomShortUuid); + List solveHistoryList = solveHistoryService.getSolveHistoryListByRoomShortUuid( + roomShortUuid); solveHistoryList.forEach(solveHistory -> { SolveStatus solveStatus = problemService.checkSolveResult( diff --git a/src/main/java/ei/algobaroapi/domain/solve/controller/SolveController.java b/src/main/java/ei/algobaroapi/domain/solve/controller/SolveController.java index 8f9c85b..7b4914f 100644 --- a/src/main/java/ei/algobaroapi/domain/solve/controller/SolveController.java +++ b/src/main/java/ei/algobaroapi/domain/solve/controller/SolveController.java @@ -3,8 +3,10 @@ import ei.algobaroapi.domain.member.domain.Member; import ei.algobaroapi.domain.solve.domain.SolveHistory; import ei.algobaroapi.domain.solve.dto.request.BojCodeSubmissionRequest; +import ei.algobaroapi.domain.solve.dto.request.CodeSubmissionRequest; import ei.algobaroapi.domain.solve.dto.request.SolveHistoryListFindRequest; import ei.algobaroapi.domain.solve.dto.response.BojCodeSubmissionResponse; +import ei.algobaroapi.domain.solve.dto.response.CodeSubmissionResponse; import ei.algobaroapi.domain.solve.dto.response.SolveHistoryDetailResponse; import ei.algobaroapi.domain.solve.dto.response.SolveHistoryResponse; import ei.algobaroapi.domain.solve.dto.response.SolveResultResponse; @@ -35,13 +37,23 @@ public class SolveController implements SolveControllerDoc { @Override @PostMapping("/solves/submission") @PreAuthorize("hasRole('ROLE_USER')") - public BojCodeSubmissionResponse submissionCode( + public CodeSubmissionResponse submissionCode( @AuthenticationPrincipal Member member, - @RequestBody @Valid BojCodeSubmissionRequest request + @RequestBody @Valid CodeSubmissionRequest request ) { return solveService.submitCode(member.getId(), request); } + @Override + @PostMapping("/solves/submission-and-compile") + @PreAuthorize("hasRole('ROLE_USER')") + public BojCodeSubmissionResponse submissionCodeAndCompile( + @AuthenticationPrincipal Member member, + @RequestBody @Valid BojCodeSubmissionRequest request + ) { + return solveService.submitCodeAndCompile(member.getId(), request); + } + @Override @GetMapping("/solves/history") @PreAuthorize("hasRole('ROLE_USER')") @@ -64,7 +76,8 @@ public SolveHistoryDetailResponse getHistoryDetail( @Override @GetMapping("/solves/result/{roomShortUuid}") - public SolveResultResponse getSolveResultInRoom(@PathVariable("roomShortUuid") String roomShortUuid) { + public SolveResultResponse getSolveResultInRoom( + @PathVariable("roomShortUuid") String roomShortUuid) { return solveHistoryService.getSolveResultInRoom(roomShortUuid); } } diff --git a/src/main/java/ei/algobaroapi/domain/solve/dto/request/CodeSubmissionRequest.java b/src/main/java/ei/algobaroapi/domain/solve/dto/request/CodeSubmissionRequest.java new file mode 100644 index 0000000..12e4b2c --- /dev/null +++ b/src/main/java/ei/algobaroapi/domain/solve/dto/request/CodeSubmissionRequest.java @@ -0,0 +1,20 @@ +package ei.algobaroapi.domain.solve.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Getter; + +@Schema(description = "코드 제출 요청") +@Getter +@Builder +public class CodeSubmissionRequest { + + @Schema(description = "방 식별 값", example = "123e4567") + private String roomShortUuid; + + @Schema(description = "코드 실행 언어\n\npython - python3\n\njavascript - nodejs\n\njava - java\n\nc++ - cpp", example = "java") + private String language; + + @Schema(description = "코드 실행 코드", example = "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] input = br.readLine().split(\" \");\n int a = Integer.parseInt(input[0]);\n int b = Integer.parseInt(input[1]);\n System.out.println(a + b);\n }\n}") + private String code; +} diff --git a/src/main/java/ei/algobaroapi/domain/solve/dto/response/CodeSubmissionResponse.java b/src/main/java/ei/algobaroapi/domain/solve/dto/response/CodeSubmissionResponse.java new file mode 100644 index 0000000..eae6a6d --- /dev/null +++ b/src/main/java/ei/algobaroapi/domain/solve/dto/response/CodeSubmissionResponse.java @@ -0,0 +1,19 @@ +package ei.algobaroapi.domain.solve.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Schema(description = "코드 제출 응답 결과") +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class CodeSubmissionResponse { + + @Schema(description = "제출 코드", example = "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] input = br.readLine().split(\" \");\n int a = Integer.parseInt(input[0]);\n int b = Integer.parseInt(input[1]);\n System.out.println(a + b);\n }\n}") + private final String submissionCode; + + public static CodeSubmissionResponse of(String submissionCode) { + return new CodeSubmissionResponse(submissionCode); + } +} diff --git a/src/main/java/ei/algobaroapi/domain/solve/service/BojSolveServiceImpl.java b/src/main/java/ei/algobaroapi/domain/solve/service/BojSolveServiceImpl.java index 6bcc83f..3fc7170 100644 --- a/src/main/java/ei/algobaroapi/domain/solve/service/BojSolveServiceImpl.java +++ b/src/main/java/ei/algobaroapi/domain/solve/service/BojSolveServiceImpl.java @@ -8,7 +8,9 @@ import ei.algobaroapi.domain.problem.service.ProblemService; import ei.algobaroapi.domain.solve.dto.BojTestCaseResult; import ei.algobaroapi.domain.solve.dto.request.BojCodeSubmissionRequest; +import ei.algobaroapi.domain.solve.dto.request.CodeSubmissionRequest; import ei.algobaroapi.domain.solve.dto.response.BojCodeSubmissionResponse; +import ei.algobaroapi.domain.solve.dto.response.CodeSubmissionResponse; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -24,7 +26,20 @@ public class BojSolveServiceImpl implements SolveService { private final SolveHistoryService solveHistoryService; @Override - public BojCodeSubmissionResponse submitCode(Long memberId, BojCodeSubmissionRequest request) { + public CodeSubmissionResponse submitCode(Long memberId, CodeSubmissionRequest request) { + solveHistoryService.updateSolveHistoryCode( + memberId, + request.getRoomShortUuid(), + request.getLanguage(), + request.getCode() + ); + + return CodeSubmissionResponse.of(request.getCode()); + } + + @Override + public BojCodeSubmissionResponse submitCodeAndCompile(Long memberId, + BojCodeSubmissionRequest request) { List problemTestCases = problemService.getProblemTestCases( ProblemFindRequest.builder() .problemLink(request.getProblemLink()) diff --git a/src/main/java/ei/algobaroapi/domain/solve/service/SolveService.java b/src/main/java/ei/algobaroapi/domain/solve/service/SolveService.java index 19f20ce..8b81c41 100644 --- a/src/main/java/ei/algobaroapi/domain/solve/service/SolveService.java +++ b/src/main/java/ei/algobaroapi/domain/solve/service/SolveService.java @@ -1,9 +1,13 @@ package ei.algobaroapi.domain.solve.service; import ei.algobaroapi.domain.solve.dto.request.BojCodeSubmissionRequest; +import ei.algobaroapi.domain.solve.dto.request.CodeSubmissionRequest; import ei.algobaroapi.domain.solve.dto.response.BojCodeSubmissionResponse; +import ei.algobaroapi.domain.solve.dto.response.CodeSubmissionResponse; public interface SolveService { - BojCodeSubmissionResponse submitCode(Long memberId, BojCodeSubmissionRequest request); + CodeSubmissionResponse submitCode(Long memberId, CodeSubmissionRequest request); + + BojCodeSubmissionResponse submitCodeAndCompile(Long memberId, BojCodeSubmissionRequest request); } diff --git a/src/main/java/ei/algobaroapi/global/config/swaggerdoc/SolveControllerDoc.java b/src/main/java/ei/algobaroapi/global/config/swaggerdoc/SolveControllerDoc.java index 647107c..d90d437 100644 --- a/src/main/java/ei/algobaroapi/global/config/swaggerdoc/SolveControllerDoc.java +++ b/src/main/java/ei/algobaroapi/global/config/swaggerdoc/SolveControllerDoc.java @@ -3,8 +3,10 @@ import ei.algobaroapi.domain.member.domain.Member; import ei.algobaroapi.domain.solve.domain.SolveHistory; import ei.algobaroapi.domain.solve.dto.request.BojCodeSubmissionRequest; +import ei.algobaroapi.domain.solve.dto.request.CodeSubmissionRequest; import ei.algobaroapi.domain.solve.dto.request.SolveHistoryListFindRequest; import ei.algobaroapi.domain.solve.dto.response.BojCodeSubmissionResponse; +import ei.algobaroapi.domain.solve.dto.response.CodeSubmissionResponse; import ei.algobaroapi.domain.solve.dto.response.SolveHistoryDetailResponse; import ei.algobaroapi.domain.solve.dto.response.SolveHistoryResponse; import ei.algobaroapi.domain.solve.dto.response.SolveResultResponse; @@ -20,7 +22,11 @@ public interface SolveControllerDoc { @Operation(summary = "코드 제출", description = "문제 코드를 제출합니다.") @ApiResponse(responseCode = "201", description = "코드 제출 성공") - BojCodeSubmissionResponse submissionCode(Member member, BojCodeSubmissionRequest request); + CodeSubmissionResponse submissionCode(Member member, CodeSubmissionRequest request); + + @Operation(summary = "코드 제출 및 테스트 케이스 컴파일", description = "문제 코드를 제출합니다.") + @ApiResponse(responseCode = "201", description = "코드 제출 성공") + BojCodeSubmissionResponse submissionCodeAndCompile(Member member, BojCodeSubmissionRequest request); @Operation(summary = "문제 풀이 히스토리 리스트 조회", description = "문제 풀이 히스토리를 상세 조회합니다.") @ApiResponse(responseCode = "200", description = "문제 풀이 히스토리 리스트 조회 성공")