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
63 changes: 31 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
# Jetbrains IntelliJ Idea
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml

# Linux
# backup files
*~

# Windows
# thumbnails
Thumbs.db

# Mac OS X
# metadata
.DS_Store
# thumbnails
._*

# GIT
.git/

# Java
*.class

# packages
*.jar
*.war
*.ear

# Logging
*.log

# jME (binaries)
*.so
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
63 changes: 37 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ A student that completes this project shows that they can:

## Introduction

This is a basic database scheme with zoos, animals, and telephones for the zoos. This Java Spring REST API application will provide endpoints for clients to read various data sets contained in the application's data.
This is a basic database scheme with zoos, animals, and telephones for the zoos. This Java Spring REST API application
will provide endpoints for clients to read various data sets contained in the application's data.

### Database layout

Expand All @@ -20,35 +21,39 @@ You are creating a Java Spring REST API server that stores data in an H2 databas
![Zoo Database Layout](zoodb_mvp.png)

* All tables contain the following auditing fields
* `createdby` - user name who created the row. Should default to **SYSTEM**
* `createddate` - date field when the row was created
* `lastmodifiedby` - user name who last changed data in the row. Should default to **SYSTEM**
* `lastmodifieddate` - date field when the data in the row was last changed
* `createdby` - user name who created the row. Should default to **SYSTEM**
* `createddate` - date field when the row was created
* `lastmodifiedby` - user name who last changed data in the row. Should default to **SYSTEM**
* `lastmodifieddate` - date field when the data in the row was last changed

* Zoo
* `zooid` - long primary key
* `zooname` - String Name of the Zoo
* `zooid` - long primary key
* `zooname` - String Name of the Zoo

* Telephone
* `phoneid` - long primary key
* `phonetype` - String - something like MAIN, EDUCATION, MEMBERSHIP, FAX, OPERATOR, OTHER
* `phonenumber` - String - a telephone number in any format
* `zooid` - foreign key to the Zoo table indicating the zoo who holds this telephone number

There is a one to many relationship between zoos and telephones. One zoo can have multiple phone numbers but each phone number can only belong to one zoo.
* `phoneid` - long primary key
* `phonetype` - String - something like MAIN, EDUCATION, MEMBERSHIP, FAX, OPERATOR, OTHER
* `phonenumber` - String - a telephone number in any format
* `zooid` - foreign key to the Zoo table indicating the zoo who holds this telephone number

There is a one to many relationship between zoos and telephones. One zoo can have multiple phone numbers but each phone
number can only belong to one zoo.

* Animal
* `animalid` - long primary key
* `animaltype` - String - the type of animal such as lion or llama
* `animalid` - long primary key
* `animaltype` - String - the type of animal such as lion or llama

Zooaminals represents is a many to many relationship between zoos and animals. A zoo may have many animal types and an animal type may be at many zoos.
Zooaminals represents is a many to many relationship between zoos and animals. A zoo may have many animal types and an
animal type may be at many zoos.

* Zooanimals
* `zooid` - long foreign key to zoo
* `animalid` - long foreign key to animal
* `incomingzoo` - String - the name of the zoo when the animal came from. The field can be left blank or null if the animal does not come from another zoo.
* `zooid` - long foreign key to zoo
* `animalid` - long foreign key to animal
* `incomingzoo` - String - the name of the zoo when the animal came from. The field can be left blank or null if the
animal does not come from another zoo.

Using the provided seed data, a successful application will return the follow data based on the given endpoint. Expand the section of the endpoint to see the data that is returned.
Using the provided seed data, a successful application will return the follow data based on the given endpoint. Expand
the section of the endpoint to see the data that is returned.

### MVP

Expand Down Expand Up @@ -417,20 +422,26 @@ Status OK

## Instructions

* [ ] Please fork and clone this repository. This repository does not have a starter project, so create one inside of the cloned repository folder. Regularly commit and push your code as appropriate.
* [ ] Please fork and clone this repository. This repository does not have a starter project, so create one inside of
the cloned repository folder. Regularly commit and push your code as appropriate.
* [ ] Create the entities needed to store this data.
* [ ] A data.sql file has been provided with seed data. You can use this class directly or modify it to fit your models. However, the data found in the file is the seed data to use!
* [ ] A data.sql file has been provided with seed data. You can use this class directly or modify it to fit your models.
However, the data found in the file is the seed data to use!
* [ ] Add default Swagger Documentation

Expose the following Endpoint

* [ ] GET /animals/count - that returns a JSON object list listing the animals and a count of how many zoos where they can be found. Use a custom query for this.
* [ ] GET /animals/count - that returns a JSON object list listing the animals and a count of how many zoos where they
can be found. Use a custom query for this.
* [ ] GET /zoos/zoos - returns all zoos with their phone numbers and animals
* [ ] GET /zoos/zoo/{id} - returns all information related to a zoo based on its id

## Stretch goals

