添加购物车模块接口

This commit is contained in:
muhua 2024-07-12 16:58:27 +08:00
parent 5a91236106
commit f680ec4ec8
16 changed files with 215 additions and 62 deletions

View File

@ -0,0 +1,33 @@
package com.example.takeawaysystemserver.controller;
import com.example.takeawaysystemserver.entity.Dish;
import com.example.takeawaysystemserver.service.DishService;
import com.example.takeawaysystemserver.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author Ethereal
* @date 2024/7/12
* @description
*/
@RestController
@Api(tags = "菜品模块")
@RequestMapping("dish")
public class DishController {
@Resource
private DishService dishService;
@GetMapping("get-dish-info")
@ApiOperation(value = "获取菜品信息")
public R<List<Dish>> getDishes(){
return dishService.getDishes();
}
}

View File

@ -0,0 +1,42 @@
package com.example.takeawaysystemserver.controller;
import com.example.takeawaysystemserver.entity.Dish;
import com.example.takeawaysystemserver.entity.Shop;
import com.example.takeawaysystemserver.service.ShopService;
import com.example.takeawaysystemserver.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author Ethereal
* @date 2024/7/12
* @description
*/
@RestController
@RequestMapping("shop")
@Api(tags = "商家模块")
public class ShopController {
@Resource
private ShopService shopService;
@GetMapping("get-all-shop")
@ApiOperation(value = "获取所有商家的菜品信息")
public R<List<Shop>> getAllShop(){
return shopService.getAllShop();
}
@GetMapping("get-shop-dishes")
@ApiOperation(value = "获取某个商家的所有菜品信息(包括口味)")
public R<List<Dish>> getAllDishes(@RequestParam("id") Integer id){
return shopService.getShopDishes(id);
}
}

View File

@ -0,0 +1,43 @@
package com.example.takeawaysystemserver.controller;
import com.example.takeawaysystemserver.entity.ShoppingCart;
import com.example.takeawaysystemserver.service.ShoppingCartService;
import com.example.takeawaysystemserver.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Ethereal
* @date 2024/7/12
* @description
*/
@RestController
@RequestMapping("shopping-cart")
@Api(tags = "购物车")
public class ShoppingCartController {
@Resource
private ShoppingCartService shoppingCartService;
@PostMapping("add-shopping-cart")
@ApiOperation(value = "添加到购物车")
public R<String> add(@RequestHeader String token, @RequestBody ShoppingCart shoppingCart){
return shoppingCartService.addShoppingCart(token, shoppingCart);
}
@GetMapping("search-carts")
@ApiOperation(value = "查询购物车")
public R<List<ShoppingCart>> getLists(@RequestHeader String token){
return shoppingCartService.getShoppingCarts(token);
}
@PostMapping("delete-shopping-cart")
@ApiOperation(value = "删除购物车选项")
public R<String> delete(@RequestHeader String token, @RequestBody ShoppingCart shoppingCart){
return shoppingCartService.deleteShoppingCart(token, shoppingCart);
}
}

View File

@ -1,9 +1,11 @@
package com.example.takeawaysystemserver.entity;
import java.io.Serializable;
import java.util.List;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import jakarta.annotation.Nullable;
import lombok.Data;
/**
@ -48,6 +50,12 @@ public class Dish implements Serializable {
*/
private String image;
/**
* 菜品口味
*/
@Nullable
private List<DishFlavor> dishFlavors;
private static final long serialVersionUID = 1L;
@Override

View File

@ -36,12 +36,12 @@ public class DishFlavor implements Serializable {
/**
* 创建时间
*/
private Long createTime;
private Integer createTime;
/**
* 更新时间
*/
private Long updateTime;
private Integer updateTime;
/**
* 是否删除1删除0未删除

View File

@ -46,12 +46,12 @@ public class Order implements Serializable {
/**
* 创建时间
*/
private Long createTime;
private Integer createTime;
/**
* 更新时间
*/
private Long updateTime;
private Integer updateTime;
private static final long serialVersionUID = 1L;

View File

@ -42,12 +42,12 @@ public class Shop implements Serializable {
/**
* 开业时间
*/
private String openTime;
private Integer openTime;
/**
* 休息时间
*/
private String closeTime;
private Integer closeTime;
/**
* 店铺地址

View File

@ -1,8 +1,13 @@
package com.example.takeawaysystemserver.mapper;
import com.example.takeawaysystemserver.entity.Dish;
import com.example.takeawaysystemserver.entity.DishFlavor;
import com.example.takeawaysystemserver.entity.Shop;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author qiushengyu
@ -13,6 +18,20 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ShopMapper extends BaseMapper<Shop> {
/**
* 获取某个店铺的所有菜品
* @param id 店铺ID
* @return 菜品列表
*/
List<Dish> getShopDishes(@Param("id") Integer id);
/**
* 获取菜品的口味
* @param id 菜品ID
* @return 菜品口味
*/
List<DishFlavor> flavors(@Param("id") Integer id);
}

View File

@ -1,24 +0,0 @@
package com.example.takeawaysystemserver.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author spyn
* @date 2024/7/10
* @description
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ShoppingCart {
// 不需要用户ID用户信息从token中获取
private Integer shopId;
/**
* 订单子项
*/
private ShoppingCartItem[] dishes;
// 用户地址用户可能会修改地址故以该字段为准
private String address;
}

View File

@ -1,29 +0,0 @@
package com.example.takeawaysystemserver.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
/**
* @author spyn
* @date 2024/7/10
* @description
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ShoppingCartItem {
private Integer dishId;
/**
* 份数
*/
private Integer count;
/**
* 子选项
* [key: 类型辣度选择] : [value: 子选项"微辣"]
* 注意这里value是String而不是String[]和Dish中的subOptions不同
*/
private Map<String, String> subOptions;
}

