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 #161

Merged
merged 14 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
3b5553e
feat #150: ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์— ์Šค์ผ€์ค„๋ง ์ ์šฉ
hyoguoo Mar 19, 2024
e67ba3c
feat #150: ์‹œ์ž‘ ์‹œ๊ฐ„ + ์ง„ํ–‰ ์‹œ๊ฐ„ + ์ผ์ • ์‹œ๊ฐ„ < ํ˜„์žฌ ์‹œ๊ฐ„์— ํ•ด๋‹นํ•˜๋Š” room ๋ฆฌ์ŠคํŠธ ์กฐํšŒํ•˜๋Š” ์ฟผ๋ฆฌ ์ž‘์„ฑ
hyoguoo Mar 19, 2024
03ab535
feat #150: ๋ฐฉ ์ข…๋ฃŒ ์˜ˆ์ • ์‹œ๊ฐ„ ์ดํ›„ 30๋ถ„์ด ์ง€๋‚œ ๋ฐฉ์— ๋Œ€ํ•ด ์‚ญ์ œํ•˜๋Š” ์Šค์ผ€์ค„๋Ÿฌ ์ถ”๊ฐ€
hyoguoo Mar 20, 2024
9c5c25f
feat #157: ์ฝ”๋“œ ์ œ์ถœ ์š”์ฒญ์— ์‹คํŒจ ์ด์œ  ํ•„๋“œ ์ถ”๊ฐ€
GiHoo Mar 20, 2024
da2a989
mod #157: SolveHistory ๋„๋ฉ”์ธ failureReason ์ถ”๊ฐ€
GiHoo Mar 20, 2024
99a73b1
mod #157: response dto์— failureReason ์ถ”๊ฐ€
GiHoo Mar 20, 2024
c8cfcf0
mod #157: failureReason param ์ถ”๊ฐ€
GiHoo Mar 20, 2024
1097939
refactor #157: ๋ฏธ์ œ์ถœ ํ•„๋“œ ์˜์–ด๋กœ ๋ณ€๊ฒฝ
GiHoo Mar 20, 2024
74f04fa
fix #158: ๋ฐฉ ์‹œ์ž‘ ์‹œ ์‹œ์ž‘ ์‹œ๊ฐ„ ์—…๋ฐ์ดํŠธ ํ•˜๋„๋ก ์ˆ˜์ •
hyoguoo Mar 20, 2024
85aa109
mod #158: ๋ฐฉ ์กฐํšŒ ์‹œ ํ’€์ด ์ข…๋ฃŒ ์‹œ๊ฐ„ ๋ฐ˜ํ™˜ ํ•„๋“œ ์ถ”๊ฐ€
hyoguoo Mar 20, 2024
5a7098f
fix #158: ๋ฐฉ ์ •๋ณด ์—…๋ฐ์ดํŠธ ์‹œ ์‹œ์ž‘ ์‹œ๊ฐ„ ๋ณ€๋™ ๋ถˆ๊ฐ€๋Šฅํ•˜๋„๋ก ๋ณ€๊ฒฝ
hyoguoo Mar 20, 2024
4065cc5
fix #158: ๋ฐฉ ์ •๋ณด ์—…๋ฐ์ดํŠธ ์‹œ ๊ถŒํ•œ ์ฒดํฌ ์ถ”๊ฐ€
hyoguoo Mar 20, 2024
ffb15f6
refactor #158: ํ• ๋‹น ์œ„์น˜ ์ƒ์„ฑ์ž๋กœ ๋ณ€๊ฒฝ
hyoguoo Mar 20, 2024
aa1a509
chore #158: warning ์ œ๊ฑฐ
hyoguoo Mar 20, 2024
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
2 changes: 2 additions & 0 deletions src/main/java/ei/algobaroapi/AlgobaroApiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class AlgobaroApiApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public RoomDetailResponseDto createRoom(

@Override
@PatchMapping("/rooms/{roomShortUuid}")
public RoomResponseDto updateRoomById(@PathVariable(name = "roomShortUuid") String roomShortUuid,
@RequestBody @Valid RoomUpdateRequestDto roomUpdateRequestDto) {
return roomService.updateRoomByShortUuid(roomShortUuid, roomUpdateRequestDto);
@PreAuthorize("hasRole('USER')")
public RoomResponseDto updateRoomById(
@PathVariable(name = "roomShortUuid") String roomShortUuid,
@RequestBody @Valid RoomUpdateRequestDto roomUpdateRequestDto,
@AuthenticationPrincipal Member member
) {
return roomService.updateRoomByShortUuid(roomShortUuid, roomUpdateRequestDto, member);
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/ei/algobaroapi/domain/room/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public class Room extends BaseEntity {
private String roomUuid;

@OneToMany(mappedBy = "room", fetch = FetchType.LAZY)
private List<RoomMember> roomMembers = new ArrayList<>();
private List<RoomMember> roomMembers;

@Builder
@SuppressWarnings("java:S107")
public Room(RoomStatus roomStatus, String title, List<String> languages, LocalDateTime startAt,
RoomAccessType roomAccessType, String problemLink, String problemPlatform,
String password, Integer roomLimit, List<String> tags,
Expand All @@ -95,18 +96,15 @@ public Room(RoomStatus roomStatus, String title, List<String> languages, LocalDa
this.tags = tags;
this.timeLimit = timeLimit;
this.roomUuid = UUID.randomUUID().toString();

this.roomMembers = new ArrayList<>();
}

public void update(RoomUpdateRequestDto roomUpdateRequestDto) {
if (roomUpdateRequestDto.getTitle() != null && !roomUpdateRequestDto.getTitle().isEmpty()) {
this.title = roomUpdateRequestDto.getTitle();
}

if (roomUpdateRequestDto.getStartAt() != null && roomUpdateRequestDto.getStartAt()
.isAfter(LocalDateTime.now())) {
this.startAt = roomUpdateRequestDto.getStartAt();
}

if (roomUpdateRequestDto.getLanguages() != null && !roomUpdateRequestDto.getLanguages()
.isEmpty()) {
this.languages = roomUpdateRequestDto.getLanguages();
Expand Down Expand Up @@ -176,5 +174,6 @@ public boolean isHeadCountFull(int roomSize) {

public void updateRoomStatusRunning() {
this.roomStatus = RoomStatus.RUNNING;
this.startAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ei.algobaroapi.domain.room.domain;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -10,4 +12,10 @@ public interface RoomRepository extends JpaRepository<Room, Long>, RoomRepositor

@Query("SELECT r FROM Room r WHERE r.roomUuid LIKE CONCAT(:roomShortUuid, '%')")
Optional<Room> findByRoomUuidStartingWith(String roomShortUuid);

@Query(value =
"SELECT * FROM room WHERE DATE_ADD(start_at, INTERVAL time_limit + :timeOffsetMinutes MINUTE) < :now",
nativeQuery = true
)
List<Room> findListEndAtBefore(LocalDateTime now, int timeOffsetMinutes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ei.algobaroapi.domain.room.domain.RoomAccessType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -15,9 +14,6 @@ public class RoomUpdateRequestDto {
@Schema(description = "๋ฐฉ ์ œ๋ชฉ", example = "๊ฐ™์ด ํ‘ธ์‹ค๋ถ„~")
private String title;

@Schema(description = "๋ฐฉ ์‹œ์ž‘ ์‹œ๊ฐ„", example = "2024-2-18T17:30:00")
private LocalDateTime startAt;

@Schema(description = "์‚ฌ์šฉ ๊ฐ€๋Šฅ ์–ธ์–ด", example = "[\"JAVA\", \"C++\"]")
private List<String> languages;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class RoomDetailResponseDto {
@Schema(description = "ํƒ€์ด๋จธ(Minute)", example = "20")
private Integer timeLimit;

@Schema(description = "๋ฐฉ ์ข…๋ฃŒ ์˜ˆ์ • ์‹œ๊ฐ„", example = "2024-03-04T00:45:18")
private String endTime;

@Schema(description = "๋ฐฉ short UUID", example = "2ad2e9db")
private String roomShortUuid;

Expand Down Expand Up @@ -88,6 +91,9 @@ public static RoomDetailResponseDto of(Room room, List<RoomMemberResponseDto> ro
room.getTags(),
room.getTimeLimit(),
room.getRoomShortUuid(),
room.getStartAt() == null
? null
: room.getStartAt().plusMinutes(room.getTimeLimit()).toString(),
roomMembers
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ei.algobaroapi.domain.room.service;

public interface RoomSchedulerService {

void deleteRoomScheduler();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ei.algobaroapi.domain.room.service;

import ei.algobaroapi.domain.room.domain.Room;
import ei.algobaroapi.domain.room.domain.RoomRepository;
import ei.algobaroapi.domain.room_member.domain.RoomMemberRepository;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@RequiredArgsConstructor
public class RoomSchedulerServiceImpl implements RoomSchedulerService {

private static final int DELETE_ROOM_TIME_OFFSET_MINUTES = 30;
private final RoomRepository roomRepository;
private final RoomMemberRepository roomMemberRepository;

@Override
@Scheduled(cron = "0/10 * * * * *")
@Transactional
public void deleteRoomScheduler() {
List<Room> toDeleteRooms = findExpiredRooms();
deleteRoomsAndMembers(toDeleteRooms);
}

private List<Room> findExpiredRooms() {
return roomRepository.findListEndAtBefore(
LocalDateTime.now(),
DELETE_ROOM_TIME_OFFSET_MINUTES
);
}

private void deleteRoomsAndMembers(List<Room> toDeleteRooms) {
for (Room toDeleteRoom : toDeleteRooms) {
roomMemberRepository.deleteAll(toDeleteRoom.getRoomMembers());
}
roomRepository.deleteAll(toDeleteRooms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public interface RoomService {

RoomDetailResponseDto createRoom(RoomCreateRequestDto roomCreateRequestDto, Member member);

RoomResponseDto updateRoomByShortUuid(String roomShortUuid,
RoomUpdateRequestDto roomUpdateRequestDto);
RoomResponseDto updateRoomByShortUuid(
String roomShortUuid,
RoomUpdateRequestDto roomUpdateRequestDto,
Member member
);

RoomDetailResponseDto getRoomDetailShortUuid(String roomShortUuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ public RoomDetailResponseDto createRoom(RoomCreateRequestDto roomCreateRequestDt

@Override
@Transactional
public RoomResponseDto updateRoomByShortUuid(String roomShortUuid,
RoomUpdateRequestDto roomUpdateRequestDto) {
public RoomResponseDto updateRoomByShortUuid(
String roomShortUuid,
RoomUpdateRequestDto roomUpdateRequestDto,
Member member
) {
roomMemberService.validateHost(roomShortUuid, member.getId());
Room room = getRoomByShortUuid(roomShortUuid);

room.update(roomUpdateRequestDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class SolveHistory extends BaseEntity {
@Column(name = "solve_status", nullable = false)
private SolveStatus solveStatus;

@Column(name = "failure_reason")
private String failureReason;

@Column(name = "problem_link", nullable = false)
private String problemLink;

Expand All @@ -68,14 +71,16 @@ public SolveHistory(Member member, String roomUuid, String problemLink) {
this.startAt = LocalDateTime.now();
this.endAt = null;
this.solveStatus = SolveStatus.FAIL;
this.failureReason = "UNSUBMITTED";
this.problemLink = problemLink;
this.problemPlatform = ProblemPlatform.BOJ;
}

public void updateCodeAndLanguageAndSolveStatus(String code, String language, String solveStatus) {
public void updateCodeAndLanguageAndSolveStatus(String code, String language, SolveStatus solveStatus, String failureReason) {
this.inputCode = code;
this.codeLanguage = language;
this.solveStatus = SolveStatus.valueOf(solveStatus);
this.solveStatus = solveStatus;
this.failureReason = failureReason;
this.endAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ei.algobaroapi.domain.solve.dto.request;

import ei.algobaroapi.domain.solve.domain.SolveStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -19,7 +20,10 @@ public class BojCodeSubmissionRequest {
private String code;

@Schema(description = "์ฝ”๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ", example = "SUCCESS / FAIL")
private String solveStatus;
private SolveStatus solveStatus;

@Schema(description = "์‹คํŒจ ์ด์œ ", example = "MEMORY_LIMIT, TIME_LIMIT, ETC")
private String failureReason;

@Schema(description = "๋ฌธ์ œ ๋งํฌ", example = "https://www.acmicpc.net/problem/1000")
private String problemLink;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ei.algobaroapi.domain.solve.dto.request;

import ei.algobaroapi.domain.solve.domain.SolveStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -19,5 +20,8 @@ public class CodeSubmissionRequest {
private String code;

@Schema(description = "์ฝ”๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ", example = "SUCCESS / FAIL")
private String solveStatus;
private SolveStatus solveStatus;

@Schema(description = "์‹คํŒจ ์ด์œ ", example = "MEMORY_LIMIT, TIME_LIMIT, ETC")
private String failureReason;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SolveHistoryDetailResponse {
@Schema(description = "ํ’€์ด ๊ฒฐ๊ณผ", example = "SUCCESS")
private final String solveStatus;

@Schema(description = "์‹คํŒจ ์ด์œ ", example = "MEMORY_LIMIT / TIME_LIMIT / ETC / NULL")
private final String failureReason;

@Schema(description = "ํ’€์ด ์‹œ๊ฐ„", example = "2024-01-01T00:00:00")
private final String solvedAt;

Expand All @@ -42,6 +45,7 @@ public static SolveHistoryDetailResponse of(SolveHistory solveHistory) {
solveHistory.getCodeLanguage(),
solveHistory.getInputCode(),
solveHistory.getSolveStatus().name(),
solveHistory.getFailureReason(),
solveHistory.getStartAt().toString(),
solveHistory.getProblemPlatform().name(),
solveHistory.getProblemLink()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class SolveHistoryResponse {
@Schema(description = "ํ’€์ด ๊ฒฐ๊ณผ", example = "SUCCESS")
private final String solveStatus;

@Schema(description = "์‹คํŒจ ์ด์œ ", example = "MEMORY_LIMIT / TIME_LIMIT / ETC / NULL")
private final String failureReason;

@Schema(description = "ํ’€์ด ์‹œ๊ฐ„", example = "2024-01-01T00:00:00")
private final String solvedAt;

Expand All @@ -35,6 +38,7 @@ public static SolveHistoryResponse of(SolveHistory solveHistory) {
solveHistory.getRoomUuid(),
solveHistory.getCodeLanguage(),
solveHistory.getSolveStatus().name(),
solveHistory.getFailureReason(),
solveHistory.getStartAt().toString(),
solveHistory.getProblemLink()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ public class SolveResult {

@Schema(description = "ํ’€์ด ๊ฒฐ๊ณผ", example = "SUCCESS")
private final SolveStatus solveStatus;

@Schema(description = "์‹คํŒจ ์ด์œ ", example = "MEMORY_LIMIT / TIME_LIMIT / ETC / NULL")
private final String failureReason;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public CodeSubmissionResponse submitCode(Long memberId, CodeSubmissionRequest re
request.getRoomShortUuid(),
request.getLanguage(),
request.getCode(),
request.getSolveStatus()
request.getSolveStatus(),
request.getFailureReason()
);

return CodeSubmissionResponse.of(request.getCode());
Expand All @@ -58,7 +59,8 @@ public BojCodeSubmissionResponse submitCodeAndCompile(Long memberId,
request.getRoomShortUuid(),
request.getLanguage(),
request.getCode(),
request.getSolveStatus()
request.getSolveStatus(),
request.getFailureReason()
);

return BojCodeSubmissionResponse.of(testCaseResults);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ei.algobaroapi.domain.solve.service;

import ei.algobaroapi.domain.solve.domain.SolveHistory;
import ei.algobaroapi.domain.solve.domain.SolveStatus;
import ei.algobaroapi.domain.solve.dto.request.SolveHistoryListFindRequest;
import ei.algobaroapi.domain.solve.dto.response.SolveHistoryDetailResponse;
import ei.algobaroapi.domain.solve.dto.response.SolveHistoryResponse;
Expand All @@ -18,7 +19,7 @@ PageResponse<SolveHistory, SolveHistoryResponse> getHistoryList(

SolveHistoryDetailResponse getHistoryDetail(Long memberId, Long solveId);

void updateSolveHistoryCode(Long memberId, String roomShortUuid, String language, String code, String solveStatus);
void updateSolveHistoryCode(Long memberId, String roomShortUuid, String language, String code, SolveStatus solveStatus, String failureReason);

SolveResultResponse getSolveResultInRoom(String roomShortUuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ei.algobaroapi.domain.member.service.MemberService;
import ei.algobaroapi.domain.solve.domain.SolveHistory;
import ei.algobaroapi.domain.solve.domain.SolveHistoryRepository;
import ei.algobaroapi.domain.solve.domain.SolveStatus;
import ei.algobaroapi.domain.solve.dto.request.SolveHistoryListFindRequest;
import ei.algobaroapi.domain.solve.dto.response.SolveHistoryDetailResponse;
import ei.algobaroapi.domain.solve.dto.response.SolveHistoryResponse;
Expand Down Expand Up @@ -59,15 +60,16 @@ public void updateSolveHistoryCode(
String roomShortUuid,
String language,
String code,
String solveStatus
SolveStatus solveStatus,
String failureReason
) {
Member findMember = memberService.getMemberById(memberId);
SolveHistory findSolveHistory = getSolveHistoryByMemberAndRoomUuid(
roomShortUuid,
findMember
);

findSolveHistory.updateCodeAndLanguageAndSolveStatus(code, language, solveStatus);
findSolveHistory.updateCodeAndLanguageAndSolveStatus(code, language, solveStatus, failureReason);
}

private SolveHistory getSolveHistoryByMemberAndRoomUuid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public interface RoomControllerDoc {
@Operation(summary = "๋ฐฉ ์ˆ˜์ •", description = "๋ฐฉ ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponse(responseCode = "200", description = "๋ฐฉ ์ˆ˜์ • ์„ฑ๊ณต")
@ApiResponse(responseCode = "E03301", description = "์ˆ˜์ •ํ•˜๋ ค๋Š” ๋ฐฉ ์ •๋ณด๋ฅผ ์ฐพ์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.")
RoomResponseDto updateRoomById(String roomShortUuid, RoomUpdateRequestDto roomUpdateRequestDto);
RoomResponseDto updateRoomById(
String roomShortUuid,
RoomUpdateRequestDto roomUpdateRequestDto,
Member member
);

@Operation(summary = "๊ฐœ๋ณ„ ๋ฐฉ ์ •๋ณด ์กฐํšŒ", description = "short UUID๋ฅผ ํ†ตํ•ด ๋ฐฉ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponse(responseCode = "200", description = "๋ฐฉ ์ •๋ณด ์กฐํšŒ ์„ฑ๊ณต")
Expand Down
Loading