Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e2e933bae3
|
@ -8,4 +8,8 @@ auth:
|
|||
- /swagger-ui.html
|
||||
- /swagger-ui/**
|
||||
- /doc.html
|
||||
- /
|
||||
- /
|
||||
- /maku/t_user/login
|
||||
- /maku/t_user/updateUser
|
||||
- /maku/t_user/register
|
||||
- /maku/t_user/logout
|
|
@ -1,6 +1,7 @@
|
|||
package net.maku.maku.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
|
@ -30,6 +31,23 @@ import java.util.List;
|
|||
public class TBookController {
|
||||
private final TBookService tBookService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "列表")
|
||||
public Result<List<TBookEntity>> list() {
|
||||
List<TBookEntity> list = tBookService.list();
|
||||
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
@Operation(summary = "书籍")
|
||||
@Parameter
|
||||
public Result<TBookEntity> getById(@PathVariable Long id){
|
||||
TBookEntity entity = tBookService.getById(id);
|
||||
|
||||
return Result.ok(entity);
|
||||
}
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('maku:t_book:page')")
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package net.maku.maku.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.cache.RedisCache;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.common.utils.Result;
|
||||
import net.maku.maku.convert.TUserConvert;
|
||||
|
@ -10,7 +13,9 @@ 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.*;
|
||||
|
||||
|
@ -18,7 +23,7 @@ import jakarta.validation.Valid;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* @since 1.0.0 2024-07-16
|
||||
|
@ -29,6 +34,55 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class TUserController {
|
||||
private final TUserService tUserService;
|
||||
private final RedisCache redisCache;
|
||||
|
||||
@PostMapping("/register")
|
||||
@Operation(summary = "注册")
|
||||
public ResponseEntity<Result<String>> register(@RequestBody TUserEntity entity) {
|
||||
TUserEntity existingUser = tUserService.login(entity);
|
||||
if (existingUser != null) {
|
||||
return ResponseEntity.badRequest().body(Result.error("用户名已存在"));
|
||||
} else {
|
||||
tUserService.save(entity);
|
||||
return ResponseEntity.ok(Result.ok("注册成功"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
@Operation(summary = "登录")
|
||||
public Result login(@RequestBody TUserEntity entity){
|
||||
TUserEntity entity1 = tUserService.login(entity);
|
||||
if(ObjectUtils.isNotNull(entity1)){
|
||||
return Result.ok(entity1);
|
||||
}else {
|
||||
return Result.error("登录失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/updateUser")
|
||||
@Operation(summary = "修改")
|
||||
public Result<TUserVO> updateUser(@RequestBody TUserVO vo){
|
||||
TUserVO tUserVO = tUserService.updateUser(vo);
|
||||
|
||||
return Result.ok(tUserVO);
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
@Operation(summary = "退出登录")
|
||||
public Result<String> logout(HttpServletRequest request) {
|
||||
String token = request.getHeader("token");
|
||||
if (token == null) {
|
||||
return Result.error("token为空");
|
||||
}
|
||||
Object o = redisCache.get(token);
|
||||
if (o != null) {
|
||||
redisCache.delete(token);
|
||||
return Result.ok("退出登录");
|
||||
}
|
||||
return Result.error("登录失败");
|
||||
}
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
|
@ -74,4 +128,6 @@ public class TUserController {
|
|||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package net.maku.maku.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
|
|
@ -23,4 +23,5 @@ public interface TBookService extends BaseService<TBookEntity> {
|
|||
void update(TBookVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
}
|
|
@ -23,4 +23,9 @@ public interface TUserService extends BaseService<TUserEntity> {
|
|||
void update(TUserVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
TUserEntity login(TUserEntity entity);
|
||||
|
||||
TUserVO updateUser(TUserVO vo);
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package net.maku.maku.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -37,8 +38,7 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
|
|||
|
||||
private LambdaQueryWrapper<TUserEntity> getWrapper(TUserQuery query){
|
||||
LambdaQueryWrapper<TUserEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.like(TUserEntity::getUsername, query.getUsername());
|
||||
wrapper.eq(ObjectUtil.isNotNull(query.getStatus()), TUserEntity::getStatus, query.getStatus());
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
@ -62,4 +62,28 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
|
|||
removeByIds(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TUserEntity login(TUserEntity entity) {
|
||||
LambdaQueryWrapper<TUserEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(TUserEntity::getUsername, entity.getUsername());
|
||||
wrapper.eq(TUserEntity::getPassword, entity.getPassword());
|
||||
TUserEntity one = getOne(wrapper);
|
||||
if(ObjectUtils.isNotNull(one)) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
one.setAvatar(uuid.toString());
|
||||
updateById(one);
|
||||
return one;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TUserVO updateUser(TUserVO vo) {
|
||||
TUserEntity entity = new TUserEntity();
|
||||
entity.setUsername(vo.getUsername());
|
||||
entity.setPassword(vo.getPassword());
|
||||
updateById(entity);
|
||||
return vo;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ spring:
|
|||
database: 0
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
# password: wxbc5b16589b8f183e
|
||||
password: 123456
|
||||
#timeout: 6000ms # 连接超时时长(毫秒)
|
||||
datasource:
|
||||
dynamic:
|
||||
|
|
Loading…
Reference in New Issue
Block a user