Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.wooteco.wiki.document.controller;

import com.wooteco.wiki.document.domain.Document;
import com.wooteco.wiki.document.domain.dto.*;
import com.wooteco.wiki.document.service.DocumentSearchService;
import com.wooteco.wiki.document.service.DocumentService;
import com.wooteco.wiki.document.service.DocumentServiceJava;
import com.wooteco.wiki.global.common.ApiResponse;
import com.wooteco.wiki.global.common.ApiResponse.SuccessBody;
import com.wooteco.wiki.global.common.ApiResponseGenerator;
import com.wooteco.wiki.global.common.PageRequestDto;
import com.wooteco.wiki.global.common.ResponseDto;
import com.wooteco.wiki.history.domain.dto.HistoryDetailResponse;
import com.wooteco.wiki.history.domain.dto.HistoryResponse;
import com.wooteco.wiki.history.service.HistoryService;
import com.wooteco.wiki.organizationdocument.dto.OrganizationDocumentSearchResponse;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/document")
@RequiredArgsConstructor
public class DocumentController {

private final DocumentService documentService;
private final HistoryService historyService;
private final DocumentSearchService documentSearchService;
private final DocumentServiceJava documentServiceJava;

@Operation(summary = "위키 글 작성", description = "위키 글을 작성합니다.")
@PostMapping
public ApiResponse<SuccessBody<DocumentResponse>> post(@RequestBody CrewDocumentCreateRequest crewDocumentCreateRequest) {
DocumentResponse response = documentService.postCrewDocument(crewDocumentCreateRequest);
return ApiResponseGenerator.success(response);
}

@Operation(summary = "랜덤 위키 글 조회", description = "랜덤으로 위키 글을 조회합니다.")
@GetMapping("/random")
public ApiResponse<SuccessBody<DocumentResponse>> getRandom() {
DocumentResponse response = documentService.getRandom();
return ApiResponseGenerator.success(response);
}

@Operation(summary = "위키 글 전체 조회", description = "페이지네이션을 통해 모든 위키 글을 조회합니다.")
@GetMapping("")
public ApiResponse<SuccessBody<ResponseDto<List<Document>>>> findAll(@ModelAttribute PageRequestDto pageRequestDto) {
Page<Document> pageResponses = documentService.findAll(pageRequestDto);
return ApiResponseGenerator.success(convertToResponse(pageResponses));
}

@Operation(summary = "제목으로 위키 글 조회", description = "제목을 통해 위키 글을 조회합니다.")
@GetMapping("title/{title}")
public ApiResponse<SuccessBody<Object>> get(@PathVariable String title) {
Object response = documentService.get(title);
return ApiResponseGenerator.success(response);
}

@Operation(summary = "제목으로 UUID 조회", description = "제목을 통해 위키 글의 UUID를 조회합니다.")
@GetMapping("title/{title}/uuid")
public ApiResponse<SuccessBody<Object>> getUuidByTitle(@PathVariable String title) {
Object response = documentService.getUuidByTitle(title);
return ApiResponseGenerator.success(response);
}

@Operation(summary = "UUID로 위키 글 조회", description = "UUID를 통해 위키 글을 조회합니다.")
@GetMapping("uuid/{uuidText}")
public ApiResponse<SuccessBody<Object>> getByUuid(@PathVariable String uuidText) {
UUID uuid = UUID.fromString(uuidText);
Object response = documentService.getByUuid(uuid);
return ApiResponseGenerator.success(response);
}

@Operation(summary = "문서 로그 목록 조회", description = "문서 UUID로 해당 문서의 로그 목록을 페이지네이션을 통해 조회합니다.")
@GetMapping("uuid/{uuidText}/log")
public ApiResponse<SuccessBody<ResponseDto<List<HistoryResponse>>>> getLogs(
@PathVariable String uuidText,
@ModelAttribute PageRequestDto pageRequestDto
) {
UUID uuid = UUID.fromString(uuidText);
Page<HistoryResponse> pageResponses = historyService.findAllByDocumentUuid(uuid, pageRequestDto);
return ApiResponseGenerator.success(convertToResponse(pageResponses));
}

@Operation(summary = "로그 상세 조회", description = "로그 ID로 로그 상세 정보를 조회합니다.")
@GetMapping("/log/{logId}")
public ApiResponse<SuccessBody<HistoryDetailResponse>> getDocumentLogs(@PathVariable Long logId) {
HistoryDetailResponse logDetail = historyService.getLogDetail(logId);
return ApiResponseGenerator.success(logDetail);
}

@Operation(summary = "위키 글 수정", description = "위키 글을 수정합니다.")
@PutMapping
public ApiResponse<SuccessBody<DocumentResponse>> put(
@RequestBody DocumentUpdateRequest documentUpdateRequest
) {
DocumentResponse response = documentService.put(documentUpdateRequest.uuid(), documentUpdateRequest);
return ApiResponseGenerator.success(response);
}

@Operation(summary = "키워드로 위키 글 검색", description = "키워드로 위키 글을 검색합니다.")
@GetMapping("/search")
public ApiResponse<SuccessBody<List<DocumentSearchResponse>>> search(@RequestParam String keyWord) {
return ApiResponseGenerator.success(documentSearchService.search(keyWord));
}

@Operation(summary = "누적 조회수 수신 API", description = "프론트에서 누적된 조회수를 전달받아 DB에 반영합니다.")
@PostMapping("/views/flush")
public ApiResponse<SuccessBody<String>> flushViews(
@RequestBody ViewFlushRequest request
) {
documentService.flushViews(request.views());
return ApiResponseGenerator.success("조회수 누적 완료");
}

@Operation(summary = "특정 문서에 대한 조직 문서 조회 API", description = "특정 문서에 대한 조직 문서들을 조회합니다.")
@GetMapping("/{uuidText}/organization-documents")
public ApiResponse<SuccessBody<List<OrganizationDocumentSearchResponse>>> readOrganizationDocument(
@PathVariable String uuidText
) {
UUID uuid = UUID.fromString(uuidText);
return ApiResponseGenerator.success(documentServiceJava.searchOrganizationDocument(uuid));
}

private <T> ResponseDto<List<T>> convertToResponse(Page<T> pageResponses) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p2) 나중에 서비스 로직으로 들어가도 되겠네요~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 유틸성이 강해보인다고 생각하는데 어떠신가용 ~?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그르네요
DTO 형태는 서비스 책임이라고 생각해서 한 말이었는데 다시 보니 오해의 소지가 있을 수 있겠군요

