diff --git a/src/main/java/guru/springframework/msscbrewery/services/BeerService.java b/src/main/java/guru/springframework/msscbrewery/services/BeerService.java index c24ff2bf..243e7384 100644 --- a/src/main/java/guru/springframework/msscbrewery/services/BeerService.java +++ b/src/main/java/guru/springframework/msscbrewery/services/BeerService.java @@ -9,4 +9,12 @@ */ public interface BeerService { BeerDto getBeerById(UUID beerId); + + BeerDto saveNewBeer(BeerDto beerDto); + + void updateBeer(UUID beerId, BeerDto beerDto); + + void deleteById(UUID beerId); } +// nuevo +//nuevo2 diff --git a/src/main/java/guru/springframework/msscbrewery/services/BeerServiceImpl.java b/src/main/java/guru/springframework/msscbrewery/services/BeerServiceImpl.java index 1b6505f0..052f95f4 100644 --- a/src/main/java/guru/springframework/msscbrewery/services/BeerServiceImpl.java +++ b/src/main/java/guru/springframework/msscbrewery/services/BeerServiceImpl.java @@ -1,6 +1,7 @@ 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; @@ -9,6 +10,7 @@ * Created by jt on 2019-04-20. */ @Service +@Slf4j public class BeerServiceImpl implements BeerService { @Override public BeerDto getBeerById(UUID beerId) { @@ -17,4 +19,21 @@ public BeerDto getBeerById(UUID beerId) { .beerStyle("Pale Ale") .build(); } + + @Override + public BeerDto saveNewBeer(BeerDto beerDto) { + return null; + } + + @Override + public void updateBeer(UUID beerId, BeerDto beerDto) { +// todo in the future in shaa Allah + } + + @Override + public void deleteById(UUID beerId) { + log.debug("Deleting a file.........."); + + } + //origin brunch borra } diff --git a/src/main/java/guru/springframework/msscbrewery/services/Class.java b/src/main/java/guru/springframework/msscbrewery/services/Class.java new file mode 100644 index 00000000..9f411556 --- /dev/null +++ b/src/main/java/guru/springframework/msscbrewery/services/Class.java @@ -0,0 +1,31 @@ +package guru.springframework.msscbrewery.services; +// File Class.java +public class Class { + private Class(String s) { + + } + + public static Class createClass(String s) { + return new Class(s); + } +} + +// File AnotherClass.java +class AnotherClass { + public void method() { + Class aClass = Class.createClass("string"); + } +} +//// File Class.java +//public class Class { +// public Class(String s) { +// ... +// } +//} +// +//// File AnotherClass.java +//public class AnotherClass { +// public void method() { +// Class aClass = new Class("string"); +// } +//} \ No newline at end of file diff --git a/src/main/java/guru/springframework/msscbrewery/services/CustomerService.java b/src/main/java/guru/springframework/msscbrewery/services/CustomerService.java new file mode 100644 index 00000000..0da71c0a --- /dev/null +++ b/src/main/java/guru/springframework/msscbrewery/services/CustomerService.java @@ -0,0 +1,15 @@ +package guru.springframework.msscbrewery.services; + + +import guru.springframework.msscbrewery.web.model.CustomerDto; + +import java.util.UUID; + +public interface CustomerService { + + + + CustomerDto getCustomerById(UUID customerId); + + +} diff --git a/src/main/java/guru/springframework/msscbrewery/services/CustomerServiceImpl.java b/src/main/java/guru/springframework/msscbrewery/services/CustomerServiceImpl.java new file mode 100644 index 00000000..17e953d9 --- /dev/null +++ b/src/main/java/guru/springframework/msscbrewery/services/CustomerServiceImpl.java @@ -0,0 +1,20 @@ +package guru.springframework.msscbrewery.services; + + +import guru.springframework.msscbrewery.web.model.CustomerDto; +import org.springframework.stereotype.Service; + +import java.util.UUID; +@Service +public class CustomerServiceImpl implements CustomerService{ + + + @Override + public CustomerDto getCustomerById(UUID customerId) { + return CustomerDto.builder().id(UUID.randomUUID()) + .name("Radi") + .build(); + } + + +} diff --git a/src/main/java/guru/springframework/msscbrewery/services/Foo.java b/src/main/java/guru/springframework/msscbrewery/services/Foo.java new file mode 100644 index 00000000..2540ab8b --- /dev/null +++ b/src/main/java/guru/springframework/msscbrewery/services/Foo.java @@ -0,0 +1,16 @@ +package guru.springframework.msscbrewery.services; + +public class Foo { + public Foo(String firstName, String lastName, int age, boolean married) {} + public static void main(String[] args) { + Foo joe = new FooBuilder().setFirstName("Joe").setLastName("Smith").setAge(42).setMarried(false).createFoo(); + } +} +//The Replace Constructor with Builder refactoring helps hide a constructor, +// replacing its usages with the references to a newly generated builder class, +// or to an existing builder class. + +// public Foo createFoo() { +// return new Foo(firstName, lastName, age, married); +// } + diff --git a/src/main/java/guru/springframework/msscbrewery/services/FooBuilder.java b/src/main/java/guru/springframework/msscbrewery/services/FooBuilder.java new file mode 100644 index 00000000..6d41c688 --- /dev/null +++ b/src/main/java/guru/springframework/msscbrewery/services/FooBuilder.java @@ -0,0 +1,32 @@ +package guru.springframework.msscbrewery.services; + +public class FooBuilder { + private String firstName; + private String lastName; + private int age; + private boolean married; + + public FooBuilder setFirstName(String firstName) { + this.firstName = firstName; + return this; + } + + public FooBuilder setLastName(String lastName) { + this.lastName = lastName; + return this; + } + + public FooBuilder setAge(int age) { + this.age = age; + return this; + } + + public FooBuilder setMarried(boolean married) { + this.married = married; + return this; + } + + public Foo createFoo() { + return new Foo(firstName, lastName, age, married); + } +} \ No newline at end of file diff --git a/src/main/java/guru/springframework/msscbrewery/web/controller/BeerController.java b/src/main/java/guru/springframework/msscbrewery/web/controller/BeerController.java index 49670652..281fdb1e 100644 --- a/src/main/java/guru/springframework/msscbrewery/web/controller/BeerController.java +++ b/src/main/java/guru/springframework/msscbrewery/web/controller/BeerController.java @@ -1,13 +1,11 @@ package guru.springframework.msscbrewery.web.controller; - +import org.slf4j.Logger; 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 java.util.UUID; @@ -29,5 +27,37 @@ public ResponseEntity getBeer(@PathVariable("beerId") UUID beerId){ return new ResponseEntity<>(beerService.getBeerById(beerId), HttpStatus.OK); } + @PostMapping // POST - create new beer + public ResponseEntity handlePost(@RequestBody BeerDto beerDto){ + + // BeerDto savedDto = BeerService.saveNewBeer(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 UpdateBeer(@PathVariable("beerId")UUID beerId ,BeerDto beerDto){ + beerService.updateBeer(beerId,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); + } } +//commit fork over fork plus fork + + + +// please fork + diff --git a/src/main/java/guru/springframework/msscbrewery/web/controller/CustomerController.java b/src/main/java/guru/springframework/msscbrewery/web/controller/CustomerController.java new file mode 100644 index 00000000..e3f37d9a --- /dev/null +++ b/src/main/java/guru/springframework/msscbrewery/web/controller/CustomerController.java @@ -0,0 +1,32 @@ +package guru.springframework.msscbrewery.web.controller; + + +import guru.springframework.msscbrewery.services.CustomerService; +import guru.springframework.msscbrewery.web.model.CustomerDto; +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 java.util.UUID; + +@RequestMapping("/api/v1/customer") +@RestController +public class CustomerController { + + private final CustomerService customerService; + + public CustomerController(CustomerService customerService) { + this.customerService = customerService; + } + + @GetMapping({"/{customerId}"}) + public ResponseEntity getBeer(@PathVariable("customerId") UUID customerId){ + + return new ResponseEntity<>(customerService.getCustomerById(customerId), HttpStatus.OK); + } +} +//Final Homework1 fork test brunch + diff --git a/src/main/java/guru/springframework/msscbrewery/web/model/CustomerDto.java b/src/main/java/guru/springframework/msscbrewery/web/model/CustomerDto.java new file mode 100644 index 00000000..ef8f2971 --- /dev/null +++ b/src/main/java/guru/springframework/msscbrewery/web/model/CustomerDto.java @@ -0,0 +1,20 @@ +package guru.springframework.msscbrewery.web.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.UUID; +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CustomerDto { + + private UUID id; + private String name; + + + +} diff --git a/target/classes/application.properties b/target/classes/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/target/classes/application.properties @@ -0,0 +1 @@ +