Skip to content

Commit

Permalink
Merge pull request #287 from 6QuizOnTheBlock/be/fix
Browse files Browse the repository at this point in the history
Be/fix
  • Loading branch information
Henry-Cha authored May 12, 2024
2 parents 48806c7 + 42517f9 commit 6102727
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quiz.ourclass.domain.challenge.controller;

import com.quiz.ourclass.domain.challenge.dto.response.MatchingRoomResponse;
import com.quiz.ourclass.global.dto.ResultResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -21,7 +22,7 @@ public interface GroupControllerDocs {
+ "์ž„์‹œ ๋Œ€๊ธฐ๋ฐฉ์˜ ID (Redis KEY) ์‘๋‹ต.",
responses = {
@ApiResponse(responseCode = "200", description = "(message : \"Success\")",
content = @Content(schema = @Schema(implementation = String.class, description = "๋Œ€๊ธฐ๋ฐฉ KEY")))
content = @Content(schema = @Schema(implementation = MatchingRoomResponse.class)))
})
@PostMapping("/groups/matchingroom")
ResponseEntity<ResultResponse<?>> createMatchingRoom(
Expand Down Expand Up @@ -53,7 +54,9 @@ ResponseEntity<ResultResponse<?>> joinMatchingRoom(
+ "์ „์ฒด ๋ฉค๋ฒ„์—๊ฒŒ SSE(CREATE_GROUP) ์ „์†ก",
responses = {
@ApiResponse(responseCode = "200", description = "(message : \"Success\")",
content = @Content(schema = @Schema(implementation = Long.class, description = "์ƒ์„ฑ๋œ ๊ทธ๋ฃน id")))
content = @Content(schema = @Schema(implementation = Long.class, description = "์ƒ์„ฑ๋œ ๊ทธ๋ฃน id"))),
@ApiResponse(responseCode = "400", description = "(message : \"๊ทธ๋ฃน ์ตœ์†Œ ์ธ์›์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.\")", content = @Content)

})
@PostMapping("/groups")
ResponseEntity<ResultResponse<?>> createGroup(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.quiz.ourclass.domain.challenge.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
@Schema(description = "๊ทธ๋ฃน ๋งค์นญ๋Œ€๊ธฐ๋ฐฉ ์ƒ์„ฑ ์‘๋‹ต DTO")
public record MatchingRoomResponse(
@Schema(description = "๊ทธ๋ฃน ๋งค์นญ๋Œ€๊ธฐ๋ฐฉ id")
String dataKey,
@Schema(description = "๊ทธ๋ฃน ์ตœ์†Œ์ธ์›")
int minCount
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,22 @@ public long createReport(ReportRequest reportRequest, MultipartFile file) {
@Transactional
@Override
public void confirmReport(long id, ReportType reportType) {
//TODO: ํ•ด๋‹น ํ•™๊ธ‰ ์„ ์ƒ๊ถŒํ•œ ์ฒดํฌ ํ•„์š”
Report report = reportRepository.findById(id)
.orElseThrow(() -> new GlobalException(ErrorCode.REPORT_NOW_FOUND));
report.setAcceptStatus(reportType);
Member loginMember = accessUtil.getMember().orElseThrow();
Organization organization = report.getChallengeGroup().getChallenge().getOrganization();
if (accessUtil.isOrganizationManager(loginMember, organization.getId()).isEmpty()) {
throw new GlobalException(ErrorCode.MEMBER_NOT_MANAGER);
}
report.setAcceptStatus(reportType);
if (reportType.equals(ReportType.APPROVE)) {
report.getChallengeGroup().getGroupMembers().forEach(groupMember -> {
Member member = groupMember.getMember();
MemberOrganization memberOrganization = memberOrganizationRepository.findByOrganizationAndMember(
organization, member).orElseThrow(
() -> new GlobalException(ErrorCode.MEMBER_ORGANIZATION_NOT_FOUND));
memberOrganization.updateChallengeCount();
memberOrganization.updateExp(report.getChallengeGroup().getChallenge().getReward());
memberOrganizationRepository.save(memberOrganization);
});
}
Expand Down Expand Up @@ -209,6 +213,9 @@ protected void challengeClosingReload() {
challenges.forEach(challenge -> {
if (challenge.getEndTime().isBefore(LocalDateTime.now())) {
challengeClosing(challenge);
} else {
schedulingService.scheduleTask(challenge, this::challengeClosing,
challenge.getEndTime());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.quiz.ourclass.domain.challenge.service;

import com.quiz.ourclass.domain.challenge.dto.response.MatchingRoomResponse;

public interface GroupService {

String createMatchingRoom(long challengeId);
MatchingRoomResponse createMatchingRoom(long challengeId);

boolean joinMatchingRoom(String key, boolean joinStatus);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.quiz.ourclass.global.exception.ErrorCode.CHALLENGE_NOT_FOUND;
import static com.quiz.ourclass.global.exception.ErrorCode.PERMISSION_DENIED;

import com.quiz.ourclass.domain.challenge.dto.response.MatchingRoomResponse;
import com.quiz.ourclass.domain.challenge.entity.Challenge;
import com.quiz.ourclass.domain.challenge.entity.ChallengeGroup;
import com.quiz.ourclass.domain.challenge.entity.GroupMember;
Expand Down Expand Up @@ -42,12 +43,18 @@ public class GroupServiceImpl implements GroupService {

@Transactional
@Override
public String createMatchingRoom(long challengeId) {
public MatchingRoomResponse createMatchingRoom(long challengeId) {
long MemberId = accessUtil.getMember()
.orElseThrow(() -> new GlobalException(ErrorCode.MEMBER_NOT_FOUND)).getId();
String dataKey = makeGroupKey(challengeId, MemberId);
redisUtil.setAdd(dataKey, String.valueOf(MemberId));
return dataKey;
Challenge challenge = challengeRepository.findById(challengeId)
.orElseThrow(() -> new GlobalException(CHALLENGE_NOT_FOUND));
int minCount = challenge.getMinCount();
return MatchingRoomResponse.builder()
.dataKey(dataKey)
.minCount(minCount)
.build();
}

@Transactional
Expand Down Expand Up @@ -77,6 +84,9 @@ public long createGroup(String key) {
Set<String> members = redisUtil.setMembers(key);
Challenge challenge = challengeRepository.findById(getChallengeIdFromKey(key))
.orElseThrow(() -> new GlobalException(CHALLENGE_NOT_FOUND));
if (members.size() < challenge.getMinCount()) {
throw new GlobalException(ErrorCode.NOT_ENOUGH_GROUP_MEMBER);
}
long leaderId = getLeaderIdFromKey(key);
LocalDateTime createTime = LocalDateTime.now();
ChallengeGroup group = ChallengeGroup.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public SendRelayResponse sendRelay(long id) {
.orElseThrow(() -> new GlobalException(ErrorCode.RELAY_NOT_FOUND));
RelayMember prevRelayMember = relayMemberRepository.findByRelayAndNextMember(relay, member)
.orElseThrow(() -> new GlobalException(ErrorCode.RELAY_MEMBER_NOT_FOUND));
MemberOrganization memberOrganization = memberOrganizationRepository.findByOrganizationAndMember(
relay.getOrganization(), member).orElseThrow();
memberOrganization.updateExp(ConstantUtil.RELAY_REWARD);
return SendRelayResponse.builder()
.prevMemberName(prevRelayMember.getCurMember().getName())
.prevQuestion(prevRelayMember.getQuestion()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public enum ErrorCode {
EXIST_RUNNING_CHALLENGE(HttpStatus.BAD_REQUEST, "์ข…๋ฃŒ๋˜์ง€ ์•Š์€ ํ•จ๊ป˜๋‹ฌ๋ฆฌ๊ธฐ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค."),
CHALLENGE_IS_END(HttpStatus.BAD_REQUEST, "์ข…๋ฃŒ๋œ ํ•จ๊ป˜๋‹ฌ๋ฆฌ๊ธฐ์ž…๋‹ˆ๋‹ค."),
NOT_CHALLENGE_GROUP_LEADER(HttpStatus.BAD_REQUEST, "๋ ˆํฌํŠธ ์ œ์ถœ์€ ๊ทธ๋ฃน ๋ฆฌ๋”๋งŒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค."),
NOT_ENOUGH_GROUP_MEMBER(HttpStatus.BAD_REQUEST, "๊ทธ๋ฃน ์ตœ์†Œ ์ธ์›์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค."),

//quiz
NO_QUIZ_GAME(HttpStatus.NOT_FOUND, "ํ•ด๋‹น ๋‹จ์ฒด์—์„œ ์ƒ์„ฑํ•œ ํ€ด์ฆˆ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public abstract class ConstantUtil {
public static final String BLACKLIST_ACCESS_TOKEN = "AT:";
public static final String QUIZ_GAME = "quiz:";
public static final int RELAY_DEMERIT = -100;
public static final int RELAY_REWARD = 50;
public static final Long RELAY_TIMEOUT_DAY = 1L;

}

0 comments on commit 6102727

Please sign in to comment.