View File

@ -2,6 +2,9 @@ package com.example.takeawaysystemserver.service;
import com.example.takeawaysystemserver.entity.Dish;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.takeawaysystemserver.util.R;
import java.util.List;
/**
* @author qiushengyu
@ -10,4 +13,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface DishService extends IService<Dish> {
/**
* 获取菜品信息
* @return 所有菜品信息
*/
R<List<Dish>> getDishes();
}

View File

@ -1,7 +1,11 @@
package com.example.takeawaysystemserver.service;
import com.example.takeawaysystemserver.entity.Shop;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.takeawaysystemserver.entity.Dish;
import com.example.takeawaysystemserver.entity.Shop;
import com.example.takeawaysystemserver.util.R;
import java.util.List;
/**
* @author qiushengyu
@ -9,5 +13,16 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @createDate 2024-07-11 17:13:56
*/
public interface ShopService extends IService<Shop> {
/**
* 获取所有商家信息
* @return 所有商家的list
*/
R<List<Shop>> getAllShop();
/**
* 获取商家的菜品信息
* @param id 商家id
* @return 菜品信息
*/
R<List<Dish>> getShopDishes(Integer id);
}

View File

@ -1,11 +1,15 @@
package com.example.takeawaysystemserver.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.takeawaysystemserver.entity.Dish;
import com.example.takeawaysystemserver.service.DishService;
import com.example.takeawaysystemserver.mapper.DishMapper;
import com.example.takeawaysystemserver.util.R;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author qiushengyu
* @description 针对表dish的数据库操作Service实现
@ -15,6 +19,11 @@ import org.springframework.stereotype.Service;
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish>
implements DishService{
@Override
public R<List<Dish>> getDishes() {
LambdaQueryWrapper<Dish> wrapper = new LambdaQueryWrapper<Dish>();
return R.ok(list(wrapper));
}
}

View File

@ -1,11 +1,17 @@
package com.example.takeawaysystemserver.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.takeawaysystemserver.entity.Dish;
import com.example.takeawaysystemserver.entity.DishFlavor;
import com.example.takeawaysystemserver.entity.Shop;
import com.example.takeawaysystemserver.service.ShopService;
import com.example.takeawaysystemserver.mapper.ShopMapper;
import com.example.takeawaysystemserver.service.ShopService;
import com.example.takeawaysystemserver.util.R;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author qiushengyu
* @description 针对表shop的数据库操作Service实现
@ -15,6 +21,21 @@ import org.springframework.stereotype.Service;
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop>
implements ShopService{
@Override
public R<List<Shop>> getAllShop() {
LambdaQueryWrapper<Shop> wrapper = new LambdaQueryWrapper<Shop>();
return R.ok(list(wrapper));
}
@Override
public R<List<Dish>> getShopDishes(Integer id) {
List<Dish> dishes = baseMapper.getShopDishes(id);
for (Dish dish: dishes) {
List<DishFlavor> dishFlavors = baseMapper.flavors(dish.getId());
dish.setDishFlavors(dishFlavors);
}
return R.ok(dishes);
}
}

View File

@ -132,7 +132,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
return Objects.nonNull(user);
}
private String getUserId(String token){
public String getUserId(String token){
Map<String, Claim> map = JwtUtil.getPayload(token);
return map.get("id").toString().replaceAll("\"", "");
}

View File

@ -21,4 +21,11 @@
sell_count,status,open_time,
close_time,address,image
</sql>
<update id="flavors">
select * from dish_flavor where dish_id = #{id}
</update>
<select id="getShopDishes" resultType="com.example.takeawaysystemserver.entity.Dish">
select * from dish where shop_id = #{id}
</select>
</mapper>