4
4
import acc .hotsix .file_share .dto .FileQueryRequestDTO ;
5
5
import acc .hotsix .file_share .dto .FileQuerySearchResponseDTO ;
6
6
import acc .hotsix .file_share .dto .FileSearchRequestDTO ;
7
- import acc .hotsix .file_share .global .error .InvalidQueryReqParamException ;
8
- import acc .hotsix .file_share .global .error .MissingSearchReqParamException ;
9
- import acc .hotsix .file_share .global .error .NoQueryFilesException ;
7
+ import acc .hotsix .file_share .global .error .exception . InvalidQueryParamException ;
8
+ import acc .hotsix .file_share .global .error .exception . MissingSearchParamException ;
9
+ import acc .hotsix .file_share .global .error .exception . MissingSearchResultException ;
10
10
import lombok .RequiredArgsConstructor ;
11
11
import org .springframework .beans .TypeMismatchException ;
12
12
import org .springframework .data .domain .PageRequest ;
@@ -28,11 +28,11 @@ public class FileQuerySearchController {
28
28
29
29
// 전체 조회
30
30
@ GetMapping ("/all" )
31
- public List <FileQuerySearchResponseDTO > queryAllFiles () throws NoQueryFilesException {
31
+ public List <FileQuerySearchResponseDTO > queryAllFiles () throws MissingSearchResultException {
32
32
List <FileQuerySearchResponseDTO > content = this .fileQuerySearchService .queryAllFile ();
33
33
34
34
if (content .isEmpty ()) {
35
- throw new NoQueryFilesException ();
35
+ throw new MissingSearchResultException ();
36
36
}
37
37
38
38
return content ;
@@ -44,10 +44,10 @@ public List<FileQuerySearchResponseDTO> queryFilesByPage(
44
44
@ RequestParam (value = "name" , required = false , defaultValue = "asc" ) String name ,
45
45
@ RequestParam (value = "time" , required = false , defaultValue = "asc" ) String time ,
46
46
@ RequestParam (value = "page" , required = false , defaultValue = "0" ) Integer page
47
- ) throws NoQueryFilesException , InvalidQueryReqParamException {
47
+ ) throws MissingSearchResultException , InvalidQueryParamException {
48
48
if ((!name .isEmpty () && !name .equals ("asc" ) && !name .equals ("desc" ))
49
49
|| (!time .isEmpty () && !time .equals ("asc" ) && !time .equals ("desc" ))) {
50
- throw new InvalidQueryReqParamException ();
50
+ throw new InvalidQueryParamException ();
51
51
}
52
52
53
53
FileQueryRequestDTO fileQueryRequestDTO = new FileQueryRequestDTO (name , time );
@@ -56,7 +56,7 @@ public List<FileQuerySearchResponseDTO> queryFilesByPage(
56
56
List <FileQuerySearchResponseDTO > content = this .fileQuerySearchService .queryFilesByPage (fileQueryRequestDTO , pageable ).getContent ();
57
57
58
58
if (content .isEmpty ()) {
59
- throw new NoQueryFilesException ();
59
+ throw new MissingSearchResultException ();
60
60
}
61
61
62
62
return content ;
@@ -71,59 +71,20 @@ public List<FileQuerySearchResponseDTO> searchFilesByCriteria (
71
71
@ RequestParam (value = "after" , required = false ) LocalDate after ,
72
72
@ RequestParam (value = "type" , required = false ) String fileType ,
73
73
@ RequestParam (value = "page" , required = false , defaultValue = "0" ) Integer page
74
- ) throws MissingSearchReqParamException , NoQueryFilesException {
74
+ ) throws MissingSearchParamException , MissingSearchResultException {
75
75
if (name == null && path == null && before == null && after == null && fileType == null ) {
76
- throw new MissingSearchReqParamException ();
76
+ throw new MissingSearchParamException ();
77
77
}
78
78
79
79
FileSearchRequestDTO fileSearchRequestDTO = new FileSearchRequestDTO (name , path , before , after , fileType );
80
80
Pageable pageable = PageRequest .of (page , 50 );
81
81
List <FileQuerySearchResponseDTO > content = this .fileQuerySearchService .searchFilesByCriteria (fileSearchRequestDTO , pageable ).getContent ();
82
82
83
83
if (content .isEmpty ()) {
84
- throw new NoQueryFilesException ();
84
+ throw new MissingSearchResultException ();
85
85
}
86
86
87
87
return content ;
88
88
}
89
89
90
- // 조회할 값이 없음
91
- @ ExceptionHandler (NoQueryFilesException .class )
92
- public ResponseEntity <Map <String , Object >> noQueryFilesExceptionHandler (NoQueryFilesException e ) {
93
- Map <String , Object > resultMap = new HashMap <>();
94
- resultMap .put ("error" , e .getMessage ());
95
- return ResponseEntity .status (HttpStatus .NOT_FOUND ).body (resultMap );
96
- }
97
-
98
- // 검색 조건이 없음
99
- @ ExceptionHandler (MissingSearchReqParamException .class )
100
- public ResponseEntity <Map <String , Object >> missingSearchReqParamExceptionHandler (MissingSearchReqParamException e ) {
101
- Map <String , Object > resultMap = new HashMap <>();
102
- resultMap .put ("error" , e .getMessage ());
103
- return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body (resultMap );
104
- }
105
-
106
- // 파라미터가 asc, desc 가 아닌 다른 값임
107
- @ ExceptionHandler (InvalidQueryReqParamException .class )
108
- public ResponseEntity <Map <String , Object >> invalidQueryReqParamExceptionHandler (InvalidQueryReqParamException e ) {
109
- Map <String , Object > resultMap = new HashMap <>();
110
- resultMap .put ("error" , e .getMessage ());
111
- return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body (resultMap );
112
- }
113
-
114
- // 파라미터 타입이 불일치
115
- @ ExceptionHandler (TypeMismatchException .class )
116
- public ResponseEntity <Map <String , Object >> typeMismatchExceptionHandler (TypeMismatchException e ) {
117
- Map <String , Object > resultMap = new HashMap <>();
118
- resultMap .put ("error" , "Invalid parameter data type" );
119
- return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body (resultMap );
120
- }
121
-
122
- // 서버 오류 처리
123
- @ ExceptionHandler (Exception .class )
124
- public ResponseEntity <Map <String , Object >> exceptionHandler (Exception e ) {
125
- Map <String , Object > resultMap = new HashMap <>();
126
- resultMap .put ("error" , "An unexpected error occurred: " + e .getMessage ());
127
- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).body (resultMap );
128
- }
129
90
}
0 commit comments