|
| 1 | +package com.wooteco.wiki.document.controller; |
| 2 | + |
| 3 | +import com.wooteco.wiki.document.domain.Document; |
| 4 | +import com.wooteco.wiki.document.domain.dto.*; |
| 5 | +import com.wooteco.wiki.document.service.DocumentSearchService; |
| 6 | +import com.wooteco.wiki.document.service.DocumentService; |
| 7 | +import com.wooteco.wiki.document.service.DocumentServiceJava; |
| 8 | +import com.wooteco.wiki.global.common.ApiResponse; |
| 9 | +import com.wooteco.wiki.global.common.ApiResponse.SuccessBody; |
| 10 | +import com.wooteco.wiki.global.common.ApiResponseGenerator; |
| 11 | +import com.wooteco.wiki.global.common.PageRequestDto; |
| 12 | +import com.wooteco.wiki.global.common.ResponseDto; |
| 13 | +import com.wooteco.wiki.history.domain.dto.HistoryDetailResponse; |
| 14 | +import com.wooteco.wiki.history.domain.dto.HistoryResponse; |
| 15 | +import com.wooteco.wiki.history.service.HistoryService; |
| 16 | +import com.wooteco.wiki.organizationdocument.dto.OrganizationDocumentSearchResponse; |
| 17 | +import io.swagger.v3.oas.annotations.Operation; |
| 18 | +import java.util.List; |
| 19 | +import java.util.UUID; |
| 20 | +import lombok.RequiredArgsConstructor; |
| 21 | +import org.springframework.data.domain.Page; |
| 22 | +import org.springframework.web.bind.annotation.*; |
| 23 | + |
| 24 | +@RestController |
| 25 | +@RequestMapping("/document") |
| 26 | +@RequiredArgsConstructor |
| 27 | +public class DocumentController { |
| 28 | + |
| 29 | + private final DocumentService documentService; |
| 30 | + private final HistoryService historyService; |
| 31 | + private final DocumentSearchService documentSearchService; |
| 32 | + private final DocumentServiceJava documentServiceJava; |
| 33 | + |
| 34 | + @Operation(summary = "위키 글 작성", description = "위키 글을 작성합니다.") |
| 35 | + @PostMapping |
| 36 | + public ApiResponse<SuccessBody<DocumentResponse>> post(@RequestBody CrewDocumentCreateRequest crewDocumentCreateRequest) { |
| 37 | + DocumentResponse response = documentService.postCrewDocument(crewDocumentCreateRequest); |
| 38 | + return ApiResponseGenerator.success(response); |
| 39 | + } |
| 40 | + |
| 41 | + @Operation(summary = "랜덤 위키 글 조회", description = "랜덤으로 위키 글을 조회합니다.") |
| 42 | + @GetMapping("/random") |
| 43 | + public ApiResponse<SuccessBody<DocumentResponse>> getRandom() { |
| 44 | + DocumentResponse response = documentService.getRandom(); |
| 45 | + return ApiResponseGenerator.success(response); |
| 46 | + } |
| 47 | + |
| 48 | + @Operation(summary = "위키 글 전체 조회", description = "페이지네이션을 통해 모든 위키 글을 조회합니다.") |
| 49 | + @GetMapping("") |
| 50 | + public ApiResponse<SuccessBody<ResponseDto<List<Document>>>> findAll(@ModelAttribute PageRequestDto pageRequestDto) { |
| 51 | + Page<Document> pageResponses = documentService.findAll(pageRequestDto); |
| 52 | + return ApiResponseGenerator.success(convertToResponse(pageResponses)); |
| 53 | + } |
| 54 | + |
| 55 | + @Operation(summary = "제목으로 위키 글 조회", description = "제목을 통해 위키 글을 조회합니다.") |
| 56 | + @GetMapping("title/{title}") |
| 57 | + public ApiResponse<SuccessBody<Object>> get(@PathVariable String title) { |
| 58 | + Object response = documentService.get(title); |
| 59 | + return ApiResponseGenerator.success(response); |
| 60 | + } |
| 61 | + |
| 62 | + @Operation(summary = "제목으로 UUID 조회", description = "제목을 통해 위키 글의 UUID를 조회합니다.") |
| 63 | + @GetMapping("title/{title}/uuid") |
| 64 | + public ApiResponse<SuccessBody<Object>> getUuidByTitle(@PathVariable String title) { |
| 65 | + Object response = documentService.getUuidByTitle(title); |
| 66 | + return ApiResponseGenerator.success(response); |
| 67 | + } |
| 68 | + |
| 69 | + @Operation(summary = "UUID로 위키 글 조회", description = "UUID를 통해 위키 글을 조회합니다.") |
| 70 | + @GetMapping("uuid/{uuidText}") |
| 71 | + public ApiResponse<SuccessBody<Object>> getByUuid(@PathVariable String uuidText) { |
| 72 | + UUID uuid = UUID.fromString(uuidText); |
| 73 | + Object response = documentService.getByUuid(uuid); |
| 74 | + return ApiResponseGenerator.success(response); |
| 75 | + } |
| 76 | + |
| 77 | + @Operation(summary = "문서 로그 목록 조회", description = "문서 UUID로 해당 문서의 로그 목록을 페이지네이션을 통해 조회합니다.") |
| 78 | + @GetMapping("uuid/{uuidText}/log") |
| 79 | + public ApiResponse<SuccessBody<ResponseDto<List<HistoryResponse>>>> getLogs( |
| 80 | + @PathVariable String uuidText, |
| 81 | + @ModelAttribute PageRequestDto pageRequestDto |
| 82 | + ) { |
| 83 | + UUID uuid = UUID.fromString(uuidText); |
| 84 | + Page<HistoryResponse> pageResponses = historyService.findAllByDocumentUuid(uuid, pageRequestDto); |
| 85 | + return ApiResponseGenerator.success(convertToResponse(pageResponses)); |
| 86 | + } |
| 87 | + |
| 88 | + @Operation(summary = "로그 상세 조회", description = "로그 ID로 로그 상세 정보를 조회합니다.") |
| 89 | + @GetMapping("/log/{logId}") |
| 90 | + public ApiResponse<SuccessBody<HistoryDetailResponse>> getDocumentLogs(@PathVariable Long logId) { |
| 91 | + HistoryDetailResponse logDetail = historyService.getLogDetail(logId); |
| 92 | + return ApiResponseGenerator.success(logDetail); |
| 93 | + } |
| 94 | + |
| 95 | + @Operation(summary = "위키 글 수정", description = "위키 글을 수정합니다.") |
| 96 | + @PutMapping |
| 97 | + public ApiResponse<SuccessBody<DocumentResponse>> put( |
| 98 | + @RequestBody DocumentUpdateRequest documentUpdateRequest |
| 99 | + ) { |
| 100 | + DocumentResponse response = documentService.put(documentUpdateRequest.uuid(), documentUpdateRequest); |
| 101 | + return ApiResponseGenerator.success(response); |
| 102 | + } |
| 103 | + |
| 104 | + @Operation(summary = "키워드로 위키 글 검색", description = "키워드로 위키 글을 검색합니다.") |
| 105 | + @GetMapping("/search") |
| 106 | + public ApiResponse<SuccessBody<List<DocumentSearchResponse>>> search(@RequestParam String keyWord) { |
| 107 | + return ApiResponseGenerator.success(documentSearchService.search(keyWord)); |
| 108 | + } |
| 109 | + |
| 110 | + @Operation(summary = "누적 조회수 수신 API", description = "프론트에서 누적된 조회수를 전달받아 DB에 반영합니다.") |
| 111 | + @PostMapping("/views/flush") |
| 112 | + public ApiResponse<SuccessBody<String>> flushViews( |
| 113 | + @RequestBody ViewFlushRequest request |
| 114 | + ) { |
| 115 | + documentService.flushViews(request.views()); |
| 116 | + return ApiResponseGenerator.success("조회수 누적 완료"); |
| 117 | + } |
| 118 | + |
| 119 | + @Operation(summary = "특정 문서에 대한 조직 문서 조회 API", description = "특정 문서에 대한 조직 문서들을 조회합니다.") |
| 120 | + @GetMapping("/{uuidText}/organization-documents") |
| 121 | + public ApiResponse<SuccessBody<List<OrganizationDocumentSearchResponse>>> readOrganizationDocument( |
| 122 | + @PathVariable String uuidText |
| 123 | + ) { |
| 124 | + UUID uuid = UUID.fromString(uuidText); |
| 125 | + return ApiResponseGenerator.success(documentServiceJava.searchOrganizationDocument(uuid)); |
| 126 | + } |
| 127 | + |
| 128 | + private <T> ResponseDto<List<T>> convertToResponse(Page<T> pageResponses) { |
| 129 | + return ResponseDto.of( |
| 130 | + pageResponses.getNumber(), |
| 131 | + pageResponses.getTotalPages(), |
| 132 | + pageResponses.getContent() |
| 133 | + ); |
| 134 | + } |
| 135 | +} |
| 136 | + |
0 commit comments