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,43 @@

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.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/baker-controller")
public class BakerController {

@Autowired
private BakerService service;

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

@GetMapping("/index") //@GetMapping maps a / root path from a GET request to the index() method
public ResponseEntity<Iterable<Baker>> index() {
return new ResponseEntity<>(service.index(), HttpStatus.OK);
}

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

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

public ResponseEntity<Baker> update(Long id, Baker baker) {
@PutMapping (value = "/update/{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(value = "/delete/{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,46 @@

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.web.bind.annotation.*;

//CONTROLLER - REQUEST MAPPING
@RestController
@RequestMapping(value = "/muffin-controller")

public class MuffinController {

@Autowired
private MuffinService service;

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

@GetMapping("/index") //@GetMapping maps a / root path from a GET request to the index() method
public ResponseEntity<Iterable<Muffin>> index() {
return new ResponseEntity<>(service.index(), HttpStatus.OK);
}

public ResponseEntity<Muffin> show(Long id) {

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

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

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

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


import org.springframework.stereotype.Component;

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

@Entity
@Component
public class Baker {

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

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

import org.springframework.stereotype.Component;

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


@Entity
@Component
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.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,8 +2,13 @@

import com.zipcodewilmington.bakery.models.Baker;
import com.zipcodewilmington.bakery.repositories.BakerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service //responsible for preforming service tasks
public class BakerService {

@Autowired //service is specialized component.
private BakerRepository repository;

public BakerService(BakerRepository repository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

import com.zipcodewilmington.bakery.models.Muffin;
import com.zipcodewilmington.bakery.repositories.MuffinRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service //responsible for service class
public class MuffinService {

@Autowired
private MuffinRepository repository;

public MuffinService(MuffinRepository repository) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
server.port=8080