-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserController.java
More file actions
96 lines (83 loc) · 4.05 KB
/
UserController.java
File metadata and controls
96 lines (83 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.example.profileem.controller;
import com.example.profileem.domain.Party;
import com.example.profileem.repository.UserRepository;
import com.example.profileem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import java.util.Optional;
@Tag(name = "User")
@RestController
@RequestMapping("/user")
public class UserController {
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
// 사용자가 받은 개인 프로필 카드 ID 추가
@Operation(summary = "사용자가 받은 개인 프로필 카드 ID 추가", description = "사용자가 받은 개인 프로필 카드 ID 추가")
@PostMapping("/{user_id}/card")
public ResponseEntity<String> addReceivedCardId(
@RequestParam("user_id") Long userId,
@PathVariable("card_id") Long cardId) {
try {
userService.addReceivedCardId(userId, cardId);
return ResponseEntity.ok("Card added to user's received cards");
} catch (IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User not found");
}
}
// 사용자가 받은 개인 프로필 카드 ID 목록 조희
@Operation(summary = "사용자가 받은 개인 프로필 카드 ID 목록 조희", description = "사용자가 받은 개인 프로필 카드 ID 목록 조희")
@GetMapping("/{user_id}/cards")
public ResponseEntity<List<Long>> getReceivedCardIds(@PathVariable("user_id") Long userId) {
try {
List<Long> receivedCardIds = userService.getReceivedCardIds(userId);
return ResponseEntity.ok(receivedCardIds);
} catch (IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
}
// 사용자가 받은 개인 프로필 카드 삭제
@Operation(summary = "사용자가 받은 개인 프로필 카드 삭제", description = "사용자가 받은 개인 프로필 카드 삭제")
@DeleteMapping("/{user_id}/{card_id}")
public ResponseEntity<String> deleteReceivedCard(
@RequestParam("user_id") Long userId,
@PathVariable("card_id") Long cardId) {
try {
userService.deleteReceivedCard(userId, cardId);
return ResponseEntity.ok("Received card deleted successfully");
} catch (IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User or card not found");
}
}
// 사용자가 속한 파티 목록 조회
@Operation(summary = "사용자가 속한 파티 목록 조회", description = "사용자가 속한 파티 목록 조회")
@GetMapping("/{userId}/parties")
public ResponseEntity<List<Long>> getUserPartyIds(@PathVariable("userId") Long userId) {
try {
List<Long> userPartyIds = userService.getUserPartyIds(userId);
return ResponseEntity.ok(userPartyIds);
} catch (IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
}
// 파티에서 탈퇴
@Operation(summary = "내 그룹에서 파티 삭제", description = "내 그룹에서 파티 삭제(파티에서 탈퇴)")
@DeleteMapping("/party/{party_id}") // 내 그룹에서 파티 삭제
public ResponseEntity<String> deletePartyInUserGroup(
@RequestParam("user_id") Long userId,
@PathVariable("party_id") Long partyId ) {
try {
userService.deletePartyInUserGroup(userId, partyId);
return ResponseEntity.ok("Party deleted successfully");
} catch (IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User or party not found");
}
}
}