ESTA PAGINA TE CREA LAS DEPENDENCIAS GRADLE OR MAVEN DESDE CERO, AGREGANDO LAS DEPENDENCIAS QUE TU QUIERES
[
{
"id": 1,
"name": "Piccadilly",
"number": "P1",
"bedInfo": "1Q"
},
{
"id": 2,
"name": "Piccadilly",
"number": "P2",
"bedInfo": "1Q"
},
{
"id": 3,
"name": "Piccadilly",
"number": "P3",
"bedInfo": "1Q"
},
{
"id": 4,
"name": "Piccadilly",
"number": "P4",
"bedInfo": "2D"
},
{
"id": 5,
"name": "Piccadilly",
"number": "P5",
"bedInfo": "2D"
},
{
"id": 6,
"name": "Piccadilly",
"number": "P6",
"bedInfo": "2D"
},
{
"id": 7,
"name": "Cambridge",
"number": "C1",
"bedInfo": "1K"
},
{
"id": 8,
"name": "Cambridge",
"number": "C2",
"bedInfo": "1K"
},
{
"id": 9,
"name": "Cambridge",
"number": "C3",
"bedInfo": "1K"
},
{
"id": 10,
"name": "Westminster",
"number": "W1",
"bedInfo": "1K"
},
{
"id": 11,
"name": "Westminster",
"number": "W2",
"bedInfo": "1K"
},
{
"id": 12,
"name": "Westminster",
"number": "W3",
"bedInfo": "1K"
},
{
"id": 13,
"name": "Westminster",
"number": "W4",
"bedInfo": "1K"
},
{
"id": 14,
"name": "Westminster",
"number": "W5",
"bedInfo": "2D"
},
{
"id": 15,
"name": "Westminster",
"number": "W6",
"bedInfo": "2D"
},
{
"id": 16,
"name": "Westminster",
"number": "W7",
"bedInfo": "2D"
},
{
"id": 17,
"name": "Oxford",
"number": "O1",
"bedInfo": "1K"
},
{
"id": 18,
"name": "Oxford",
"number": "O2",
"bedInfo": "1K"
},
{
"id": 19,
"name": "Oxford",
"number": "O3",
"bedInfo": "1Q"
},
{
"id": 20,
"name": "Oxford",
"number": "O4",
"bedInfo": "1Q"
},
{
"id": 21,
"name": "Oxford",
"number": "O5",
"bedInfo": "1Q"
},
{
"id": 22,
"name": "Victoria",
"number": "V1",
"bedInfo": "1K"
},
{
"id": 23,
"name": "Victoria",
"number": "V2",
"bedInfo": "2D"
},
{
"id": 24,
"name": "Victoria",
"number": "V3",
"bedInfo": "2D"
},
{
"id": 25,
"name": "Manchester",
"number": "M1",
"bedInfo": "1K"
},
{
"id": 26,
"name": "Manchester",
"number": "M2",
"bedInfo": "1K"
},
{
"id": 27,
"name": "Manchester",
"number": "M3",
"bedInfo": "1K"
},
{
"id": 28,
"name": "Manchester",
"number": "M4",
"bedInfo": "1K"
}
]
CREATE TABLE ROOM(
ROOM_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
NAME VARCHAR(16) NOT NULL,
ROOM_NUMBER CHAR(2) NOT NULL UNIQUE,
BED_INFO CHAR(2) NOT NULL
);
CREATE TABLE GUEST(
GUEST_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
FIRST_NAME VARCHAR(64),
LAST_NAME VARCHAR(64),
EMAIL_ADDRESS VARCHAR(64),
ADDRESS VARCHAR(64),
COUNTRY VARCHAR(32),
STATE VARCHAR(12),
PHONE_NUMBER VARCHAR(24)
);
CREATE TABLE RESERVATION(
RESERVATION_ID BIGINT AUTO_INCREMENT PRIMARY KEY,
ROOM_ID BIGINT NOT NULL,
GUEST_ID BIGINT NOT NULL,
RES_DATE DATE
);
ALTER TABLE RESERVATION ADD FOREIGN KEY (ROOM_ID) REFERENCES ROOM(ROOM_ID);
ALTER TABLE RESERVATION ADD FOREIGN KEY (GUEST_ID) REFERENCES GUEST(GUEST_ID);
CREATE INDEX IDX_RES_DATE_ ON RESERVATION(RES_DATE);
package com.frankmoley.landon.data.webservice;
import com.frankmoley.landon.data.entity.Room;
import com.frankmoley.landon.data.repository.RoomRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
public class RoomController {
@Autowired
private RoomRepository repository;
@RequestMapping(value="/rooms", method= RequestMethod.GET)
List<Room> findAll(@RequestParam(required=false) String roomNumber){
List<Room> rooms = new ArrayList<>();
if(null==roomNumber){
Iterable<Room> results = this.repository.findAll();
results.forEach(room-> {rooms.add(room);});
}else{
Room room = this.repository.findByNumber(roomNumber);
if(null!=room) {
rooms.add(room);
}
}
return rooms;
}
}
No hay comentarios:
Publicar un comentario