Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev -> main #149

Merged
merged 8 commits into from
Mar 19, 2024
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 @@ -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
Loading