-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new REST API for getting scan types [#465]
* Removed the old API.
- Loading branch information
Showing
6 changed files
with
214 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
comixed-rest-api/src/main/java/org/comixedproject/controller/comic/ScanTypeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ed-rest-api/src/test/java/org/comixedproject/controller/comic/ScanTypeControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
comixed-services/src/main/java/org/comixedproject/service/comic/ScanTypeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
comixed-services/src/test/java/org/comixedproject/service/comic/ScanTypeServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |