mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
完成房间信息接口编写,通过单元测试
This commit is contained in:
parent
8c14346247
commit
ed537bd926
@ -4,6 +4,7 @@ import cn.mafangui.hotel.entity.Room;
|
|||||||
import cn.mafangui.hotel.service.RoomService;
|
import cn.mafangui.hotel.service.RoomService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -15,11 +16,42 @@ public class RoomController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RoomService roomService;
|
private RoomService roomService;
|
||||||
|
|
||||||
@RequestMapping(value = "/all")
|
@RequestMapping(value = "/add")
|
||||||
public List<Room> getAllRoom(){
|
public int addRoom(String roomNumber,int typeId,String roomType,double roomPrice,double roomDiscount,int roomStatus,String remark){
|
||||||
List<Room> result = roomService.selectAll();
|
Room room = new Room(roomNumber,typeId,roomType,roomPrice,roomDiscount,roomStatus,remark);
|
||||||
for (Room r:result) {
|
return roomService.insert(room);
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST,value = "/delete")
|
||||||
|
public int deleteRoom(int roomId){
|
||||||
|
return roomService.delete(roomId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/update")
|
||||||
|
public int updateRoom(int roomId,String roomNumber,int typeId,
|
||||||
|
String roomType,double roomPrice,double roomDiscount,int roomStatus,String remark){
|
||||||
|
Room room = new Room(roomNumber,typeId,roomType,roomPrice,roomDiscount,roomStatus,remark);
|
||||||
|
room.setRoomId(roomId);
|
||||||
|
return roomService.update(room);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/withId")
|
||||||
|
public Room getById(int roomId){
|
||||||
|
return roomService.selectById(roomId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/withType")
|
||||||
|
public List<Room> getByType(int typeId){
|
||||||
|
return roomService.selectByType(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/withStatus")
|
||||||
|
public List<Room> getByStatus(int roomStatus){
|
||||||
|
return roomService.selectByStatus(roomStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/all")
|
||||||
|
public List<Room> getAll(){
|
||||||
|
return roomService.selectAll();
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,12 @@ public class RoomTypeController {
|
|||||||
return roomTypeService.findAllType();
|
return roomTypeService.findAllType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/withId")
|
||||||
|
public RoomType getById(int typeId){
|
||||||
|
return roomTypeService.selectById(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/add")
|
@RequestMapping(method = RequestMethod.POST,value = "/add")
|
||||||
public int addRoomType(String roomType,Double price,Double discount,int area,
|
public int addRoomType(String roomType,Double price,Double discount,int area,
|
||||||
int bedNum,String bedSize,int window,String remark){
|
int bedNum,String bedSize,int window,String remark){
|
||||||
|
@ -103,6 +103,19 @@ public class Room {
|
|||||||
this.updateTime = updateTime;
|
this.updateTime = updateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Room() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Room(String roomNumber, Integer typeId, String roomType, Double roomPrice, Double roomDiscount, Integer roomStatus, String remark) {
|
||||||
|
this.roomNumber = roomNumber;
|
||||||
|
this.typeId = typeId;
|
||||||
|
this.roomType = roomType;
|
||||||
|
this.roomPrice = roomPrice;
|
||||||
|
this.roomDiscount = roomDiscount;
|
||||||
|
this.roomStatus = roomStatus;
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Room{" +
|
return "Room{" +
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package cn.mafangui.hotel.controller;
|
||||||
|
|
||||||
|
import cn.mafangui.hotel.entity.Room;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
public class RoomControllerTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RoomController rc;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addRoom() {
|
||||||
|
|
||||||
|
Assert.assertEquals(1,rc.addRoom("100",2,"单人房",
|
||||||
|
108.0,20.0,1,"1 person"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteRoom() {
|
||||||
|
Assert.assertEquals(1,rc.deleteRoom(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateRoom() {
|
||||||
|
Assert.assertEquals(1,rc.updateRoom(2,"200",2,"单人房",
|
||||||
|
108.0,20.0,1,"1 person"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getById() {
|
||||||
|
int res = rc.getById(2).getTypeId();
|
||||||
|
Assert.assertEquals(2,res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getByType() {
|
||||||
|
int res = rc.getByType(2).size();
|
||||||
|
Assert.assertEquals(1,res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getByStatus() {
|
||||||
|
int res = rc.getByStatus(1).size();
|
||||||
|
Assert.assertEquals(2,res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAll() {
|
||||||
|
int res = rc.getAll().size();
|
||||||
|
Assert.assertEquals(2,res);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user