Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9b60561
completing customer assignment
springframeworkguru Apr 21, 2019
de27f8b
adding post example
springframeworkguru Apr 21, 2019
802ddcf
adding put example
springframeworkguru Apr 21, 2019
dce38e6
adding delete example
springframeworkguru Apr 23, 2019
36804b7
completing coding assignment
springframeworkguru Apr 23, 2019
8a04983
adding v2 of beer controller
springframeworkguru Apr 23, 2019
ab7aaac
adding request mapping example and test
springframeworkguru May 12, 2019
b3f5b2e
Merge branch 'request-mapping' into http-delete
springframeworkguru May 12, 2019
ab7eac3
Merge branch 'http-delete' into http-ops-assn
springframeworkguru May 12, 2019
3957ff7
Merge branch 'http-ops-assn' into beer-api-v2
springframeworkguru May 12, 2019
9304260
adding bean validation
springframeworkguru May 17, 2019
8b7cd5e
exception handler
springframeworkguru May 19, 2019
eb62838
adding customer validation
springframeworkguru May 25, 2019
2e4f48a
adding controller advice
springframeworkguru May 25, 2019
04c4dcc
adding lombok examples
springframeworkguru May 25, 2019
4405d91
adding mapstruct config
springframeworkguru May 25, 2019
5165769
adding mapstruct example
springframeworkguru May 25, 2019
a817257
adding mapstruct customer assignment
springframeworkguru May 25, 2019
9a6e7ea
Update README.md
springframeworkguru Jun 3, 2019
cfbc759
Update README.md
springframeworkguru Jun 3, 2019
4fbad30
Update README.md
springframeworkguru Jun 3, 2019
535be0b
updating for Mapstruct Binding and newer version of Lombok
springframeworkguru Mar 7, 2021
a1a1ec9
Merge branch 'mapstruct-config' into mapstruct-example
springframeworkguru Mar 7, 2021
9db70f7
Merge branch 'mapstruct-example' into assn-use-mapstruct
springframeworkguru Mar 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# SFG Beer Works - Brewery Microservice
# SFG Beer Works - Brewery Microservice

