diff --git a/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java b/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java index 120e32e..1bdf6fc 100644 --- a/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java +++ b/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java @@ -4,8 +4,11 @@ import cn.mafangui.hotel.entity.RoomType; import cn.mafangui.hotel.service.RoomTypeService; 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.RestController; +import java.util.List; + @RestController @RequestMapping(value = "/roomType") public class RoomTypeController { @@ -13,14 +16,35 @@ public class RoomTypeController { @Autowired private RoomTypeService roomTypeService; - @RequestMapping(value = "/add") + @RequestMapping(method = RequestMethod.POST,value = "/add") public int addNewType(int roomType,String typeName,double bookingPrice,double bookingDiscount){ RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount); return roomTypeService.addRoomType(rt); } + @RequestMapping(method = RequestMethod.POST,value = "/del") public int delType(int roomType,String typeName){ - return 0; + RoomType rt = new RoomType(); + rt.setRoomType(roomType); + rt.setTypeName(typeName); + return roomTypeService.delRoomType(rt); } + @RequestMapping(method = RequestMethod.POST,value = "/update") + public int updateType(int roomType,String typeName,double bookingPrice,double bookingDiscount){ + RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount); + return roomTypeService.updateRoomType(rt); + } + + @RequestMapping(value = "/query") + public RoomType findByRoomType(int roomType){ + RoomType rt = new RoomType(); + rt.setRoomType(roomType); + return roomTypeService.selectByName(rt); + } + + @RequestMapping(value = "/all") + public List findAllRoomType(){ + return roomTypeService.findAllType(); + } } diff --git a/src/test/java/cn/mafangui/hotel/controller/RoomTypeControllerTest.java b/src/test/java/cn/mafangui/hotel/controller/RoomTypeControllerTest.java new file mode 100644 index 0000000..d1cfb76 --- /dev/null +++ b/src/test/java/cn/mafangui/hotel/controller/RoomTypeControllerTest.java @@ -0,0 +1,42 @@ +package cn.mafangui.hotel.controller; + +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.*; + + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest +public class RoomTypeControllerTest { + + @Autowired + private RoomTypeController roomTypeController; + + @Test + public void addNewType() { + } + + @Test + public void delType() { + } + + @Test + public void updateType() { + } + + @Test + public void findByRoomType() { + int roomType = 101; + Assert.assertNotNull(roomTypeController.findByRoomType(roomType)); + } + + @Test + public void findAllRoomType() { + Assert.assertNotNull(roomTypeController.findAllRoomType()); + } +} \ No newline at end of file