Skip to content

Commit

Permalink
Merge pull request #149 from 1e5i-Shark/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoguoo authored Mar 19, 2024
2 parents 287a29e + dcc282d commit 33fd123
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ei/algobaroapi/domain/room/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -107,7 +107,8 @@ public RoomDetailResponseDto startCodingTest(String roomShortUuid) {
@Override
@Transactional
public void completeSolveHistory(String roomShortUuid) {
List<SolveHistory> solveHistoryList = solveHistoryService.getSolveHistoryListByRoomShortUuid(roomShortUuid);
List<SolveHistory> solveHistoryList = solveHistoryService.getSolveHistoryListByRoomShortUuid(
roomShortUuid);

solveHistoryList.forEach(solveHistory -> {
SolveStatus solveStatus = problemService.checkSolveResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')")
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ProblemTestCaseResponse> problemTestCases = problemService.getProblemTestCases(
ProblemFindRequest.builder()
.problemLink(request.getProblemLink())
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "문제 풀이 히스토리 리스트 조회 성공")
Expand Down

0 comments on commit 33fd123

Please sign in to comment.