File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
src/main/kotlin/com/example/lsa/lab Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import com.example.lsa.lab.dto.LabDto
4
4
import com.example.lsa.lab.dto.LabMembershipRequestDto
5
5
import com.example.lsa.member.dto.UserInfoDto
6
6
import com.example.lsa.lab.service.LabService
7
+ import org.springframework.http.HttpStatus
7
8
import org.springframework.http.ResponseEntity
8
9
import org.springframework.web.bind.annotation.*
9
10
@@ -15,8 +16,12 @@ class LabController(
15
16
16
17
@PostMapping(" /request-membership" )
17
18
fun requestMembership (@RequestParam userId : Long , @RequestParam labId : Long ): ResponseEntity <String > {
18
- labService.requestLabMembership(userId, labId)
19
- return ResponseEntity .ok(" 멤버쉽 요청 전송" )
19
+ return try {
20
+ labService.requestLabMembership(userId, labId)
21
+ ResponseEntity .ok(" 멤버쉽 요청이 성공적으로 처리되었습니다." )
22
+ }catch (e: IllegalStateException ){
23
+ ResponseEntity .status(HttpStatus .BAD_REQUEST ).body(e.message)
24
+ }
20
25
}
21
26
22
27
@PostMapping(" /respond-to-request" )
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ import org.springframework.stereotype.Repository
8
8
interface LabMembershipRequestRepository : JpaRepository <LabMembershipRequest , Long > {
9
9
fun findAllByLab_Id (labId : Long ): List <LabMembershipRequest >
10
10
fun findAllByUser_Id (userId : Long ): List <LabMembershipRequest >
11
+ fun findByUserIdAndLabId (userId : Long , labId : Long ): LabMembershipRequest ?
11
12
}
Original file line number Diff line number Diff line change @@ -24,11 +24,19 @@ class LabService(
24
24
val user = userRepository.findById(userId).orElseThrow { IllegalArgumentException (" 사용자를 찾을 수 없습니다" ) }
25
25
val lab = labRepository.findById(labId).orElseThrow { IllegalArgumentException (" 연구실을 찾을 수 없습니다." ) }
26
26
27
- if (user.role == Role .STUDENT ) {
27
+ val existingUserLab = userLabRepository.findByUserIdAndLabId(userId, labId)
28
+
29
+ if (existingUserLab != null ){
30
+ throw IllegalStateException (" 이미 가입 중인 연구실입니다." )
31
+ }
32
+
33
+ val existingRequest = requestRepository.findByUserIdAndLabId(userId, labId)
34
+
35
+ if (existingRequest == null ) {
28
36
val request = LabMembershipRequest (user = user, lab = lab)
29
37
requestRepository.save(request)
30
38
} else {
31
- throw IllegalStateException (" 학생만 요청 가능합니다. " )
39
+ throw IllegalStateException (" 이미 가입 요청이 있습니다: 사용자 ID = ${user.id} , 연구실 ID = ${lab.id} " )
32
40
}
33
41
}
34
42
You can’t perform that action at this time.
0 commit comments