-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from Gamegoo-repo/feat/186
[Feat/186] ๋งค์นญ ์ฐ์ ์์ API ๊ตฌํ
- Loading branch information
Showing
22 changed files
with
1,791 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,5 @@ | |
|
||
public enum Mike { | ||
UNAVAILABLE, | ||
ONLY_LISTEN, | ||
AVAILABLE, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/com/gamegoo/gamegoo_v2/account/member/service/MemberGameStyleService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.gamegoo.gamegoo_v2.account.member.service; | ||
|
||
import com.gamegoo.gamegoo_v2.account.member.domain.Member; | ||
import com.gamegoo.gamegoo_v2.account.member.domain.MemberGameStyle; | ||
import com.gamegoo.gamegoo_v2.account.member.repository.MemberGameStyleRepository; | ||
import com.gamegoo.gamegoo_v2.core.exception.MemberException; | ||
import com.gamegoo.gamegoo_v2.core.exception.common.ErrorCode; | ||
import com.gamegoo.gamegoo_v2.game.domain.GameStyle; | ||
import com.gamegoo.gamegoo_v2.game.repository.GameStyleRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MemberGameStyleService { | ||
|
||
private final GameStyleRepository gameStyleRepository; | ||
private final MemberGameStyleRepository memberGameStyleRepository; | ||
|
||
/** | ||
* @param member ํ์ | ||
* @param gameStyleIdList ์์ ํ ๊ฒ์ ์คํ์ผ ๋ฆฌ์คํธ | ||
*/ | ||
@Transactional | ||
public void updateGameStyle(Member member, List<Long> gameStyleIdList) { | ||
// request์ Gamestyle ์กฐํ | ||
List<GameStyle> requestGameStyleList = findRequestGameStyle(gameStyleIdList); | ||
|
||
// ํ์ฌ DB์ GameStyle ์กฐํ | ||
List<MemberGameStyle> currentMemberGameStyleList = findCurrentMemberGameStyleList(member); | ||
|
||
// request์ ์๊ณ , DB์ ์๋ GameStyle ์ญ์ | ||
removeUnnecessaryGameStyles(member, requestGameStyleList, currentMemberGameStyleList); | ||
|
||
// request์ ์๊ณ , DB์ ์๋ GameStyle ์ถ๊ฐ | ||
addNewGameStyles(member, requestGameStyleList, currentMemberGameStyleList); | ||
} | ||
|
||
/** | ||
* request id๋ก GameStyle Entity ์กฐํ | ||
* | ||
* @return request์ GamestyleList | ||
*/ | ||
private List<GameStyle> findRequestGameStyle(List<Long> gameStyleIdList) { | ||
return gameStyleIdList.stream() | ||
.map(id -> gameStyleRepository.findById(id).orElseThrow(() -> new MemberException(ErrorCode.GAMESTYLE_NOT_FOUND))) | ||
.toList(); | ||
} | ||
|
||
/** | ||
* ํ์ฌ DB์ MemberGameStyle List ์กฐํ | ||
* | ||
* @return MemberGameStyleList | ||
*/ | ||
private List<MemberGameStyle> findCurrentMemberGameStyleList(Member member) { | ||
return new ArrayList<>(member.getMemberGameStyleList()); | ||
} | ||
|
||
/** | ||
* ๋ถํ์ํ GameStyle ์ ๊ฑฐ | ||
* | ||
* @param member ํ์ | ||
* @param requestedGameStyles ์๋ก์ด GameStyle | ||
* @param currentMemberGameStyles ํ์ฌ Gamestyle | ||
*/ | ||
@Transactional | ||
protected void removeUnnecessaryGameStyles(Member member, List<GameStyle> requestedGameStyles, | ||
List<MemberGameStyle> currentMemberGameStyles) { | ||
currentMemberGameStyles.stream() | ||
.filter(mgs -> !requestedGameStyles.contains(mgs.getGameStyle())) | ||
.forEach(mgs -> { | ||
mgs.removeMember(member); | ||
memberGameStyleRepository.delete(mgs); | ||
}); | ||
} | ||
|
||
/** | ||
* ์๋ก์ด GameStyle ์ถ๊ฐ | ||
* | ||
* @param member ์ฌ์ฉ์ | ||
* @param requestedGameStyles ๋ณ๊ฒฝ ํ ๊ฒ์์คํ์ผ | ||
* @param currentMemberGameStyles ๋ณ๊ฒฝ ์ ๊ฒ์์คํ์ผ | ||
*/ | ||
@Transactional | ||
protected void addNewGameStyles(Member member, List<GameStyle> requestedGameStyles, | ||
List<MemberGameStyle> currentMemberGameStyles) { | ||
List<GameStyle> currentGameStyles = currentMemberGameStyles.stream() | ||
.map(MemberGameStyle::getGameStyle) | ||
.toList(); | ||
|
||
requestedGameStyles.stream() | ||
.filter(gs -> !currentGameStyles.contains(gs)) | ||
.forEach(gs -> { | ||
MemberGameStyle newMemberGameStyle = MemberGameStyle.create(gs, member); | ||
memberGameStyleRepository.save(newMemberGameStyle); | ||
}); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/gamegoo/gamegoo_v2/matching/Controller/MatchingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.gamegoo.gamegoo_v2.matching.Controller; | ||
|
||
import com.gamegoo.gamegoo_v2.core.common.ApiResponse; | ||
import com.gamegoo.gamegoo_v2.matching.dto.request.InitializingMatchingRequest; | ||
import com.gamegoo.gamegoo_v2.matching.dto.response.PriorityListResponse; | ||
import com.gamegoo.gamegoo_v2.matching.service.MatchingFacadeService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "Matching", description = "๋งค์นญ ์ ๋ณด ๊ด๋ จ API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v2/internal") | ||
@Validated | ||
public class MatchingController { | ||
|
||
private final MatchingFacadeService matchingFacadeService; | ||
|
||
@Operation(summary = "๋งค์นญ ์ฐ์ ์์ ๊ณ์ฐ ๋ฐ ๊ธฐ๋ก ์ ์ฅ API", description = "API for calculating and recording matching") | ||
@PostMapping("/matching/priority/{memberId}") | ||
public ApiResponse<PriorityListResponse> InitializeMatching(@PathVariable(name = "memberId") Long memberId, | ||
@RequestBody @Valid InitializingMatchingRequest request) { | ||
return ApiResponse.ok(matchingFacadeService.calculatePriorityAndRecording(memberId, request)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.