Skip to content

Commit

Permalink
Added a new REST API for getting scan types [#465]
Browse files Browse the repository at this point in the history
 * Removed the old API.
  • Loading branch information
mcpierce committed Oct 12, 2020
1 parent 9734121 commit 3164241
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
package org.comixedproject.repositories.comic;

import org.comixedproject.model.comic.ScanType;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

/**
* <code>ScanTypeRepository</code> provides methods for working with persisted instances of {@link
* ScanType}.
*
* @author Darryl L. Pierce
*/
@Repository
public interface ScanTypeRepository extends CrudRepository<ScanType, Long> {}
public interface ScanTypeRepository extends JpaRepository<ScanType, Long> {}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public class ComicController {
@Autowired private PageCacheService pageCacheService;
@Autowired private FileService fileService;
@Autowired private FileTypeIdentifier fileTypeIdentifier;
@Autowired private ScanTypeRepository scanTypeRepository;
@Autowired private ComicFormatRepository comicFormatRepository;
@Autowired private ComicDataAdaptor comicDataAdaptor;
@Autowired private TaskManager taskManager;
@Autowired private ScanTypeRepository scanTypeRepository;
@Autowired private ObjectFactory<DeleteComicsWorkerTask> deleteComicsWorkerTaskFactory;
@Autowired private ObjectFactory<UndeleteComicsWorkerTask> undeleteComicsWorkerTaskObjectFactory;
@Autowired private ObjectFactory<RescanComicsWorkerTask> rescanComicsWorkerTaskObjectFactory;
Expand Down Expand Up @@ -243,12 +243,6 @@ public GetLibraryUpdatesResponse getComicsUpdatedSince(
return new GetLibraryUpdatesResponse(comics, lastReadDates, rescanCount, processCount);
}

@GetMapping(value = "/scan_types")
public Iterable<ScanType> getScanTypes() {
log.debug("Fetching all scan types");
return this.scanTypeRepository.findAll();
}

/**
* Starts the process of rescanning all comics in the library.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* ComiXed - A digital comic book library management application.
* Copyright (C) 2020, The ComiXed Project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixedproject.controller.comic;

import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.comixedproject.auditlog.AuditableEndpoint;
import org.comixedproject.model.comic.ScanType;
import org.comixedproject.model.net.ApiResponse;
import org.comixedproject.service.comic.ScanTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* <code>ScanTypeController</code> provides APIs for working with {@link
* org.comixedproject.model.comic.ScanType}s.
*
* @author Darryl L. Pierce
*/
@RestController
@Log4j2
public class ScanTypeController {
@Autowired private ScanTypeService scanTypeService;

/**
* Retrieves the list of all scan types.
*
* @return the scan type list
*/
@GetMapping(value = "/api/comics/scantypes", produces = MediaType.APPLICATION_JSON_VALUE)
@AuditableEndpoint
public ApiResponse<List<ScanType>> getScanTypes() {
log.info("Getting all scan types");
return new ApiResponse<>(this.scanTypeService.getAll());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* ComiXed - A digital comic book library management application.
* Copyright (C) 2020, The ComiXed Project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixedproject.controller.comic;

import static junit.framework.TestCase.*;

import java.util.List;
import org.comixedproject.model.comic.ScanType;
import org.comixedproject.model.net.ApiResponse;
import org.comixedproject.service.comic.ScanTypeService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class ScanTypeControllerTest {
@InjectMocks private ScanTypeController controller;
@Mock private ScanTypeService scanTypeService;
@Mock private List<ScanType> scanTypeList;

@Test
public void testGetScanTypes() {
Mockito.when(scanTypeService.getAll()).thenReturn(scanTypeList);

final ApiResponse<List<ScanType>> result = controller.getScanTypes();

assertNotNull(result);
assertTrue(result.isSuccess());
assertSame(scanTypeList, result.getResult());

Mockito.verify(scanTypeService, Mockito.times(1)).getAll();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* ComiXed - A digital comic book library management application.
* Copyright (C) 2020, The ComiXed Project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixedproject.service.comic;

import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.comixedproject.model.comic.ScanType;
import org.comixedproject.repositories.comic.ScanTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* <code>ScanTypeService</code> provides business logic methods for working with instances of {@link
* ScanType}.
*
* @author Darryl L. Pierce
*/
@Service
@Log4j2
public class ScanTypeService {
@Autowired private ScanTypeRepository scanTypeRepository;

/**
* Returns the list of all defined {@link ScanType}s.
*
* @return the list
*/
public List<ScanType> getAll() {
log.debug("Getting all scan types");
return this.scanTypeRepository.findAll();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* ComiXed - A digital comic book library management application.
* Copyright (C) 2020, The ComiXed Project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

package org.comixedproject.service.comic;

import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertSame;

import java.util.List;
import org.comixedproject.model.comic.ScanType;
import org.comixedproject.repositories.comic.ScanTypeRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class ScanTypeServiceTest {
@InjectMocks private ScanTypeService service;
@Mock private ScanTypeRepository scanTypeRepository;
@Mock private List<ScanType> scanTypeList;

@Test
public void testGetAll() {
Mockito.when(scanTypeRepository.findAll()).thenReturn(scanTypeList);

final List<ScanType> result = service.getAll();

assertNotNull(result);
assertSame(scanTypeList, result);

Mockito.verify(scanTypeRepository, Mockito.times(1)).findAll();
}
}

0 comments on commit 3164241

Please sign in to comment.