mirror of
				https://github.com/FreeeBird/hotel.git
				synced 2025-10-31 12:34:54 +08:00 
			
		
		
		
	完成操作员接口编写,通过单元测试
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| package cn.mafangui.hotel.controller; | ||||
|  | ||||
| import cn.mafangui.hotel.entity.Worker; | ||||
| import cn.mafangui.hotel.service.WorkerService; | ||||
| import cn.mafangui.hotel.utils.StaticString; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -7,18 +8,14 @@ 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 = "/operator") | ||||
| public class OperatorController { | ||||
|     @Autowired | ||||
|     private WorkerService workerService; | ||||
|  | ||||
|     /** | ||||
|      * 管理员登录 | ||||
|      * @param username | ||||
|      * @param password | ||||
|      * @return | ||||
|      */ | ||||
|     @RequestMapping(method = RequestMethod.POST,value = "/login") | ||||
|     public int login(String username,String password){ | ||||
|         if(workerService.login(username,password, StaticString.OPERATOR) != null) | ||||
| @@ -26,6 +23,39 @@ public class OperatorController { | ||||
|         else return 0; | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(method = RequestMethod.POST,value = "/delete") | ||||
|     public int deleteOperator(int workerId){ | ||||
|         return workerService.delete(workerId); | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(value = "/all") | ||||
|     public List<Worker> getAllOperator(){ | ||||
|         return workerService.selectByRole(StaticString.OPERATOR); | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(method = RequestMethod.POST,value = "/withId") | ||||
|     public Worker getOperator(int workerId){ | ||||
|         return workerService.selectById(workerId); | ||||
|     } | ||||
|  | ||||
|     @RequestMapping(method = RequestMethod.POST,value = "/add") | ||||
|     public int addOperator(String username,String password,String name,String gender,String phone,String email,String address){ | ||||
|         Worker worker = new Worker(username,password,name,gender,phone,email,address); | ||||
|         worker.setRole(StaticString.OPERATOR); | ||||
|         return workerService.insert(worker); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     @RequestMapping(method = RequestMethod.POST,value = "/update") | ||||
|     public int updateOperator(int workerId,String name,String gender,String phone,String email,String address){ | ||||
|         Worker worker = new Worker(); | ||||
|         worker.setWorkerId(workerId); | ||||
|         worker.setName(name); | ||||
|         worker.setGender(gender); | ||||
|         worker.setPhone(phone); | ||||
|         worker.setEmail(email); | ||||
|         worker.setAddress(address); | ||||
|         return workerService.updateById(worker); | ||||
|     } | ||||
|  | ||||
|     // TODO | ||||
| } | ||||
|   | ||||
| @@ -123,6 +123,19 @@ public class Worker { | ||||
|         this.updateTime = updateTime; | ||||
|     } | ||||
|  | ||||
|     public Worker() { | ||||
|     } | ||||
|  | ||||
|     public Worker(String username, String password, String name, String gender, String phone, String email, String address) { | ||||
|         this.username = username; | ||||
|         this.password = password; | ||||
|         this.name = name; | ||||
|         this.gender = gender; | ||||
|         this.phone = phone; | ||||
|         this.email = email; | ||||
|         this.address = address; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "Worker{" + | ||||
|   | ||||
| @@ -0,0 +1,49 @@ | ||||
| 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.*; | ||||
|  | ||||
| @SpringBootTest | ||||
| @RunWith(SpringJUnit4ClassRunner.class) | ||||
| public class OperatorControllerTest { | ||||
|     @Autowired | ||||
|     OperatorController oc; | ||||
|  | ||||
|     @Test | ||||
|     public void login() { | ||||
|         Assert.assertEquals(1,oc.login("w1","w1")); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void deleteOperator() { | ||||
|         Assert.assertEquals(1,oc.deleteOperator(2)); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void getAllOperator() { | ||||
|         Assert.assertEquals(1,oc.getAllOperator().size()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void getOperator() { | ||||
|         Assert.assertNotNull(oc.getOperator(2)); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void addOperator() { | ||||
|         int res = oc.addOperator("op","op","杜锋","男","124342","assf","jfad"); | ||||
|         Assert.assertEquals(1,res); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void updateOperator() { | ||||
|         int res = oc.updateOperator(3,"疾风","女","32132","asdsa","assf"); | ||||
|         Assert.assertEquals(1,res); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user