Skip to content

All finished #6

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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,10 +2,17 @@

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.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RequestMapping("api/v1/bakery")
@Controller
public class BakerController {

@Autowired
private BakerService service;

public BakerController(BakerService service) {
Expand All @@ -16,19 +23,23 @@ public ResponseEntity<Iterable<Baker>> index() {
return new ResponseEntity<>(service.index(), HttpStatus.OK);
}

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

public ResponseEntity<Baker> create(Baker baker) {
@PostMapping(path = "/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(path = "/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(path = "/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,10 +2,17 @@

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.*;

@RequestMapping("api/v1/bakery")
@Controller
public class MuffinController {

@Autowired
private MuffinService service;

public MuffinController(MuffinService service) {
Expand All @@ -16,19 +23,23 @@ public ResponseEntity<Iterable<Muffin>> index() {
return new ResponseEntity<>(service.index(), HttpStatus.OK);
}

public ResponseEntity<Muffin> show(Long id) {
@GetMapping(path = "/muffins/{id}")
public ResponseEntity<Muffin> show(@PathVariable("id") 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(path = "/muffins")
public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
return new ResponseEntity<>(service.create(muffin), HttpStatus.CREATED);
}

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

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


import com.fasterxml.jackson.annotation.JsonProperty;

import javax.persistence.*;
import java.util.Objects;

@Entity
public class Baker {

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

@JsonProperty("name")
private String name;

@JsonProperty("employeeId")
private String employeeId;

@JsonProperty("speciality")
private String specialty;

public Baker() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/zipcodewilmington/bakery/models/Muffin.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.zipcodewilmington.bakery.models;

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.persistence.*;
import java.util.Objects;

@Entity
public class Muffin {

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

@JsonProperty("flavor")
private String flavor;

public Muffin() {
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.Repository;

@Repository
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.Repository;

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

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

@Service
public class BakerService {
private BakerRepository repository;

Expand All @@ -26,6 +28,7 @@ public Baker update(Long id, Baker newBakerData) {
Baker originalBaker = repository.findById(id).get();
originalBaker.setName(newBakerData.getName());
originalBaker.setSpecialty(newBakerData.getSpecialty());
originalBaker.setEmployeeId(newBakerData.getEmployeeId());
return repository.save(originalBaker);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

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

@Service
public class MuffinService {
private MuffinRepository repository;

Expand Down