Skip to content

all tests pass... is the nightmare over?? #5

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 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 21 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.zipcodewilmington</groupId>
@@ -25,29 +25,29 @@
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
@@ -60,4 +60,4 @@
</build>


</project>
</project>
Original file line number Diff line number Diff line change
@@ -2,33 +2,44 @@

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

@Controller
public class BakerController {

private BakerService service;

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

@GetMapping("/bakers/")
public ResponseEntity<Iterable<Baker>> index() {
return new ResponseEntity<>(service.index(), 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
@@ -2,33 +2,44 @@

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

@Controller
public class MuffinController {

private MuffinService service;

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

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

public ResponseEntity<Muffin> show(Long id) {
@GetMapping(value = "/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(value = "/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(value = "/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(value = "/muffins/{id}")
public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
return new ResponseEntity<>(service.delete(id), HttpStatus.OK);
}
}
8 changes: 8 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,17 @@
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;
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 Muffin {

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

private String flavor;
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -2,10 +2,15 @@

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
public class BakerService {

private BakerRepository repository;

@Autowired
public BakerService(BakerRepository repository) {
this.repository = repository;
}
Original file line number Diff line number Diff line change
@@ -2,10 +2,15 @@

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
public class MuffinService {
private MuffinRepository repository;


private MuffinRepository repository;
@Autowired
public MuffinService(MuffinRepository repository) {
this.repository = repository;
}
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ public class BakerTest {
public void testClassSignatureAnnotations() {
Assert.assertTrue(Baker.class.isAnnotationPresent(Entity.class));
}

@Test
public void testCreateJson() throws JsonProcessingException {
ObjectMapper jsonWriter = new ObjectMapper();