Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borra #30

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,6 +10,7 @@
* Created by jt on 2019-04-20.
*/
@Service
@Slf4j
public class BeerServiceImpl implements BeerService {
@Override
public BeerDto getBeerById(UUID beerId) {
Expand All @@ -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
}
31 changes: 31 additions & 0 deletions src/main/java/guru/springframework/msscbrewery/services/Class.java
Original file line number Diff line number Diff line change
@@ -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");
// }
//}
Original file line number Diff line number Diff line change
@@ -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);


}
Original file line number Diff line number Diff line change
@@ -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();
}


}
16 changes: 16 additions & 0 deletions src/main/java/guru/springframework/msscbrewery/services/Foo.java
Original file line number Diff line number Diff line change
@@ -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);
// }

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -29,5 +27,37 @@ public ResponseEntity<BeerDto> 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

Original file line number Diff line number Diff line change
@@ -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<CustomerDto> getBeer(@PathVariable("customerId") UUID customerId){

return new ResponseEntity<>(customerService.getCustomerById(customerId), HttpStatus.OK);
}
}
//Final Homework1 fork test brunch

Original file line number Diff line number Diff line change
@@ -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;



}
1 change: 1 addition & 0 deletions target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@