-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from aosn/develop
Ready for v0.3 release
- Loading branch information
Showing
56 changed files
with
2,678 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
applications: | ||
- name: aosn-mosaic | ||
memory: 256M | ||
memory: 384M | ||
instances: 1 | ||
path: build/libs/mosaic.war | ||
env: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2017 Alice on Sunday Nights Workshop Participants. All rights reserved. | ||
*/ | ||
package io.github.aosn.mosaic.config; | ||
|
||
import io.github.aosn.mosaic.MosaicApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.service.Contact; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
/** | ||
* Enables Swagger API documentation. | ||
* | ||
* @author mikan | ||
* @since 0.3 | ||
*/ | ||
@Configuration | ||
@EnableSwagger2 | ||
public class DocConfig { | ||
|
||
@Bean | ||
public Docket document() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.select() | ||
.apis(RequestHandlerSelectors.basePackage("io.github.aosn.mosaic.controller")) | ||
.paths(PathSelectors.any()) | ||
.build() | ||
.apiInfo(new ApiInfo("Mosaic Web API", "Web API documentation for Mosaic", | ||
MosaicApplication.MOSAIC_VERSION, null, | ||
new Contact("Alice on Sunday Nights Workshop", "https://aosn.github.io/", ""), | ||
null, null)); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/io/github/aosn/mosaic/config/RestTemplateConfig.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
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
41 changes: 41 additions & 0 deletions
41
src/main/java/io/github/aosn/mosaic/controller/BookController.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,41 @@ | ||
/* | ||
* Copyright (C) 2017 Alice on Sunday Nights Workshop Participants. All rights reserved. | ||
*/ | ||
package io.github.aosn.mosaic.controller; | ||
|
||
import io.github.aosn.mosaic.domain.model.stock.Stock; | ||
import io.github.aosn.mosaic.domain.service.stock.StockService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* @author mikan | ||
* @since 0.3 | ||
*/ | ||
@RestController | ||
@Slf4j | ||
public class BookController { | ||
|
||
private final StockService stockService; | ||
|
||
@Autowired | ||
public BookController(StockService stockService) { | ||
this.stockService = stockService; | ||
} | ||
|
||
@PostMapping(value = "/book") | ||
@ResponseBody | ||
public void addBook(Stock stock, HttpServletResponse response) { | ||
try { | ||
stockService.add(stock); | ||
response.setStatus(HttpServletResponse.SC_CREATED); | ||
} catch (RuntimeException e) { | ||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/io/github/aosn/mosaic/controller/CatalogController.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,53 @@ | ||
/* | ||
* Copyright (C) 2017 Alice on Sunday Nights Workshop Participants. All rights reserved. | ||
*/ | ||
package io.github.aosn.mosaic.controller; | ||
|
||
import io.github.aosn.mosaic.domain.model.catalog.ReleasedBook; | ||
import io.github.aosn.mosaic.domain.model.stock.Stock; | ||
import io.github.aosn.mosaic.domain.service.catalog.CatalogService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* @author mikan | ||
* @since 0.3 | ||
*/ | ||
@RestController | ||
@Slf4j | ||
public class CatalogController { | ||
|
||
public static final String CATALOG_ENDPOINT = "/catalog"; | ||
private final CatalogService catalogService; | ||
|
||
@Autowired | ||
public CatalogController(CatalogService catalogService) { | ||
this.catalogService = catalogService; | ||
} | ||
|
||
@GetMapping(value = CATALOG_ENDPOINT) | ||
@ResponseBody | ||
public List<ReleasedBook> findBooks(@RequestParam("q") String keyword, HttpServletResponse response) { | ||
try { | ||
String isbn = Stock.normalizeIsbn(keyword); | ||
return catalogService.searchByIsbn(isbn); | ||
} catch (IllegalArgumentException e) { | ||
// Not a ISBN, search by name | ||
return catalogService.searchByKeyword(keyword); | ||
} catch (NullPointerException e) { | ||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST); | ||
} catch (RuntimeException e) { | ||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
} | ||
response.setStatus(HttpServletResponse.SC_NOT_FOUND); | ||
return Collections.emptyList(); | ||
} | ||
} |
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
Oops, something went wrong.