Skip to content

Commit

Permalink
Merge pull request #3 from gbzarelli/refactor
Browse files Browse the repository at this point in the history
refactor(Interfaces): Interfaces
  • Loading branch information
gbzarelli authored Dec 24, 2019
2 parents 9af5cf5 + 7bda559 commit 3f9d356
Show file tree
Hide file tree
Showing 56 changed files with 758 additions and 678 deletions.
11 changes: 0 additions & 11 deletions src/main/java/br/com/beblue/musicstore/ServletInitializer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,47 +1,16 @@
package br.com.beblue.musicstore.controller;

import br.com.beblue.musicstore.dto.DiscDTO;
import br.com.beblue.musicstore.controller.dto.DiscDTO;
import br.com.beblue.musicstore.exception.NoValuePresentException;
import br.com.beblue.musicstore.service.DiscService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static br.com.beblue.musicstore.controller.DiscController.ROOT_PATH;
public interface DiscController {

@RestController
@RequestMapping(ROOT_PATH)
public class DiscController {
Page<DiscDTO> listDiscsByGenre(String genre, Pageable pageable);

static final String ROOT_PATH = "/disc";
static final String PATH_BY_GENRE = "/genre/{genre}";
static final String PATH_BY_ID = "/{id}";
Page<DiscDTO> listDiscs(Pageable pageable);

private final DiscService discService;

@Autowired
public DiscController(DiscService discService) {
this.discService = discService;
}

@GetMapping(value = PATH_BY_GENRE, produces = MediaType.APPLICATION_JSON_VALUE)
public Page<DiscDTO> list(@PathVariable String genre, Pageable pageable) {
return discService.getDiscs(genre, pageable);
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Page<DiscDTO> list(Pageable pageable) {
return discService.getDiscs(pageable);
}

@GetMapping(value = PATH_BY_ID, produces = MediaType.APPLICATION_JSON_VALUE)
public DiscDTO get(@PathVariable int id) throws NoValuePresentException {
return discService.getDisc(id);
}
DiscDTO getDiscByID(Integer id) throws NoValuePresentException;

}
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
package br.com.beblue.musicstore.controller;

import br.com.beblue.musicstore.dto.GenreDTO;
import br.com.beblue.musicstore.service.GenreService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import br.com.beblue.musicstore.controller.dto.GenreDTO;

import java.util.List;

import static br.com.beblue.musicstore.controller.GenreController.ROOT_PATH;

@RestController
@RequestMapping(ROOT_PATH)
public class GenreController {
static final String ROOT_PATH = "/genre";

private final GenreService genreService;

@Autowired
public GenreController(GenreService genreService) {
this.genreService = genreService;
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List<GenreDTO> getAll() {
return genreService.getAllGenres();
}

public interface GenreController {
List<GenreDTO> getAllGenres();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,56 +1,19 @@
package br.com.beblue.musicstore.controller;

import br.com.beblue.musicstore.dto.SaleRequestDTO;
import br.com.beblue.musicstore.dto.SaleResponseDTO;
import br.com.beblue.musicstore.controller.dto.SaleRequestDTO;
import br.com.beblue.musicstore.controller.dto.SaleResponseDTO;
import br.com.beblue.musicstore.exception.IllegalDateException;
import br.com.beblue.musicstore.exception.NoValuePresentException;
import br.com.beblue.musicstore.service.SaleSearchService;
import br.com.beblue.musicstore.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

import static br.com.beblue.musicstore.controller.SaleController.ROOT_PATH;
public interface SaleController {

@RestController
@RequestMapping(ROOT_PATH)
public class SaleController {
static final String ROOT_PATH = "/sale";
static final String PATH_BY_ORDER_NUMBER = "/{orderNumber}";
static final String PATH_BY_DATE = "/start_date/{startDate}/end_date/{endDate}";
SaleResponseDTO registerOrder(SaleRequestDTO request) throws NoValuePresentException;

private final SaleService saleService;
private final SaleSearchService saleSearchService;
SaleResponseDTO getOrderByOrderNumber(String orderNumber) throws NoValuePresentException;

@Autowired
public SaleController(SaleService saleService, SaleSearchService saleSearchService) {
this.saleService = saleService;
this.saleSearchService = saleSearchService;
}

@PostMapping()
public SaleResponseDTO postOrder(@RequestBody SaleRequestDTO request) throws NoValuePresentException {
return saleService.registerOrder(request);
}

@GetMapping(value = PATH_BY_ORDER_NUMBER)
public SaleResponseDTO getOrder(@PathVariable String orderNumber) throws NoValuePresentException {
return saleSearchService.getOrderByNumber(orderNumber);
}

@GetMapping(value = PATH_BY_DATE)
public Page<SaleResponseDTO> getOrders(
@PathVariable
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
LocalDate startDate,
@PathVariable
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
LocalDate endDate,
Pageable pageable) throws IllegalDateException {
return saleSearchService.getOrdersByDate(startDate, endDate, pageable);
}
Page<SaleResponseDTO> getOrdersByDateFilter(LocalDate startDate, LocalDate endDate, Pageable pageable) throws IllegalDateException;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.beblue.musicstore.dto;
package br.com.beblue.musicstore.controller.dto;

public class DiscDTO {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.beblue.musicstore.dto;
package br.com.beblue.musicstore.controller.dto;

public class GenreDTO {
private int id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.beblue.musicstore.dto;
package br.com.beblue.musicstore.controller.dto;

import java.util.ArrayList;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.beblue.musicstore.dto;
package br.com.beblue.musicstore.controller.dto;

import javax.validation.constraints.Min;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.beblue.musicstore.dto;
package br.com.beblue.musicstore.controller.dto;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package br.com.beblue.musicstore.controller.rest;

import br.com.beblue.musicstore.controller.DiscController;
import br.com.beblue.musicstore.controller.dto.DiscDTO;
import br.com.beblue.musicstore.exception.NoValuePresentException;
import br.com.beblue.musicstore.service.DiscService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(DiscRestController.ROOT_PATH)
class DiscRestController implements DiscController {

static final String ROOT_PATH = "/disc";
static final String PATH_BY_GENRE = "/genre/{genre}";
static final String PATH_BY_ID = "/{id}";

private final DiscService discService;

@Autowired
DiscRestController(final DiscService discService) {
this.discService = discService;
}

@GetMapping(value = PATH_BY_GENRE, produces = MediaType.APPLICATION_JSON_VALUE)
public Page<DiscDTO> listDiscsByGenre(@PathVariable String genre, Pageable pageable) {
return discService.getDiscsByGenre(genre, pageable);
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Page<DiscDTO> listDiscs(Pageable pageable) {
return discService.getDiscs(pageable);
}

@GetMapping(value = PATH_BY_ID, produces = MediaType.APPLICATION_JSON_VALUE)
public DiscDTO getDiscByID(@PathVariable Integer id) throws NoValuePresentException {
return discService.getDiscByID(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package br.com.beblue.musicstore.controller.rest;

import br.com.beblue.musicstore.controller.GenreController;
import br.com.beblue.musicstore.controller.dto.GenreDTO;
import br.com.beblue.musicstore.service.GenreService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(GenreRestController.ROOT_PATH)
class GenreRestController implements GenreController {

static final String ROOT_PATH = "/genre";

private final GenreService genreService;

@Autowired
GenreRestController(final GenreService genreService) {
this.genreService = genreService;
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List<GenreDTO> getAllGenres() {
return genreService.getAllGenres();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package br.com.beblue.musicstore.controller.rest;

import br.com.beblue.musicstore.controller.SaleController;
import br.com.beblue.musicstore.controller.dto.SaleRequestDTO;
import br.com.beblue.musicstore.controller.dto.SaleResponseDTO;
import br.com.beblue.musicstore.exception.IllegalDateException;
import br.com.beblue.musicstore.exception.NoValuePresentException;
import br.com.beblue.musicstore.service.SaleSearchService;
import br.com.beblue.musicstore.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping(SaleRestController.ROOT_PATH)
class SaleRestController implements SaleController {

static final String ROOT_PATH = "/sale";
static final String PATH_BY_ORDER_NUMBER = "/{orderNumber}";
static final String PATH_BY_DATE = "/start_date/{startDate}/end_date/{endDate}";

private final SaleService saleService;
private final SaleSearchService saleSearchService;

@Autowired
SaleRestController(final SaleService saleService, final SaleSearchService saleSearchService) {
this.saleService = saleService;
this.saleSearchService = saleSearchService;
}

@PostMapping()
public SaleResponseDTO registerOrder(@RequestBody SaleRequestDTO request) throws NoValuePresentException {
return saleService.registerOrder(request);
}

@GetMapping(value = PATH_BY_ORDER_NUMBER)
public SaleResponseDTO getOrderByOrderNumber(@PathVariable String orderNumber) throws NoValuePresentException {
return saleSearchService.getOrderByNumber(orderNumber);
}

@GetMapping(value = PATH_BY_DATE)
public Page<SaleResponseDTO> getOrdersByDateFilter(
@PathVariable
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
LocalDate startDate,
@PathVariable
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
LocalDate endDate,
Pageable pageable) throws IllegalDateException {
return saleSearchService.getOrdersByDate(startDate, endDate, pageable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package br.com.beblue.musicstore.events;

import org.springframework.amqp.AmqpException;

public interface SaleNotifiable {
void notifyNewOrder(String order) throws AmqpException;
}
Loading

0 comments on commit 3f9d356

Please sign in to comment.