convertToResponse는 유틸 클래스로 빼고,
DTO를 반환하는 결정을 서비스에서 끝내는 구조는 어떻게 생각하시나요~?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다~ 현재 PR은 마이그레이션만 진행을 마치고 새로운 이슈로 파는 게 좋아보여서 머지할게요~

return ResponseDto.of(
pageResponses.getNumber(),
pageResponses.getTotalPages(),
pageResponses.getContent()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wooteco.wiki.document.domain.dto;

import com.wooteco.wiki.organizationdocument.dto.response.OrganizationDocumentResponse;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

public record DocumentResponse(
Long documentId,
UUID documentUUID,
String title,
String contents,
String writer,
LocalDateTime generateTime,
Integer viewCount,
Long latestVersion,
List<OrganizationDocumentResponse> organizationDocumentResponses
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wooteco.wiki.document.domain.dto;

import com.wooteco.wiki.document.domain.DocumentType;
import java.util.UUID;

public record DocumentSearchResponse(
String title,
UUID uuid,
DocumentType documentType
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.wooteco.wiki.document.domain.dto;

import java.util.UUID;

public record DocumentUpdateRequest(
String title,
String contents,
String writer,
Long documentBytes,
UUID uuid
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wooteco.wiki.document.domain.dto;

import java.util.Map;
import java.util.UUID;

public record ViewFlushRequest(
Map<UUID, Integer> views
) {
}

This file was deleted.

Loading
Loading