forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewsController.java
More file actions
83 lines (75 loc) · 3.6 KB
/
NewsController.java
File metadata and controls
83 lines (75 loc) · 3.6 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 com.example.solidconnection.news.controller;
import com.example.solidconnection.common.resolver.AuthorizedUser;
import com.example.solidconnection.news.dto.NewsCreateRequest;
import com.example.solidconnection.news.dto.NewsCommandResponse;
import com.example.solidconnection.news.dto.NewsFindResponse;
import com.example.solidconnection.news.dto.NewsResponse;
import com.example.solidconnection.news.dto.NewsUpdateRequest;
import com.example.solidconnection.news.service.NewsCommandService;
import com.example.solidconnection.news.service.NewsQueryService;
import com.example.solidconnection.security.annotation.RequireAdminAccess;
import com.example.solidconnection.siteuser.domain.SiteUser;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequiredArgsConstructor
@RequestMapping("/news")
public class NewsController {
private final NewsQueryService newsQueryService;
private final NewsCommandService newsCommandService;
// todo: 추후 검색 조건 및 Slice 적용
@GetMapping
public ResponseEntity<NewsResponse> searchNews() {
NewsResponse newsResponse = newsQueryService.searchNews();
return ResponseEntity.ok(newsResponse);
}
@GetMapping(value = "/{news_id}")
public ResponseEntity<NewsFindResponse> findNewsById(
@AuthorizedUser SiteUser siteUser,
@PathVariable("news_id") Long newsId
) {
NewsFindResponse newsFindResponse = newsQueryService.findNewsById(newsId);
return ResponseEntity.ok(newsFindResponse);
}
@RequireAdminAccess
@PostMapping
public ResponseEntity<NewsCommandResponse> createNews(
@AuthorizedUser SiteUser siteUser,
@Valid @RequestPart("newsCreateRequest") NewsCreateRequest newsCreateRequest,
@RequestParam(value = "file") MultipartFile imageFile
) {
NewsCommandResponse newsCommandResponse = newsCommandService.createNews(newsCreateRequest, imageFile);
return ResponseEntity.ok(newsCommandResponse);
}
@RequireAdminAccess
@PatchMapping(value = "/{news_id}")
public ResponseEntity<NewsCommandResponse> updateNews(
@AuthorizedUser SiteUser siteUser,
@PathVariable("news_id") Long newsId,
@Valid @RequestPart(value = "newsUpdateRequest") NewsUpdateRequest newsUpdateRequest,
@RequestParam(value = "file", required = false) MultipartFile imageFile
) {
NewsCommandResponse newsCommandResponse = newsCommandService.updateNews(newsId, newsUpdateRequest, imageFile);
return ResponseEntity.ok(newsCommandResponse);
}
@RequireAdminAccess
@DeleteMapping(value = "/{news_id}")
public ResponseEntity<NewsCommandResponse> deleteNewsById(
@AuthorizedUser SiteUser siteUser,
@PathVariable("news_id") Long newsId
) {
NewsCommandResponse newsCommandResponse = newsCommandService.deleteNewsById(newsId);
return ResponseEntity.ok(newsCommandResponse);
}
}