backend/src/main/java/com/magamochi/content/controller/MangaChapterController.java

85 lines
3.2 KiB
Java

package com.magamochi.content.controller;
import com.magamochi.content.service.MangaChapterService;
import com.magamochi.model.dto.DefaultResponseDTO;
import com.magamochi.content.model.dto.MangaChapterImagesDTO;
import com.magamochi.model.enumeration.ArchiveFileType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import java.io.IOException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/mangas/chapters")
@RequiredArgsConstructor
public class MangaChapterController {
private final MangaChapterService mangaChapterService;
@Operation(
summary = "Fetch chapter",
description = "Fetch the chapter from the provider",
tags = {"Manga Chapter"},
operationId = "fetchChapter")
@PostMapping(value = "/{chapterId}/fetch")
public DefaultResponseDTO<Void> fetchChapter(@PathVariable Long chapterId) {
mangaChapterService.fetchChapter(chapterId);
return DefaultResponseDTO.ok().build();
}
@Operation(
summary = "Get the images for a specific manga/provider combination",
description =
"Retrieve a list of manga chapter images for a specific manga/provider combination.",
tags = {"Manga Chapter"},
operationId = "getMangaChapterImages")
@GetMapping("/{chapterId}/images")
public DefaultResponseDTO<MangaChapterImagesDTO> getMangaChapterImages(
@PathVariable Long chapterId) {
return DefaultResponseDTO.ok(mangaChapterService.getMangaChapterImages(chapterId));
}
@Operation(
summary = "Mark a chapter as read",
description = "Mark a chapter as read by its ID.",
tags = {"Manga Chapter"},
operationId = "markAsRead")
@PostMapping("/{chapterId}/mark-as-read")
public DefaultResponseDTO<Void> markAsRead(@PathVariable Long chapterId) {
mangaChapterService.markAsRead(chapterId);
return DefaultResponseDTO.ok().build();
}
@Operation(
summary = "Download chapter archive",
description = "Download a chapter as a compressed file by its ID.",
tags = {"Manga Chapter"},
operationId = "downloadChapterArchive")
@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "Successful download",
content =
@Content(
mediaType = "application/octet-stream",
schema = @Schema(type = "string", format = "binary"))),
})
@PostMapping(value = "/{chapterId}/download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> downloadChapterArchive(
@PathVariable Long chapterId, @RequestParam ArchiveFileType archiveFileType)
throws IOException {
var response = mangaChapterService.downloadChapter(chapterId, archiveFileType);
return ResponseEntity.ok()
.header("Content-Disposition", "attachment; filename=\"" + response.filename() + "\"")
.body(response.content());
}
}