完成对房间类型的简单操作

This commit is contained in:
freeebird 2018-10-16 19:22:37 +08:00
parent 78f900b710
commit 9c7af9d032
2 changed files with 68 additions and 2 deletions

View File

@ -4,8 +4,11 @@ import cn.mafangui.hotel.entity.RoomType;
import cn.mafangui.hotel.service.RoomTypeService; import cn.mafangui.hotel.service.RoomTypeService;
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;
@RestController @RestController
@RequestMapping(value = "/roomType") @RequestMapping(value = "/roomType")
public class RoomTypeController { public class RoomTypeController {
@ -13,14 +16,35 @@ public class RoomTypeController {
@Autowired @Autowired
private RoomTypeService roomTypeService; private RoomTypeService roomTypeService;
@RequestMapping(value = "/add") @RequestMapping(method = RequestMethod.POST,value = "/add")
public int addNewType(int roomType,String typeName,double bookingPrice,double bookingDiscount){ public int addNewType(int roomType,String typeName,double bookingPrice,double bookingDiscount){
RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount); RoomType rt = new RoomType(roomType,typeName,bookingPrice,bookingDiscount);
return roomTypeService.addRoomType(rt); return roomTypeService.addRoomType(rt);
} }
@RequestMapping(method = RequestMethod.POST,value = "/del")
public int delType(int roomType,String typeName){ 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<RoomType> findAllRoomType(){
return roomTypeService.findAllType();
}
} }

View File

@ -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());
}
}