Skip to content

Commit 47ee6ee

Browse files
authored
refactor: 자바 마이그레이션 (#132)
* refactor: 코틀린 파일 삭제 및 자바 파일 추가 * fix: 테스트 오류 수정
1 parent 3be3d90 commit 47ee6ee

File tree

15 files changed

+218
-202
lines changed

15 files changed

+218
-202
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+

src/main/java/com/wooteco/wiki/document/controller/DocumentController.kt

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.wooteco.wiki.document.domain.dto;
2+
3+
import com.wooteco.wiki.organizationdocument.dto.response.OrganizationDocumentResponse;
4+
import java.time.LocalDateTime;
5+
import java.util.List;
6+
import java.util.UUID;
7+
8+
public record DocumentResponse(
9+
Long documentId,
10+
UUID documentUUID,
11+
String title,
12+
String contents,
13+
String writer,
14+
LocalDateTime generateTime,
15+
Integer viewCount,
16+
Long latestVersion,
17+
List<OrganizationDocumentResponse> organizationDocumentResponses
18+
) {
19+
}
20+

src/main/java/com/wooteco/wiki/document/domain/dto/DocumentResponse.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.wooteco.wiki.document.domain.dto;
2+
3+
import com.wooteco.wiki.document.domain.DocumentType;
4+
import java.util.UUID;
5+
6+
public record DocumentSearchResponse(
7+
String title,
8+
UUID uuid,
9+
DocumentType documentType
10+
) {
11+
}
12+

src/main/java/com/wooteco/wiki/document/domain/dto/DocumentSearchResponse.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.wooteco.wiki.document.domain.dto;
2+
3+
import java.util.UUID;
4+
5+
public record DocumentUpdateRequest(
6+
String title,
7+
String contents,
8+
String writer,
9+
Long documentBytes,
10+
UUID uuid
11+
) {
12+
}
13+

src/main/java/com/wooteco/wiki/document/domain/dto/DocumentUpdateRequest.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.wooteco.wiki.document.domain.dto;
2+
3+
import java.util.Map;
4+
import java.util.UUID;
5+
6+
public record ViewFlushRequest(
7+
Map<UUID, Integer> views
8+
) {
9+
}
10+

src/main/java/com/wooteco/wiki/document/domain/dto/ViewFlushRequest.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)