* [ ] POST /zoos/zoo - adds a zoo including new telephone number and zoo animal combinations. The Animal Type must already exist. * In the header return as the location of the newly created zoo POST /zoos/zoo/{id}
* [ ] POST /zoos/zoo - adds a zoo including new telephone number and zoo animal combinations. The Animal Type must
already exist. * In the header return as the location of the newly created zoo POST /zoos/zoo/{id}
* [ ] PUT /zoos/zoo/{id} - Completely replace the zoo record and all accompany records based off of the given zoo id.
* [ ] PATCH /zoos/zoo/{id} - Updates the zoo with new information. Only the new data is to be sent from the frontend client.
* [ ] DELETE /zoos/zoo/{id} - delete the zoo, associated phone numbers, and zoo animals combination associated with this zoo id
* [ ] PATCH /zoos/zoo/{id} - Updates the zoo with new information. Only the new data is to be sent from the frontend
client.
* [ ] DELETE /zoos/zoo/{id} - delete the zoo, associated phone numbers, and zoo animals combination associated with this
zoo id
58 changes: 29 additions & 29 deletions data.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

DELETE
FROM zooanimals;

Expand All @@ -12,38 +11,39 @@ DELETE
FROM zoos;

INSERT INTO zoos (zooid, zooname, createdby, createddate, lastmodifiedby, lastmodifieddate)
VALUES (1, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(2, 'Point Defiance Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 'San Diego Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(4, 'San Antonio Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 'Smithsonian National Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP);

INSERT INTO telephones (phoneid, phonetype, phonenumber, zooid, createdby, createddate, lastmodifiedby, lastmodifieddate)
VALUES (1, 'MAIN', '555-555-5555', 1, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(2, 'EDUCATION', '555-555-1234', 1, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 'MEMBERSHIP', '555-555-4321', 1, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(4, 'MAIN', '123-555-5555', 4, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 'MAIN', '555-123-5555', 3, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP);
VALUES (1, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(2, 'Point Defiance Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 'San Diego Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(4, 'San Antonio Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 'Smithsonian National Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP);

INSERT INTO telephones (phoneid, phonetype, phonenumber, zooid, createdby, createddate, lastmodifiedby,
lastmodifieddate)
VALUES (1, 'MAIN', '555-555-5555', 1, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(2, 'EDUCATION', '555-555-1234', 1, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 'MEMBERSHIP', '555-555-4321', 1, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(4, 'MAIN', '123-555-5555', 4, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 'MAIN', '555-123-5555', 3, 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP);

INSERT INTO animals (animalid, animaltype, createdby, createddate, lastmodifiedby, lastmodifieddate)
VALUES (1, 'lion', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(2, 'bear', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 'monkey', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(4, 'penguin', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 'tiger', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(6, 'llama', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(7, 'turtle', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP);
VALUES (1, 'lion', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(2, 'bear', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 'monkey', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(4, 'penguin', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 'tiger', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(6, 'llama', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(7, 'turtle', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP);

INSERT INTO zooanimals (zooid, animalid, incomingzoo, createdby, createddate, lastmodifiedby, lastmodifieddate)
VALUES (1, 1, 'Point Defiance Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(2, 2, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(1, 2, 'Point Defiance Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 7, 'San Diego Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 6, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 5, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 1, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 1, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 2, 'Point Defiance Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP);
VALUES (1, 1, 'Point Defiance Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(2, 2, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(1, 2, 'Point Defiance Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 7, 'San Diego Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 6, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 5, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(5, 1, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 1, 'Gladys Porter Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP),
(3, 2, 'Point Defiance Zoo', 'SYSTEM', CURRENT_TIMESTAMP, 'SYSTEM', CURRENT_TIMESTAMP);

/*
We must tell hibernate the ids that have already been used.
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/lambdaschool/zoos/config/H2ServerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package lambdaschool.zoos.config;

import org.h2.tools.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.sql.SQLException;

@Configuration
class H2ServerConfiguration
{

@Value("${h2.tcp.port:9092}")
private String h2TcpPort;

@Value("${h2.web.port:8082}")
private String h2WebPort;

@Bean
@ConditionalOnExpression("${h2.tcp.enabled:true}")
public Server h2TcpServer() throws
SQLException
{
return Server.createTcpServer("-tcp",
"-tcpAllowOthers",
"-tcpPort",
h2TcpPort)
.start();
}

@Bean
@ConditionalOnExpression("${h2.web.enabled:true}")
public Server h2WebServer() throws
SQLException
{
return Server.createWebServer("-web",
"-webAllowOthers",
"-webPort",
h2WebPort)
.start();
}
}
24 changes: 24 additions & 0 deletions src/main/java/lambdaschool/zoos/controllers/AnimalController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lambdaschool.zoos.controllers;

import lambdaschool.zoos.services.AnimalServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/animals")
public class AnimalController {

// @Autowired
// private AnimalServices animalServices;
//
//
// @GetMapping(value = "/count", produces = "application/json")
// public ResponseEntity<?> getAnimalCount(){
// return new ResponseEntity<>(animalServices.getAnimalCount(), HttpStatus.OK);
// }

}
22 changes: 22 additions & 0 deletions src/main/java/lambdaschool/zoos/controllers/ZooController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lambdaschool.zoos.controllers;

import lambdaschool.zoos.services.ZooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/zoos")
public class ZooController {

@Autowired
private ZooService zooService;

@GetMapping(value = "/zoo", produces = "application/json")
public ResponseEntity<?> findAllZoos(){
return new ResponseEntity<>(zooService.findZoos(), HttpStatus.OK);
}
}
Loading