-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectCommunityController.java
More file actions
83 lines (70 loc) · 3.67 KB
/
ProjectCommunityController.java
File metadata and controls
83 lines (70 loc) · 3.67 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
package NextLevel.demo.project.community.controller;
import NextLevel.demo.common.SuccessResponse;
import NextLevel.demo.project.community.dto.request.SaveCommunityDto;
import NextLevel.demo.project.community.service.ProjectCommunityAnswerService;
import NextLevel.demo.project.community.dto.response.ResponseCommunityListDto;
import NextLevel.demo.project.community.service.ProjectCommunityAskService;
import NextLevel.demo.util.jwt.JWTUtil;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@Slf4j
@RequiredArgsConstructor
public class ProjectCommunityController {
private final ProjectCommunityAskService askService;
private final ProjectCommunityAnswerService answerService;
// ask 관련
// list
@GetMapping("/public/project/{projectId}/community")
public ResponseEntity getProjectCommunity(@PathVariable Long projectId) {
return ResponseEntity.ok().body(new SuccessResponse("success", new ResponseCommunityListDto(askService.selectAll(projectId))));
}
// 생성
@PostMapping("/api1/project/{projectId}/community")
public ResponseEntity<?> saveProjectCommunityAsk(@PathVariable("projectId") Long projectId, @RequestBody @Valid SaveCommunityDto dto) {
dto.setUserId(JWTUtil.getUserIdFromSecurityContext());
dto.setId(projectId);
askService.create(dto);
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", null));
}
// 수정
@PostMapping("/api1/project/community/{communityId}")
public ResponseEntity<?> updateProjectCommunityAsk(@PathVariable("communityId") Long communityId, @RequestBody @Valid SaveCommunityDto dto) {
dto.setUserId(JWTUtil.getUserIdFromSecurityContext());
dto.setId(communityId);
askService.update(dto);
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", null));
}
@DeleteMapping("/api1/project/community/{communityId}")
public ResponseEntity<?> deleteProjectCommunity(@PathVariable("communityId") Long communityId) {
askService.delete(communityId,JWTUtil.getUserIdFromSecurityContext());
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", null));
}
// answer 관련
// 생성
@PostMapping("/api1/project/{askId}/community/answer")
public ResponseEntity<?> saveProjectCommunityAnswer(@PathVariable("askId") Long askId, @RequestBody @Valid SaveCommunityDto dto) {
dto.setUserId(JWTUtil.getUserIdFromSecurityContext());
dto.setId(askId);
answerService.addAnswer(dto);
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", null));
}
// 수정
@PostMapping("/api1/project/community/{answerId}/answer")
public ResponseEntity<?> updateProjectCommunityAnswer(@PathVariable("answerId") Long answerId, @RequestBody @Valid SaveCommunityDto dto) {
dto.setUserId(JWTUtil.getUserIdFromSecurityContext());
dto.setId(answerId);
answerService.updateAnswer(dto);
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", null));
}
@DeleteMapping("/api1/project/community/{answerId}/answer")
public ResponseEntity<?> deleteProjectCommunityAnswer(@PathVariable("answerId") Long answerId) {
answerService.deleteAnswer(answerId,JWTUtil.getUserIdFromSecurityContext());
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", null));
}
}