Skip to content

Commit

Permalink
fix: 매칭 리더만 볼 수 있도록 변경 (#166)
Browse files Browse the repository at this point in the history
* fix: ddl-auto validate로 다시 변경

* feat: V1__init 생성

* fix: 유저 검증 로직 삭제

* fix: sql 로그에서 제거

* feat: 요청 로그

* fix: 결제 취소 시 DB에서 payment 삭제

* feat: 리더만 볼 수 있게 예외 추가

* fix: 리더 아니면 예외 발생

* fix: 응답값 변경

* chore: apply lint

* fix: 변수명 변경
  • Loading branch information
UDADDY authored May 27, 2024
1 parent 88126a1 commit 20db0c6
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ enum class ErrorCode(val code: String, val message: String, var status: Int) {
),
// Match
MATCH_NOT_FOUND("MT01", "Match is not Found.", HttpStatus.BAD_REQUEST.value()),
ONLY_TEAM_LEADER_CAN_GET_MATCH(
"MT02",
"Only Team Leader Can Get Match.",
HttpStatus.BAD_REQUEST.value()
),

// External API
EXTERNAL_API_FAILED(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class MatchedMeetingTeamInformationGetResponse(
@field:NotNull @Schema(description = "팀 타입", example = "SINGLE") val teamType: TeamType,
@Schema(description = "팀 이름", example = "팀 이름(1:1인 경우 null)") val teamName: String?,
@field:NotNull @Schema(description = "성별", example = "MALE") val gender: GenderType,
@Schema(description = "팀에 속한 유저 정보") val teamUserList: List<UserProfile>?,
@Schema(description = "팀에 속한 유저 정보") val leaderProfile: UserProfile?,
@Schema(description = "질문 응답값") val information: MatchedInformation?,
@Schema(description = "상대에게 전하는 메세지") val message: String?
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import uoslife.servermeeting.meetingteam.entity.MeetingTeam
import uoslife.servermeeting.meetingteam.entity.enums.TeamType.SINGLE
import uoslife.servermeeting.meetingteam.entity.enums.TeamType.TRIPLE
import uoslife.servermeeting.meetingteam.exception.MeetingTeamNotFoundException
import uoslife.servermeeting.meetingteam.exception.OnlyTeamLeaderCanGetMatchException
import uoslife.servermeeting.meetingteam.service.impl.SingleMeetingService
import uoslife.servermeeting.meetingteam.service.impl.TripleMeetingService
import uoslife.servermeeting.user.dao.UserDao
Expand All @@ -21,8 +22,8 @@ import uoslife.servermeeting.user.exception.UserNotFoundException
@Service
@Transactional(readOnly = true)
class MatchingService(
private val userDao: UserDao,
private val matchedDao: MatchedDao,
private val userDao: UserDao,
private val singleMeetingService: SingleMeetingService,
private val tripleMeetingService: TripleMeetingService,
) {
Expand All @@ -31,10 +32,10 @@ class MatchingService(
val user = userDao.findUserWithMeetingTeam(userId) ?: throw UserNotFoundException()
val meetingTeam = user.team ?: throw MeetingTeamNotFoundException()

val match = getMatchByGender(user, meetingTeam)
if (!isLeader(user)) throw OnlyTeamLeaderCanGetMatchException()

val match = getMatchByGender(user, meetingTeam)
val opponentTeam = getOpponentTeamByGender(user, match)

val opponentUser = opponentTeam.leader ?: throw UserNotFoundException()

return MatchInformationResponse(
Expand Down Expand Up @@ -74,4 +75,9 @@ class MatchingService(
}
return meetingTeamInformationGetResponse.toMatchedMeetingTeamInformationGetResponse()
}

private fun isLeader(user: User): Boolean {
if (user.team!!.leader!!.id == user.id) return true
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class MeetingTeamInformationGetResponse(
@field:NotNull @Schema(description = "팀 타입", example = "SINGLE") val teamType: TeamType,
@Schema(description = "팀 이름", example = "팀 이름(1:1인 경우 null)") val teamName: String?,
@field:NotNull @Schema(description = "성별", example = "MALE") val gender: GenderType,
@Schema(description = "팀에 속한 유저 정보") val teamUserList: List<UserProfile>?,
@Schema(description = "팀에 속한 유저 정보") val opponentLeaderProfile: UserProfile?,
@Schema(description = "질문 응답값") val information: Information?,
@Schema(description = "상대방 선호 응답값") val preference: Preference?,
@Schema(description = "상대에게 전하는 메세지") val message: String?
Expand All @@ -23,7 +23,7 @@ data class MeetingTeamInformationGetResponse(
teamType = teamType,
teamName = teamName,
gender = gender,
teamUserList = teamUserList,
leaderProfile = opponentLeaderProfile,
information = information?.toMatchedInformation(),
message = message
)
Expand All @@ -32,17 +32,17 @@ data class MeetingTeamInformationGetResponse(

data class UserProfile(
@field:NotNull @Schema(description = "유저 이름", example = "이름") val name: String,
@Schema(description = "유저 전화번호", example = "01012341234") val phoneNumber: String?,
// @Schema(description = "유저 전화번호", example = "01012341234") val phoneNumber: String?,
@field:NotNull @Schema(description = "유저 나이", example = "20") val age: Int,
@Schema(description = "유저 키", example = "180") val height: Int?,
// @Schema(description = "유저 키", example = "180") val height: Int?,
@Schema(description = "대학", example = "UOS") val university: University?,
@field:NotNull @Schema(description = "학과", example = "경영학부") val department: String,
@field:NotNull
@Schema(description = "학생 신분", example = "UNDERGRADUATE")
val studentType: StudentType,
@field:NotNull @Schema(description = "카카오톡 ID", example = "kakaoId") val kakaoTalkId: String,
@Schema(description = "흡연 여부", example = "TRUE") val smoking: SmokingType?,
@Schema(description = "종교", example = "CHRISTIAN") val religion: ReligionType?,
// @Schema(description = "종교", example = "CHRISTIAN") val religion: ReligionType?,
@Schema(description = "한달 최소 음주량", example = "1") val drinkingMin: Int?,
@Schema(description = "한달 최대 음주량", example = "10") val drinkingMax: Int?,
@Schema(description = "동물상", example = "[\"DOG\", \"CAT\"]")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package uoslife.servermeeting.meetingteam.exception

import uoslife.servermeeting.global.error.exception.AccessDeniedException
import uoslife.servermeeting.global.error.exception.ErrorCode

class OnlyTeamLeaderCanGetMatchException :
AccessDeniedException(ErrorCode.ONLY_TEAM_LEADER_CAN_GET_MATCH)
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class PortOneService(
payment.price
)

payment.status = PaymentStatus.REFUND
paymentRepository.delete(payment)
return PaymentResponseDto.PaymentRefundResponse(true, "")
} catch (e: ExternalApiFailedException) {
payment.status = PaymentStatus.REFUND_FAILED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class SingleMeetingService(
return meetingServiceUtils.toMeetingTeamInformationGetResponse(
user.userPersonalInformation.gender,
TeamType.SINGLE,
listOf(user),
user,
information,
preference,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class TripleMeetingService(
return meetingServiceUtils.toMeetingTeamInformationGetResponse(
user.userPersonalInformation.gender,
TeamType.TRIPLE,
userList,
user,
information,
preference,
meetingTeam.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MeetingServiceUtils {
fun toMeetingTeamInformationGetResponse(
gender: GenderType,
teamType: TeamType,
userList: List<User>,
user: User,
information: Information,
preference: Preference,
teamName: String?,
Expand All @@ -27,26 +27,21 @@ class MeetingServiceUtils {
teamType = teamType,
teamName = teamName,
gender = gender,
teamUserList =
userList.map {
UserProfile(
name = it.name,
phoneNumber = it.phoneNumber,
age = it.userPersonalInformation.age,
height = it.userPersonalInformation.height,
university = it.userPersonalInformation.university,
department = it.userPersonalInformation.department,
studentType = it.userPersonalInformation.studentType,
kakaoTalkId = it.kakaoTalkId,
smoking = it.userPersonalInformation.smoking,
religion = it.userPersonalInformation.religion,
drinkingMin = it.userPersonalInformation.drinkingMin,
drinkingMax = it.userPersonalInformation.drinkingMax,
spiritAnimal = it.userPersonalInformation.spiritAnimal,
mbti = it.userPersonalInformation.mbti,
interest = it.userPersonalInformation.interest
)
},
opponentLeaderProfile =
UserProfile(
name = user.name,
age = user.userPersonalInformation.age,
university = user.userPersonalInformation.university,
department = user.userPersonalInformation.department,
studentType = user.userPersonalInformation.studentType,
kakaoTalkId = user.kakaoTalkId,
smoking = user.userPersonalInformation.smoking,
drinkingMin = user.userPersonalInformation.drinkingMin,
drinkingMax = user.userPersonalInformation.drinkingMax,
spiritAnimal = user.userPersonalInformation.spiritAnimal,
mbti = user.userPersonalInformation.mbti,
interest = user.userPersonalInformation.interest
),
information = information,
preference = preference,
message = message
Expand Down

0 comments on commit 20db0c6

Please sign in to comment.