Skip to content

Commit 1b77575

Browse files
authored
Merge pull request #42 from GAT2025/refactor/#35
[Refactor/#35] 회원탈퇴 로직 수정
2 parents 105972a + 24cfadd commit 1b77575

23 files changed

Lines changed: 207 additions & 35 deletions

src/main/kotlin/gat_be/dev/domain/application/repository/ApplicationRepository.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ interface ApplicationRepository : JpaRepository<Application, Long> {
3333
"GROUP BY a.teamId")
3434
fun countPendingApplicantsByTeamIn(@Param("teamIdList") teamIdList: List<Long>): List<TeamApplicantCountDto>
3535

36+
@Modifying
37+
@Query("DELETE FROM Application a " +
38+
"WHERE a.userId = :userId")
39+
fun deleteAllByUserId(@Param("userId") userId: Long)
40+
3641
}

src/main/kotlin/gat_be/dev/domain/application/service/ApplicationService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,8 @@ class ApplicationService(
8181
return applicationRepository.existsByUserIdAndTeamId(userId, teamId)
8282
}
8383

84+
fun deleteAllByUserId(userId: Long) {
85+
applicationRepository.deleteAllByUserId(userId)
86+
}
87+
8488
}

src/main/kotlin/gat_be/dev/domain/auth/controller/AuthController.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ApiResponse
44
import gat_be.dev.common.status.SuccessStatus
55
import gat_be.dev.domain.auth.dto.request.*
66
import gat_be.dev.domain.auth.dto.response.*
7+
import gat_be.dev.domain.auth.facade.UserWithdrawalFacade
78
import gat_be.dev.domain.auth.service.AuthService
89
import io.swagger.v3.oas.annotations.Operation
910
import io.swagger.v3.oas.annotations.media.Content
@@ -18,7 +19,8 @@ import org.springframework.web.bind.annotation.*
1819
@RequestMapping("/auth")
1920
@Tag(name = "Auth")
2021
class AuthController(
21-
private val authService: AuthService
22+
private val authService: AuthService,
23+
private val userWithdrawalFacade: UserWithdrawalFacade
2224
) {
2325

2426
@PostMapping("/signup")
@@ -63,7 +65,7 @@ class AuthController(
6365
fun withdraw(
6466
@AuthenticationPrincipal userId: Long
6567
): ResponseEntity<ApiResponse<Nothing>> {
66-
authService.withdraw(userId)
68+
userWithdrawalFacade.withdraw(userId)
6769
return ApiResponse.success(SuccessStatus.DELETE_USER_SUCCESS)
6870
}
6971

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package gat_be.dev.domain.auth.facade
2+
3+
import gat_be.dev.domain.application.service.ApplicationService
4+
import gat_be.dev.domain.review.service.ReviewService
5+
import gat_be.dev.domain.team.service.TeamService
6+
import gat_be.dev.domain.user.service.UserService
7+
import jakarta.transaction.Transactional
8+
import org.springframework.stereotype.Service
9+
10+
@Service
11+
class UserWithdrawalFacade(
12+
private val applicationService: ApplicationService,
13+
private val userService: UserService,
14+
private val teamService: TeamService,
15+
private val reviewService: ReviewService
16+
) {
17+
18+
// 회원 탈퇴
19+
@Transactional
20+
fun withdraw(userId: Long) {
21+
// TODO: 지원서 삭제?
22+
applicationService.deleteAllByUserId(userId)
23+
reviewService.deleteAllByUserId(userId)
24+
teamService.deleteAllByUserId(userId)
25+
userService.withdrawUser(userId)
26+
}
27+
28+
}

src/main/kotlin/gat_be/dev/domain/auth/service/AuthService.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ class AuthService(
5656
userService.clearRefreshToken(user)
5757
}
5858

59-
// 회원탈퇴
60-
@Transactional
61-
fun withdraw(userId: Long) {
62-
val user = userService.findUserByUserId(userId)
63-
userService.withdrawUser(user)
64-
}
65-
6659
// 아이디 중복 확인
6760
fun checkId(loginId: String): CheckIdResponse {
6861
return userService.checkId(loginId)

src/main/kotlin/gat_be/dev/domain/review/repository/ReviewCategoryRepository.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ package gat_be.dev.domain.review.repository
22

33
import gat_be.dev.domain.review.entity.ReviewCategory
44
import org.springframework.data.jpa.repository.JpaRepository
5+
import org.springframework.data.jpa.repository.Modifying
6+
import org.springframework.data.jpa.repository.Query
7+
import org.springframework.data.repository.query.Param
58

69
interface ReviewCategoryRepository: JpaRepository<ReviewCategory, Long> {
10+
11+
@Modifying
12+
@Query("""
13+
DELETE FROM ReviewCategory rc
14+
WHERE rc.review.teamMemberId = :teamMemberId
15+
""")
16+
fun deleteAllByTeamMemberId(@Param("teamMemberId") teamMemberId: Long)
17+
718
}

src/main/kotlin/gat_be/dev/domain/review/repository/ReviewRepository.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@ package gat_be.dev.domain.review.repository
22

33
import gat_be.dev.domain.review.entity.Review
44
import org.springframework.data.jpa.repository.JpaRepository
5+
import org.springframework.data.jpa.repository.Modifying
56
import org.springframework.data.jpa.repository.Query
67
import org.springframework.data.repository.query.Param
78

89
interface ReviewRepository: JpaRepository<Review, Long> {
910
@Query("SELECT r FROM Review r JOIN FETCH r.categories WHERE r.teamMemberId = :teamMemberId")
1011
fun findAllWithCategoriesByTeamMemberId(@Param("teamMemberId") teamMemberId: Long): List<Review>
12+
13+
@Modifying
14+
@Query("""
15+
DELETE FROM Review r
16+
WHERE r.teamMemberId = :teamMemberId
17+
""")
18+
fun deleteAllByTeamMemberId(@Param("teamMemberId") teamMemberId: Long)
19+
1120
}

src/main/kotlin/gat_be/dev/domain/review/service/ReviewService.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gat_be.dev.domain.review.service
22

33
import gat_be.dev.domain.review.enums.Category
4+
import gat_be.dev.domain.review.repository.ReviewCategoryRepository
45
import gat_be.dev.domain.review.repository.ReviewRepository
56
import gat_be.dev.domain.user.dto.response.UserReviewCategoryCount
67
import gat_be.dev.domain.user.dto.response.UserReviewDetails
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service
1011
@Service
1112
class ReviewService(
1213
private val reviewRepository: ReviewRepository,
14+
private val reviewCategoryRepository: ReviewCategoryRepository
1315
) {
1416

1517
// 유저의 리뷰 카테고리별 개수 집계
@@ -34,4 +36,11 @@ class ReviewService(
3436
reviewCategoryCount = reviewCategoryCount,
3537
)
3638
}
39+
40+
// 유저에 대해 작성된 리뷰 삭제
41+
fun deleteAllByUserId(userId: Long) {
42+
reviewCategoryRepository.deleteAllByTeamMemberId(userId)
43+
reviewRepository.deleteAllByTeamMemberId(userId)
44+
}
45+
3746
}

src/main/kotlin/gat_be/dev/domain/team/dto/response/TeamResponse.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ data class TeamInfoResponse(
2727
) {
2828
companion object {
2929
fun from(team: Team,
30-
leaderName: String
30+
leaderName: String?
3131
): TeamInfoResponse {
3232
return TeamInfoResponse(
3333
teamId = team.teamId,
@@ -39,7 +39,7 @@ data class TeamInfoResponse(
3939
projectStartDate = team.formattedProjectStartDate,
4040
projectEndDate = team.formattedProjectEndDate,
4141
description = team.description,
42-
teamLeaderInfo = TeamLeaderInfo.from(leaderName, team.leader!!)
42+
teamLeaderInfo = TeamLeaderInfo.from(leaderName, team.leader)
4343
)
4444
}
4545
}
@@ -65,18 +65,19 @@ data class TeamTechStackInfo(
6565
}
6666

6767
data class TeamLeaderInfo(
68+
// TODO: leader가 탈퇴했을 시 고려해서 field nullable 여부 수정
6869
val name: String,
6970
val contactInfo: String?,
7071
val portfolioLinks: List<String?>
7172
) {
7273
companion object {
73-
fun from(leaderName: String,
74-
leader: TeamLeader
74+
fun from(leaderName: String?,
75+
leader: TeamLeader?
7576
): TeamLeaderInfo {
7677
return TeamLeaderInfo(
77-
name = leaderName,
78-
contactInfo = leader.contactInfo,
79-
portfolioLinks = listOf(leader.portfolioLink1, leader.portfolioLink2)
78+
name = leaderName ?: "",
79+
contactInfo = leader?.contactInfo,
80+
portfolioLinks = listOf(leader?.portfolioLink1, leader?.portfolioLink2)
8081
)
8182
}
8283
}

src/main/kotlin/gat_be/dev/domain/team/entity/TeamTechStack.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ class TeamTechStack(
5151
if (this.isFulfilled) {
5252
this.isFulfilled = false
5353
}
54-
this.currentCount -= 1
54+
55+
if (this.currentCount > 0) {
56+
this.currentCount -= 1
57+
}
5558
}
5659

5760
fun ensureIsNotFulfilled() {

0 commit comments

Comments
 (0)