Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,47 @@

import com.zipcodewilmington.bakery.models.Baker;
import com.zipcodewilmington.bakery.services.BakerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.persistence.Entity;
import javax.persistence.Id;

@Controller
public class BakerController {
private BakerService service;

@Autowired
public BakerController(BakerService service) {
this.service = service;
}

public ResponseEntity<Iterable<Baker>> index() {
return new ResponseEntity<>(service.index(), HttpStatus.OK);
@GetMapping("/bakers")
public ResponseEntity<Iterable<Baker>> findAll() {
return new ResponseEntity<>(service.findAll(), HttpStatus.OK);
}

public ResponseEntity<Baker> show(Long id) {
@GetMapping("/bakers/{id}")
public ResponseEntity<Baker> show(@PathVariable Long id) {
return new ResponseEntity<>(service.show(id), HttpStatus.OK);
}

public ResponseEntity<Baker> create(Baker baker) {
@PostMapping("/bakers")
public ResponseEntity<Baker> create(@RequestBody Baker baker) {
return new ResponseEntity<>(service.create(baker), HttpStatus.CREATED);
}

public ResponseEntity<Baker> update(Long id, Baker baker) {
@PutMapping("/bakers/{id}")
public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
return new ResponseEntity<>(service.update(id, baker), HttpStatus.OK);
}

public ResponseEntity<Boolean> destroy(Long id) {
@DeleteMapping("/bakers/{id}")
public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
return new ResponseEntity<>(service.delete(id), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,45 @@

import com.zipcodewilmington.bakery.models.Muffin;
import com.zipcodewilmington.bakery.services.MuffinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.persistence.Entity;

@Controller
public class MuffinController {
private MuffinService service;

@Autowired
public MuffinController(MuffinService service) {
this.service = service;
}

@GetMapping("/muffins")
public ResponseEntity<Iterable<Muffin>> index() {
return new ResponseEntity<>(service.index(), HttpStatus.OK);
return new ResponseEntity<>(service.findAll(), HttpStatus.OK);
}

public ResponseEntity<Muffin> show(Long id) {
@GetMapping("/muffins/{id}")
public ResponseEntity<Muffin> show(@PathVariable Long id) {
return new ResponseEntity<>(service.show(id), HttpStatus.OK);
}

public ResponseEntity<Muffin> create(Muffin baker) {
return new ResponseEntity<>(service.create(baker), HttpStatus.CREATED);
@PostMapping("/muffins")
public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
return new ResponseEntity<>(service.create(muffin), HttpStatus.CREATED);
}

public ResponseEntity<Muffin> update(Long id, Muffin baker) {
return new ResponseEntity<>(service.update(id, baker), HttpStatus.OK);
@PutMapping("/muffins/{id}")
public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
return new ResponseEntity<>(service.update(id, muffin), HttpStatus.OK);
}

public ResponseEntity<Boolean> destroy(Long id) {
@DeleteMapping("/muffins/{id}")
public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
return new ResponseEntity<>(service.delete(id), HttpStatus.OK);
}
}
8 changes: 7 additions & 1 deletion src/main/java/com/zipcodewilmington/bakery/models/Baker.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.zipcodewilmington.bakery.models;


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Objects;

@Entity
public class Baker {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/zipcodewilmington/bakery/models/Muffin.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.zipcodewilmington.bakery.models;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Objects;

@Entity
public class Muffin {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String flavor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.zipcodewilmington.bakery.models.Baker;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

@Component
public interface BakerRepository extends CrudRepository<Baker, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.zipcodewilmington.bakery.models.Muffin;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

@Component
public interface MuffinRepository extends CrudRepository<Muffin, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import com.zipcodewilmington.bakery.models.Baker;
import com.zipcodewilmington.bakery.repositories.BakerRepository;
import org.springframework.stereotype.Service;

@Service
public class BakerService {
private BakerRepository repository;

public BakerService(BakerRepository repository) {
this.repository = repository;
}

public Iterable<Baker> index() {
public Iterable<Baker> findAll() {
return repository.findAll();
}

Expand All @@ -25,6 +27,7 @@ public Baker create(Baker baker) {
public Baker update(Long id, Baker newBakerData) {
Baker originalBaker = repository.findById(id).get();
originalBaker.setName(newBakerData.getName());
originalBaker.setEmployeeId(newBakerData.getEmployeeId());
originalBaker.setSpecialty(newBakerData.getSpecialty());
return repository.save(originalBaker);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

import com.zipcodewilmington.bakery.models.Muffin;
import com.zipcodewilmington.bakery.repositories.MuffinRepository;
import org.springframework.stereotype.Service;

@Service
public class MuffinService {
private MuffinRepository repository;

public MuffinService(MuffinRepository repository) {
this.repository = repository;
}

public Iterable<Muffin> index() {
public Iterable<Muffin> findAll() {
return repository.findAll();
}

public Muffin show(Long id) {
return repository.findById(id).get();
}

public Muffin create(Muffin baker) {
return repository.save(baker);
public Muffin create(Muffin muffin) {
return repository.save(muffin);
}

public Muffin update(Long id, Muffin newMuffinData) {
Expand Down