Merge remote-tracking branch 'origin/master'

# Conflicts:
#	maku-framework/src/main/resources/auth.yml
#	maku-server/src/main/java/net/maku/maku/controller/TBookController.java
This commit is contained in:
hxf13 2024-07-18 17:46:55 +08:00
commit 3221c3bcc9
5 changed files with 22 additions and 28 deletions

View File

@ -38,26 +38,7 @@ import java.util.List;
public class TBookCommentController {
private final TBookCommentService tBookCommentService;
private final RedisCache redisCache;
@PostMapping("/comment")
public Result setshoppingtrolly(HttpServletRequest request, @RequestBody TBookCommentVO vo) {
// 首先验证token的有效性然后从Redis中获取用户信息
String token = request.getHeader("token");
if(token==null || token.isEmpty()){
return Result.error("token is error");
}
TUserEntity tUserEntity = (TUserEntity) redisCache.get(token);
Integer userId=tUserEntity.getId();
LocalDateTime currentTime = LocalDateTime.now();
ZoneId zoneId = ZoneId.systemDefault();
//DATE没有时区二localDateTime有时区,为了将 LocalDateTime 转换为 Date你需要指定一个时区因为 Date 是基于UTC的
// 将LocalDateTime转换为ZonedDateTime然后转换为Instant最后转换为Date
// ZonedDateTime zdt = currentTime.atZone(zoneId);
// Date date = Date.from(zdt.toInstant());
// tBookCollectionService.save(userId,bookId,date);
return Result.ok("加入购物车成功");
}
@GetMapping("page")
@Operation(summary = "分页")
@ -77,12 +58,11 @@ public class TBookCommentController {
return Result.ok(TBookCommentConvert.INSTANCE.convert(entity));
}
@PostMapping
@PostMapping("/comment")
@Operation(summary = "保存")
@PreAuthorize("hasAuthority('maku:t_book_comment:save')")
public Result<String> save(@RequestBody TBookCommentVO vo){
tBookCommentService.save(vo);
return Result.ok();
}

View File

@ -1,5 +1,7 @@
package net.maku.maku.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -13,13 +15,14 @@ import net.maku.maku.entity.TUserEntity;
import net.maku.maku.service.TUserService;
import net.maku.maku.query.TUserQuery;
import net.maku.maku.vo.TUserVO;
import oracle.jdbc.proxy.annotation.Post;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
@ -37,6 +40,7 @@ public class TUserController {
private final TUserService tUserService;
private final RedisCache redisCache;
@PostMapping("/register")
@Operation(summary = "注册")
public ResponseEntity<Result<String>> register(@RequestBody TUserEntity entity) {
@ -56,7 +60,7 @@ public class TUserController {
TUserEntity entity1 = tUserService.login(entity);
if(ObjectUtils.isNotNull(entity1)){
String token = UUID.randomUUID()+"";
redisCache.set(token,entity1);
redisCache.set(token, entity1);
return Result.ok(token);
}else {
return Result.error("登录失败");
@ -64,7 +68,7 @@ public class TUserController {
}
@GetMapping("/updateUser")
@PutMapping("/updateUser")
@Operation(summary = "修改")
public Result<TUserVO> updateUser(@RequestBody TUserVO vo){
TUserVO tUserVO = tUserService.updateUser(vo);
@ -72,6 +76,15 @@ public class TUserController {
return Result.ok(tUserVO);
}
@GetMapping("/info")
@Operation(summary = "用户中心")
public Result findByUsername(HttpServletRequest request){
String token = request.getHeader("token");
TUserEntity entity = (TUserEntity) redisCache.get(token);
return Result.ok(entity);
}
@PostMapping("/logout")
@Operation(summary = "退出登录")
public Result<String> logout(HttpServletRequest request) {
@ -81,7 +94,7 @@ public class TUserController {
redisCache.delete(token);
return Result.ok("退出登录");
}
return Result.error("失败");
return Result.error("失败");
}
@GetMapping("page")

View File

@ -24,5 +24,5 @@ public interface TBookService extends BaseService<TBookEntity> {
void delete(List<Long> idList);
TBookEntity getByName(String name);
TBookEntity getByName(String bookName);
}

View File

@ -62,9 +62,9 @@ public class TBookServiceImpl extends BaseServiceImpl<TBookDao, TBookEntity> imp
}
@Override
public TBookEntity getByName(String name) {
public TBookEntity getByName(String bookName) {
LambdaQueryWrapper<TBookEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(TBookEntity::getBookName, name);
wrapper.eq(TBookEntity::getBookName, bookName);
return baseMapper.selectOne(wrapper);
}

View File

@ -78,6 +78,7 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
@Override
public TUserVO updateUser(TUserVO vo) {
TUserEntity entity = new TUserEntity();
entity.setId(vo.getId());
entity.setUsername(vo.getUsername());
entity.setPassword(vo.getPassword());
updateById(entity);