Skip to content
Open
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
Expand Up @@ -71,9 +71,9 @@ class DocumentController(
return ApiResponseGenerator.success(response)
}

@Operation(summary = "문서 로그 목록 조회", description = "문서 UUID로 해당 문서의 로그 목록을 페이지네이션을 통해 조회합니다.")
@GetMapping("uuid/{uuidText}/log")
fun getLogs(
@Operation(summary = "문서 히스토리 목록 조회", description = "문서 UUID로 해당 문서의 히스토리 목록을 페이지네이션을 통해 조회합니다.")
@GetMapping("uuid/{uuidText}/history")
fun getHistories(
@PathVariable uuidText: String,
@ModelAttribute pageRequestDto: PageRequestDto
): ApiResponse<SuccessBody<ResponseDto<List<HistoryResponse>>>> {
Expand All @@ -82,11 +82,11 @@ class DocumentController(
return ApiResponseGenerator.success(convertToResponse(pageResponses))
}

@Operation(summary = "로그 상세 조회", description = "로그 ID로 로그 상세 정보를 조회합니다.")
@GetMapping("/log/{logId}")
fun getDocumentLogs(@PathVariable logId: Long): ApiResponse<SuccessBody<HistoryDetailResponse>> {
val logDetail = historyService.getLogDetail(logId)
return ApiResponseGenerator.success(logDetail)
@Operation(summary = "히스토리 상세 조회", description = "히스토리 ID로 히스토리 상세 정보를 조회합니다.")
@GetMapping("/history/{historyId}")
fun getDocumentHistory(@PathVariable historyId: Long): ApiResponse<SuccessBody<HistoryDetailResponse>> {
val historyDetail = historyService.getHistoryDetail(historyId)
return ApiResponseGenerator.success(historyDetail)
}

@Operation(summary = "위키 글 수정", description = "위키 글을 수정합니다.")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/wooteco/wiki/history/domain/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

@Getter
@Entity
@Table(name = "log")
@Table(name = "history")
public class History {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "log_id")
@Column(name = "history_id")
private Long id;

private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import java.time.LocalDateTime;

public record HistoryDetailResponse(Long logId, String title, String contents, String writer,
public record HistoryDetailResponse(Long historyId, String title, String contents, String writer,
LocalDateTime generateTime) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public void save(Document document) {
}

@Transactional(readOnly = true)
public HistoryDetailResponse getLogDetail(Long logId) {
History history = historyRepository.findById(logId)
public HistoryDetailResponse getHistoryDetail(Long historyId) {
History history = historyRepository.findById(historyId)
.orElseThrow(() -> new WikiException(DOCUMENT_NOT_FOUND));
return new HistoryDetailResponse(logId, history.getTitle(), history.getContents(), history.getWriter(),
return new HistoryDetailResponse(historyId, history.getTitle(), history.getContents(), history.getWriter(),
history.getGenerateTime());
}

Expand All @@ -52,14 +52,14 @@ public Page<HistoryResponse> findAllByDocumentUuid(UUID documentUuid, PageReques
.orElseThrow(() -> new WikiException(DOCUMENT_NOT_FOUND));

Pageable pageable = pageRequestDto.toPageable();
Page<History> logs = historyRepository.findAllByDocumentId(documentId, pageable);
List<History> content = logs.getContent();
Page<History> histories = historyRepository.findAllByDocumentId(documentId, pageable);
List<History> content = histories.getContent();

List<HistoryResponse> responses = content.stream()
.map(HistoryResponse::of)
.collect(Collectors.toList());

return new PageImpl<>(responses, pageable, logs.getTotalElements());
return new PageImpl<>(responses, pageable, histories.getTotalElements());
}

@Transactional(readOnly = true)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ VALUES ('titleA', '내용A', '작성자1', 100, '2024-01-01T10:00:00', 'c036a5d8
('titleD1', '내용D1', '작성자11', 400, '2024-01-04T10:00:00', 'e64ae9dc-70d2-4ef7-a431-6ef5f81b2cf0'),
('titleE1', '내용E1', '작성자21', 500, '2024-01-05T10:00:00', 'a3eb4453-e317-4411-932f-8d3b3e3b5b74');

INSERT INTO log (title, contents, writer, document_bytes, generate_time, document_id, version)
INSERT INTO history (title, contents, writer, document_bytes, generate_time, document_id, version)
VALUES ('titleA', '내용Abefore', '작성자1before', 1000, '2023-01-01T10:00:00', 1, 1),
('titleA', '내용A', '작성자1', 100, '2024-01-01T10:00:00', 1, 2),
('titleB', '내용B', '작성자2', 200, '2024-01-02T10:00:00', 2, 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class HistoryServiceTest {
private HistoryRepository historyRepository;

@Nested
@DisplayName("documentUuid로 요청 시 로그 리스트 반환하는 기능")
@DisplayName("documentUuid로 요청 시 히스토리 리스트 반환하는 기능")
class findAllByCrewDocumentUuid {

private PageRequestDto pageRequestDto = new PageRequestDto();
Expand All @@ -59,7 +59,7 @@ void setUp() {
HistoryFixture.create("t1", "c2", "w2", 20L, LocalDateTime.now(), savedCrewDocument, 2L));
}

@DisplayName("documentUuid에 해당하는 로그들이 반환된다")
@DisplayName("documentUuid에 해당하는 히스토리들이 반환된다")
@Test
void findAllByDocumentUuid_success_bySomeData() {
// when
Expand Down Expand Up @@ -100,7 +100,7 @@ void findAllByDocumentUuid_throwsException_byNonExistsDocumentUuid() {
assertThat(ex.getErrorCode()).isEqualTo(ErrorCode.DOCUMENT_NOT_FOUND);
}

@DisplayName("로그 저장 시 최신 version을 제공한다.")
@DisplayName("히스토리 저장 시 최신 version을 제공한다.")
@Test
void save_versionIsNumberedCorrectly() {
// when
Expand All @@ -110,10 +110,10 @@ void save_versionIsNumberedCorrectly() {
historyService.save(updatedDocument);

// then
Page<HistoryResponse> secondLogs = historyService.findAllByDocumentUuid(savedCrewDocument.getUuid(), pageRequestDto);
assertThat(secondLogs.getContent()).hasSize(3);
assertThat(secondLogs.getContent().get(0).version()).isEqualTo(1L);
assertThat(secondLogs.getContent().get(2).version()).isEqualTo(3L);
Page<HistoryResponse> secondHistories = historyService.findAllByDocumentUuid(savedCrewDocument.getUuid(), pageRequestDto);
assertThat(secondHistories.getContent()).hasSize(3);
assertThat(secondHistories.getContent().get(0).version()).isEqualTo(1L);
assertThat(secondHistories.getContent().get(2).version()).isEqualTo(3L);
}
}
}
Loading