!16 添加API插入接口

Merge pull request !16 from Sky_ID/feature_lwh
This commit is contained in:
Sky_ID 2020-12-15 15:30:25 +08:00 committed by Gitee
commit d420cc5697
6 changed files with 58 additions and 44 deletions

View File

@ -0,0 +1,27 @@
package com.letoy.edu.controller;
import com.letoy.edu.entity.MyApi;
import com.letoy.edu.service.UserApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@Api(value = "Api权限管理", tags = "Api权限管理API")
public class ApiManageController {
@Autowired
UserApiService userApiService;
@PostMapping("/api/insertApi")
@ApiOperation(value = "插入Api", notes = "插入Api")
@ApiImplicitParam(value = "",name = "Authorization",paramType = "header", dataType = "String", required=true)
private Map<String,Object> insertApi(MyApi myApi){
return userApiService.insertApi(myApi);
}
}

View File

@ -11,4 +11,6 @@ import java.util.List;
public interface UserApiMapper {
List<MyApi> getApiListByUserId(String id);
int cleanToken(String token);
int insertApi(MyApi myApi);
}

View File

@ -1,56 +1,19 @@
package com.letoy.edu.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MyApi {
private String id;
private String name;
private String url;
private String method;
private String role;
@Override
public String toString() {
return "MyApi{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", url='" + url + '\'' +
", method='" + method + '\'' +
'}';
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
}

View File

@ -6,6 +6,7 @@ import com.letoy.edu.service.UserApiService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
@Service
@ -22,4 +23,19 @@ public class UserApiServiceImpl implements UserApiService {
public boolean cleanToken(String token) {
return userApiMapper.cleanToken(token) >= 1;
}
@Override
public HashMap<String, Object> insertApi(MyApi myApi) {
HashMap<String, Object> hashMap = new HashMap<>();
int i = userApiMapper.insertApi(myApi);
if (i==0) {
hashMap.put("status","1");
hashMap.put("msg","插入失败");
return hashMap;
}
hashMap.put("status","0");
hashMap.put("msg","插入成功");
return hashMap;
}
}

View File

@ -2,9 +2,12 @@ package com.letoy.edu.service;
import com.letoy.edu.entity.MyApi;
import java.util.HashMap;
import java.util.List;
public interface UserApiService {
List<MyApi> getMyApiListByUserId(String id);
boolean cleanToken(String token);
HashMap<String,Object> insertApi(MyApi myApi);
}

View File

@ -16,4 +16,7 @@
where token = #{token}
</update>
<insert id="insertApi" parameterType="com.letoy.edu.entity.MyApi">
insert into api_table (name, url, method, role) VALUES (#{name},#{url},#{method},#{role})
</insert>
</mapper>