-
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 the comic formats [#465]
* Added a new controller and service. * Made the API auditable. * Removed the old REST API.
- Loading branch information
Showing
6 changed files
with
208 additions
and
8 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
...xed-rest-api/src/main/java/org/comixedproject/controller/comic/ComicFormatController.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.ComicFormat; | ||
import org.comixedproject.model.net.ApiResponse; | ||
import org.comixedproject.service.comic.ComicFormatService; | ||
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>ComicFormatController</code> provides a set of REST APIs for working with the instances of | ||
* {@link ComicFormat}. | ||
* | ||
* @author Darryl L. Pierce | ||
*/ | ||
@RestController | ||
@Log4j2 | ||
public class ComicFormatController { | ||
@Autowired private ComicFormatService comicFormatService; | ||
|
||
/** | ||
* Returns the list of all defined comic formats. | ||
* | ||
* @return the list | ||
*/ | ||
@GetMapping(value = "/api/comics/formats", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@AuditableEndpoint | ||
public ApiResponse<List<ComicFormat>> getAll() { | ||
log.info("Retrieving the list of comic formats"); | ||
return new ApiResponse<>(this.comicFormatService.getAll()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...rest-api/src/test/java/org/comixedproject/controller/comic/ComicFormatControllerTest.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.ComicFormat; | ||
import org.comixedproject.model.net.ApiResponse; | ||
import org.comixedproject.service.comic.ComicFormatService; | ||
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 ComicFormatControllerTest { | ||
@InjectMocks private ComicFormatController controller; | ||
@Mock private ComicFormatService comicFormatService; | ||
@Mock private List<ComicFormat> comicFormatList; | ||
|
||
@Test | ||
public void testGetAll() { | ||
Mockito.when(comicFormatService.getAll()).thenReturn(comicFormatList); | ||
|
||
final ApiResponse<List<ComicFormat>> result = controller.getAll(); | ||
|
||
assertNotNull(result); | ||
assertTrue(result.isSuccess()); | ||
assertSame(comicFormatList, result.getResult()); | ||
|
||
Mockito.verify(comicFormatService, Mockito.times(1)).getAll(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
comixed-services/src/main/java/org/comixedproject/service/comic/ComicFormatService.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,43 @@ | ||
/* | ||
* 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.ComicFormat; | ||
import org.comixedproject.repositories.comic.ComicFormatRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* <code>ComicFormatService</code> provides business logic when working with instances of {@link | ||
* ComicFormat}. | ||
* | ||
* @author Darryl L. Pierce | ||
*/ | ||
@Service | ||
@Log4j2 | ||
public class ComicFormatService { | ||
@Autowired private ComicFormatRepository comicFormatRepository; | ||
|
||
public List<ComicFormat> getAll() { | ||
log.debug("Getting all comic formts"); | ||
return this.comicFormatRepository.findAll(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
comixed-services/src/test/java/org/comixedproject/service/comic/ComicFormatServiceTest.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.ComicFormat; | ||
import org.comixedproject.repositories.comic.ComicFormatRepository; | ||
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 ComicFormatServiceTest { | ||
@InjectMocks private ComicFormatService service; | ||
@Mock private ComicFormatRepository comicFormatRepository; | ||
@Mock private List<ComicFormat> comicFormatList; | ||
|
||
@Test | ||
public void testGetAll() { | ||
Mockito.when(comicFormatRepository.findAll()).thenReturn(comicFormatList); | ||
|
||
final List<ComicFormat> result = service.getAll(); | ||
|
||
assertNotNull(result); | ||
assertSame(comicFormatList, result); | ||
|
||
Mockito.verify(comicFormatRepository, Mockito.times(1)).findAll(); | ||
} | ||
} |