添加api接口
This commit is contained in:
parent
f47beacecb
commit
f44a6a5da5
|
@ -134,7 +134,7 @@ public class SecurityConfig {
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
// 对于登录login 注册register 验证码captchaImage 以及公共Api的请求允许匿名访问
|
// 对于登录login 注册register 验证码captchaImage 以及公共Api的请求允许匿名访问
|
||||||
// 注意: 当携带token请求以下这几个接口时 会返回403的错误
|
// 注意: 当携带token请求以下这几个接口时 会返回403的错误
|
||||||
.antMatchers("/login", "/register", "/getConfig", "/captchaImage", "/api/**").anonymous()
|
.antMatchers("/login", "/register", "/getConfig", "/captchaImage", "/api/**", "/file/**").anonymous()
|
||||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js",
|
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js",
|
||||||
"/profile/**").permitAll()
|
"/profile/**").permitAll()
|
||||||
// TODO this is danger.
|
// TODO this is danger.
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.agileboot.api.controller;
|
||||||
|
|
||||||
|
import com.agileboot.api.response.ShopGoodsResponse;
|
||||||
|
import com.agileboot.common.core.dto.ResponseDTO;
|
||||||
|
import com.agileboot.domain.shop.category.CategoryApplicationService;
|
||||||
|
import com.agileboot.domain.shop.category.dto.ShopCategoryDTO;
|
||||||
|
import com.agileboot.domain.shop.goods.GoodsApplicationService;
|
||||||
|
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/shop")
|
||||||
|
@CrossOrigin(origins = "*", allowedHeaders = "*")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ShopController {
|
||||||
|
private final GoodsApplicationService goodsApplicationService;
|
||||||
|
private final CategoryApplicationService categoryApplicationService;
|
||||||
|
|
||||||
|
@GetMapping("/goods")
|
||||||
|
public ResponseDTO<ShopGoodsResponse> getShopGoodsInfo() {
|
||||||
|
// 获取商品列表
|
||||||
|
List<ShopGoodsEntity> goodsList = goodsApplicationService.getGoodsAll();
|
||||||
|
// 获取分类列表
|
||||||
|
List<ShopCategoryDTO> categoryList = categoryApplicationService.getCategoryAll();
|
||||||
|
|
||||||
|
|
||||||
|
return ResponseDTO.ok(new ShopGoodsResponse(goodsList, categoryList));
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,7 +64,7 @@ public class SecurityConfig {
|
||||||
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 禁用 session
|
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 禁用 session
|
||||||
.and()
|
.and()
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/common/**").permitAll()
|
.antMatchers("/common/**", "/api/**").permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
// 禁用 X-Frame-Options 响应头。下面是具体解释:
|
// 禁用 X-Frame-Options 响应头。下面是具体解释:
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.agileboot.api.response;
|
||||||
|
|
||||||
|
|
||||||
|
import com.agileboot.domain.shop.category.dto.ShopCategoryDTO;
|
||||||
|
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ShopGoodsResponse {
|
||||||
|
private List<ShopGoodsEntity> goodsList;
|
||||||
|
private List<ShopCategoryDTO> categoryList;
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
# 数据源配置
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
druid:
|
||||||
|
webStatFilter:
|
||||||
|
enabled: true
|
||||||
|
statViewServlet:
|
||||||
|
enabled: true
|
||||||
|
# 设置白名单,不填则允许所有访问
|
||||||
|
allow:
|
||||||
|
url-pattern: /druid/*
|
||||||
|
# 控制台管理用户名和密码
|
||||||
|
login-username: agileboot
|
||||||
|
login-password: 123456
|
||||||
|
filter:
|
||||||
|
stat:
|
||||||
|
enabled: true
|
||||||
|
# 慢SQL记录
|
||||||
|
log-slow-sql: true
|
||||||
|
slow-sql-millis: 1000
|
||||||
|
merge-sql: true
|
||||||
|
wall:
|
||||||
|
config:
|
||||||
|
multi-statement-allow: true
|
||||||
|
dynamic:
|
||||||
|
primary: master
|
||||||
|
strict: false
|
||||||
|
druid:
|
||||||
|
# 初始连接数
|
||||||
|
initialSize: 5
|
||||||
|
# 最小连接池数量
|
||||||
|
minIdle: 10
|
||||||
|
# 最大连接池数量
|
||||||
|
maxActive: 20
|
||||||
|
# 配置获取连接等待超时的时间
|
||||||
|
maxWait: 60000
|
||||||
|
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||||
|
timeBetweenEvictionRunsMillis: 60000
|
||||||
|
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||||
|
minEvictableIdleTimeMillis: 300000
|
||||||
|
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
||||||
|
maxEvictableIdleTimeMillis: 900000
|
||||||
|
# 配置检测连接是否有效
|
||||||
|
validationQuery: SELECT 1 FROM DUAL
|
||||||
|
testWhileIdle: true
|
||||||
|
testOnBorrow: false
|
||||||
|
testOnReturn: false
|
||||||
|
datasource:
|
||||||
|
# 主库数据源
|
||||||
|
master:
|
||||||
|
url: jdbc:mysql://localhost:3306/agileboot-pure?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
|
username: root
|
||||||
|
password: ys123456
|
||||||
|
# 从库数据源
|
||||||
|
# slave:
|
||||||
|
# url: jdbc:mysql://localhost:33067/agileboot2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
|
# username: root
|
||||||
|
# password: 12345
|
||||||
|
|
||||||
|
# redis 配置
|
||||||
|
redis:
|
||||||
|
# 地址
|
||||||
|
host: 127.0.0.1
|
||||||
|
# 端口,默认为6379
|
||||||
|
port: 6379
|
||||||
|
# 数据库索引
|
||||||
|
database: 0
|
||||||
|
# 密码
|
||||||
|
# password: 12345
|
||||||
|
# 连接超时时间
|
||||||
|
timeout: 10s
|
||||||
|
lettuce:
|
||||||
|
pool:
|
||||||
|
# 连接池中的最小空闲连接
|
||||||
|
min-idle: 0
|
||||||
|
# 连接池中的最大空闲连接
|
||||||
|
max-idle: 8
|
||||||
|
# 连接池的最大数据库连接数
|
||||||
|
max-active: 8
|
||||||
|
# #连接池最大阻塞等待时间(使用负值表示没有限制)
|
||||||
|
max-wait: -1ms
|
||||||
|
|
||||||
|
logging:
|
||||||
|
file:
|
||||||
|
path: D:/logs/agileboot-dev
|
||||||
|
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
swagger-ui:
|
||||||
|
# ***注意*** 开启Swagger UI界面 **安全考虑的话生产环境需要关掉**
|
||||||
|
# 因为knife4j的一些配置不灵活 所以重新改回springdoc+swagger的组合 真实开发的时候 使用apifox这种工具效率更高
|
||||||
|
enabled: true
|
||||||
|
url: ${agileboot.api-prefix}/v3/api-docs
|
||||||
|
config-url: ${agileboot.api-prefix}/v3/api-docs/swagger-config
|
||||||
|
|
||||||
|
|
||||||
|
# 项目相关配置
|
||||||
|
agileboot:
|
||||||
|
# 文件基路径 示例( Windows配置D:\agileboot,Linux配置 /home/agileboot)
|
||||||
|
file-base-dir: D:\agileboot
|
||||||
|
# 前端url请求转发前缀
|
||||||
|
api-prefix: /dev-api
|
||||||
|
demo-enabled: false
|
|
@ -5,6 +5,7 @@ import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||||
import com.agileboot.domain.shop.goods.command.AddGoodsCommand;
|
import com.agileboot.domain.shop.goods.command.AddGoodsCommand;
|
||||||
import com.agileboot.domain.shop.goods.command.UpdateGoodsCommand;
|
import com.agileboot.domain.shop.goods.command.UpdateGoodsCommand;
|
||||||
import com.agileboot.domain.shop.goods.db.SearchGoodsDO;
|
import com.agileboot.domain.shop.goods.db.SearchGoodsDO;
|
||||||
|
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
|
||||||
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
|
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
|
||||||
import com.agileboot.domain.shop.goods.dto.ShopGoodsDTO;
|
import com.agileboot.domain.shop.goods.dto.ShopGoodsDTO;
|
||||||
import com.agileboot.domain.shop.goods.model.GoodsModel;
|
import com.agileboot.domain.shop.goods.model.GoodsModel;
|
||||||
|
@ -54,4 +55,8 @@ public class GoodsApplicationService {
|
||||||
model.deleteById();
|
model.deleteById();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ShopGoodsEntity> getGoodsAll(){
|
||||||
|
return shopGoodsService.selectAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import java.util.List;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
@ -31,4 +32,14 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
|
||||||
Page<SearchGoodsDO> page,
|
Page<SearchGoodsDO> page,
|
||||||
@Param(Constants.WRAPPER) Wrapper<SearchGoodsDO> queryWrapper
|
@Param(Constants.WRAPPER) Wrapper<SearchGoodsDO> queryWrapper
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有商品(未删除的)
|
||||||
|
* @return 商品列表
|
||||||
|
*/
|
||||||
|
@Select("SELECT * " +
|
||||||
|
"FROM shop_goods " +
|
||||||
|
"WHERE deleted = 0 " +
|
||||||
|
"ORDER BY create_time DESC")
|
||||||
|
List<ShopGoodsEntity> selectAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.agileboot.domain.shop.goods.db;
|
||||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -14,4 +15,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
*/
|
*/
|
||||||
public interface ShopGoodsService extends IService<ShopGoodsEntity> {
|
public interface ShopGoodsService extends IService<ShopGoodsEntity> {
|
||||||
Page<SearchGoodsDO> getGoodsList(AbstractPageQuery<SearchGoodsDO> query);
|
Page<SearchGoodsDO> getGoodsList(AbstractPageQuery<SearchGoodsDO> query);
|
||||||
|
|
||||||
|
List<ShopGoodsEntity> selectAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.agileboot.common.core.page.AbstractPageQuery;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -19,4 +20,9 @@ public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoods
|
||||||
public Page<SearchGoodsDO> getGoodsList(AbstractPageQuery<SearchGoodsDO> query) {
|
public Page<SearchGoodsDO> getGoodsList(AbstractPageQuery<SearchGoodsDO> query) {
|
||||||
return baseMapper.getGoodsList(query.toPage(), query.toQueryWrapper());
|
return baseMapper.getGoodsList(query.toPage(), query.toQueryWrapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ShopGoodsEntity> selectAll() {
|
||||||
|
return baseMapper.selectAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue