苍穹外卖--管理端和用户端对店铺状态的设置与获取功能实现&swagger的分组接口展示操作
This commit is contained in:
@@ -48,7 +48,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Bean//将当前方法的返回值交给spring容器来管理
|
@Bean//将当前方法的返回值交给spring容器来管理
|
||||||
public Docket docket() {
|
public Docket docket1() {
|
||||||
log.info("准备生成接口文档....");
|
log.info("准备生成接口文档....");
|
||||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||||
.title("苍穹外卖项目接口文档")
|
.title("苍穹外卖项目接口文档")
|
||||||
@@ -56,9 +56,29 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||||||
.description("苍穹外卖项目接口文档")
|
.description("苍穹外卖项目接口文档")
|
||||||
.build();
|
.build();
|
||||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.groupName("管理端接口")
|
||||||
.apiInfo(apiInfo)
|
.apiInfo(apiInfo)
|
||||||
.select()
|
.select()
|
||||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
|
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
.build();
|
||||||
|
return docket;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean//将当前方法的返回值交给spring容器来管理
|
||||||
|
public Docket docket2() {
|
||||||
|
log.info("准备生成接口文档....");
|
||||||
|
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||||
|
.title("苍穹外卖项目接口文档")
|
||||||
|
.version("2.0")
|
||||||
|
.description("苍穹外卖项目接口文档")
|
||||||
|
.build();
|
||||||
|
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.groupName("用户端接口")
|
||||||
|
.apiInfo(apiInfo)
|
||||||
|
.select()
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.user"))
|
||||||
.paths(PathSelectors.any())
|
.paths(PathSelectors.any())
|
||||||
.build();
|
.build();
|
||||||
return docket;
|
return docket;
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺的营业状态
|
||||||
|
*/
|
||||||
|
@RestController("adminShopController")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "店铺状态相关的接口")
|
||||||
|
@RequestMapping("/admin/shop")
|
||||||
|
public class ShopController {
|
||||||
|
|
||||||
|
public static final String SHOP_STATUS = "SHOP_STATUS";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置营业状态
|
||||||
|
* @param status
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/{status}")
|
||||||
|
@ApiOperation("设置营业状态")
|
||||||
|
public Result setStatus(@PathVariable Integer status){
|
||||||
|
log.info("设置店铺的营业状态:{}",status);
|
||||||
|
redisTemplate.opsForValue().set(SHOP_STATUS,status);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询营业状态
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/status")
|
||||||
|
@ApiOperation("获取营业状态")
|
||||||
|
public Result<Integer> getStatus(){
|
||||||
|
log.info("获取店铺的营业状态");
|
||||||
|
Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
|
||||||
|
return Result.success(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺的营业状态
|
||||||
|
*/
|
||||||
|
@RestController("userShopController")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "店铺状态相关的接口")
|
||||||
|
@RequestMapping("/user/shop")
|
||||||
|
public class ShopController {
|
||||||
|
|
||||||
|
public static final String SHOP_STATUS = "SHOP_STATUS";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询营业状态
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/status")
|
||||||
|
@ApiOperation("获取营业状态")
|
||||||
|
public Result<Integer> getStatus(){
|
||||||
|
log.info("获取店铺的营业状态");
|
||||||
|
Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
|
||||||
|
return Result.success(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,10 +10,10 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@SpringBootTest
|
//@SpringBootTest
|
||||||
public class SpringDataRedisTest {
|
public class SpringDataRedisTest {
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user