Source code in this repository is to support my on line courses:
* [Spring Boot Microservices with Spring Cloud](https://www.udemy.com/spring-boot-microservices-with-spring-cloud-beginner-to-guru/?couponCode=GIT_HUB2)
37 changes: 36 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -17,6 +17,8 @@

<properties>
<java.version>11</java.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<org.lombok.version>1.18.18</org.lombok.version>
</properties>

<dependencies>
Expand All @@ -37,8 +39,14 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.lombok.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -52,6 +60,33 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.lombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>-Amapstruct.defaultComponentModel=spring</compilerArg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/guru/springframework/msscbrewery/domain/Beer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package guru.springframework.msscbrewery.domain;

import guru.springframework.msscbrewery.web.model.v2.BeerStyleEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

/**
* Created by jt on 2019-05-25.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Beer {
private UUID id;
private String beerName;
private BeerStyleEnum beerStyle;
private Long upc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package guru.springframework.msscbrewery.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

/**
* Created by jt on 2019-05-25.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Customer {
private UUID id;
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
*/
public interface BeerService {
BeerDto getBeerById(UUID beerId);

BeerDto saveNewBeer(BeerDto beerDto);

void updateBeer(UUID beerId, BeerDto beerDto);

void deleteById(UUID beerId);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package guru.springframework.msscbrewery.services;

import guru.springframework.msscbrewery.web.model.BeerDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
* Created by jt on 2019-04-20.
*/
@Slf4j
@Service
public class BeerServiceImpl implements BeerService {
@Override
Expand All @@ -17,4 +19,21 @@ public BeerDto getBeerById(UUID beerId) {
.beerStyle("Pale Ale")
.build();
}

@Override
public BeerDto saveNewBeer(BeerDto beerDto) {
return BeerDto.builder()
.id(UUID.randomUUID())
.build();
}

@Override
public void updateBeer(UUID beerId, BeerDto beerDto) {
//todo impl - would add a real impl to update beer
}

@Override
public void deleteById(UUID beerId) {
log.debug("Deleting a beer...");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package guru.springframework.msscbrewery.services;

import guru.springframework.msscbrewery.web.model.CustomerDto;

import java.util.UUID;

/**
* Created by jt on 2019-04-21.
*/
public interface CustomerService {
CustomerDto getCustomerById(UUID customerId);

CustomerDto saveNewCustomer(CustomerDto customerDto);

void updateCustomer(UUID customerId, CustomerDto customerDto);

void deleteById(UUID customerId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package guru.springframework.msscbrewery.services;

import guru.springframework.msscbrewery.web.model.CustomerDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
* Created by jt on 2019-04-21.
*/
@Slf4j
@Service
public class CustomerServiceImpl implements CustomerService {
@Override
public CustomerDto getCustomerById(UUID customerId) {
return CustomerDto.builder()
.id(UUID.randomUUID())
.name("Joe Buck")
.build();
}

@Override
public CustomerDto saveNewCustomer(CustomerDto customerDto) {
return CustomerDto.builder()
.id(UUID.randomUUID())
.build();
}

@Override
public void updateCustomer(UUID customerId, CustomerDto customerDto) {
//todo impl
log.debug("Updating....");
}

@Override
public void deleteById(UUID customerId) {
log.debug("Deleting.... ");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package guru.springframework.msscbrewery.services.v2;

import guru.springframework.msscbrewery.web.model.v2.BeerDtoV2;

import java.util.UUID;

/**
* Created by jt on 2019-04-23.
*/
public interface BeerServiceV2 {
BeerDtoV2 getBeerById(UUID beerId);

BeerDtoV2 saveNewBeer(BeerDtoV2 beerDto);

void updateBeer(UUID beerId, BeerDtoV2 beerDto);

void deleteById(UUID beerId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package guru.springframework.msscbrewery.services.v2;

import guru.springframework.msscbrewery.web.model.v2.BeerDtoV2;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
* Created by jt on 2019-04-23.
*/
@Service
public class BeerServiceV2Impl implements BeerServiceV2 {
@Override
public BeerDtoV2 getBeerById(UUID beerId) {
return null;
}

@Override
public BeerDtoV2 saveNewBeer(BeerDtoV2 beerDto) {
return null;
}

@Override
public void updateBeer(UUID beerId, BeerDtoV2 beerDto) {

}

@Override
public void deleteById(UUID beerId) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import guru.springframework.msscbrewery.services.BeerService;
import guru.springframework.msscbrewery.web.model.BeerDto;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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 org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.UUID;

/**
* Created by jt on 2019-04-20.
*/
@Deprecated
@RequestMapping("/api/v1/beer")
@RestController
public class BeerController {
Expand All @@ -30,4 +30,30 @@ public ResponseEntity<BeerDto> getBeer(@PathVariable("beerId") UUID beerId){
return new ResponseEntity<>(beerService.getBeerById(beerId), HttpStatus.OK);
}

@PostMapping // POST - create new beer
public ResponseEntity handlePost(@Valid @RequestBody BeerDto beerDto){

BeerDto savedDto = beerService.saveNewBeer(beerDto);

HttpHeaders headers = new HttpHeaders();
//todo add hostname to url
headers.add("Location", "/api/v1/beer/" + savedDto.getId().toString());

return new ResponseEntity(headers, HttpStatus.CREATED);
}

@PutMapping({"/{beerId}"})
public ResponseEntity handleUpdate(@PathVariable("beerId") UUID beerId, @Valid @RequestBody BeerDto beerDto){

beerService.updateBeer(beerId, beerDto);

return new ResponseEntity(HttpStatus.NO_CONTENT);
}

@DeleteMapping({"/{beerId}"})
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteBeer(@PathVariable("beerId") UUID beerId){
beerService.deleteById(beerId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package guru.springframework.msscbrewery.web.controller;

import guru.springframework.msscbrewery.services.CustomerService;
import guru.springframework.msscbrewery.web.model.CustomerDto;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

/**
* Created by jt on 2019-04-21.
*/

@RequestMapping("api/v1/customer")
@RestController
public class CustomerController {

private CustomerService customerService;

public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}

@GetMapping("/{customerId}")
public ResponseEntity<CustomerDto> getCustomer(@PathVariable("customerId") UUID customerId){

return new ResponseEntity<>(customerService.getCustomerById(customerId), HttpStatus.OK);
}

@PostMapping
public ResponseEntity handlePost(@RequestBody @Validated CustomerDto customerDto){
CustomerDto savedDto = customerService.saveNewCustomer(customerDto);

HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Location", "/api/v1/customer/" + savedDto.getId().toString());

return new ResponseEntity(httpHeaders, HttpStatus.CREATED);
}

@PutMapping("/{customerId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void handleUpdate(@PathVariable("customerId") UUID customerId, @Validated @RequestBody CustomerDto customerDto){
customerService.updateCustomer(customerId, customerDto);
}

@DeleteMapping("/{customerId}")
public void deleteById(@PathVariable("customerId") UUID customerId){
customerService.deleteById(customerId);
}

}
Loading