feat:更新用户接口
This commit is contained in:
0
logs/food-hub-service/log_error.log
Normal file
0
logs/food-hub-service/log_error.log
Normal file
27
logs/food-hub-service/log_info.log
Normal file
27
logs/food-hub-service/log_info.log
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
2025-06-28 14:39:50 |INFO |background-preinit |Version.java:21 |org.hibernate.validator.internal.util.Version |HV000001: Hibernate Validator 8.0.2.Final
|
||||||
|
2025-06-28 14:39:50 |INFO |main |StartupInfoLogger.java:53 |com.cxx.food.FoodHubServiceApplication |Starting FoodHubServiceApplication v0.0.1 using Java 17.0.12 with PID 18968 (D:\Cxx\GitHubProjects\food-hub-service\target\classes started by chenxiuxiang in D:\Cxx\GitHubProjects\food-hub-service)
|
||||||
|
2025-06-28 14:39:50 |INFO |main |SpringApplication.java:658 |com.cxx.food.FoodHubServiceApplication |The following 1 profile is active: "prod"
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.dao.FoodDao
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/FoodDao.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.dao.MomentDao
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/MomentDao.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.CommentMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/CommentMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.FileRecordMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/FileRecordMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.LikeMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/LikeMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.MaterialMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/MaterialMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.MomentImageMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/MomentImageMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.MomentMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/MomentMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.RecipeMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/RecipeMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.RecordMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/RecordMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.StepMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/StepMapper.xml
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:204 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper interface: com.cxx.food.mapper.UserMapper
|
||||||
|
2025-06-28 14:39:53 |INFO |main |MyBatisNativeConfiguration.java:210 |com.cxx.autoconfigure.data.MyBatisNativeConfiguration$MyBatisBeanFactoryInitializationAotProcessor |Registering MyBatis mapper xml: mapper/UserMapper.xml
|
||||||
0
logs/food-hub-service/log_warn.log
Normal file
0
logs/food-hub-service/log_warn.log
Normal file
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonView;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -21,7 +22,21 @@ public class UserController {
|
|||||||
@Operation(summary = "注册用户")
|
@Operation(summary = "注册用户")
|
||||||
@PostMapping("")
|
@PostMapping("")
|
||||||
@SaIgnore
|
@SaIgnore
|
||||||
public Boolean createSession(@JsonView(WriteView.class) @RequestBody UserDto userDto) {
|
public Boolean registerUser(@RequestParam("username") String username,
|
||||||
return userService.register(userDto);
|
@RequestParam("password") String password) {
|
||||||
|
return userService.register(username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "查询用户")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public @JsonView(ReadView.class) UserDto queryUser(@PathVariable("id") Long id) {
|
||||||
|
return userService.queryUser(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "更新用户")
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public Boolean updateUser(@PathVariable("id") Long id,
|
||||||
|
@JsonView(WriteView.class) @Validated @RequestBody UserDto userDto) {
|
||||||
|
return userService.updateUser(id, userDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,52 +22,34 @@ public class UserDto {
|
|||||||
@NotBlank(message = "用户名称不能为空")
|
@NotBlank(message = "用户名称不能为空")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Schema(description = "密码")
|
@Schema(description = "性别")
|
||||||
@NotBlank(message = "密码不能为空")
|
private Integer gender;
|
||||||
@JsonView(WriteView.class)
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
// @Schema(description = "性别")
|
@Schema(description = "手机号码")
|
||||||
// @JsonView(ReadView.class)
|
private String phoneNumber;
|
||||||
// private Integer gender;
|
|
||||||
//
|
@Schema(description = "电子邮件")
|
||||||
// @Schema(description = "身份证号")
|
private String email;
|
||||||
// @JsonView(ReadView.class)
|
|
||||||
// private String idNumber;
|
@Schema(description = "生日")
|
||||||
//
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
// @Schema(description = "手机号码")
|
private Date birthDate;
|
||||||
// @JsonView(ReadView.class)
|
|
||||||
// private String phoneNumber;
|
|
||||||
//
|
|
||||||
// @Schema(description = "电子邮件")
|
|
||||||
// @JsonView(ReadView.class)
|
|
||||||
// private String email;
|
|
||||||
//
|
|
||||||
// @Schema(description = "生日")
|
|
||||||
// @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
|
||||||
// private Date birthDate;
|
|
||||||
|
|
||||||
@Schema(description = "头像")
|
@Schema(description = "头像")
|
||||||
@JsonView(ReadView.class)
|
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
// @Schema(description = "地区")
|
@Schema(description = "地区")
|
||||||
// @JsonView(ReadView.class)
|
private List<String> area;
|
||||||
// private List<String> area;
|
|
||||||
//
|
@Schema(description = "地址")
|
||||||
// @Schema(description = "地址")
|
private String address;
|
||||||
// @JsonView(ReadView.class)
|
|
||||||
// private String address;
|
@Schema(description = "职业")
|
||||||
//
|
private String job;
|
||||||
// @Schema(description = "职业")
|
|
||||||
// @JsonView(ReadView.class)
|
@Schema(description = "标签")
|
||||||
// private String job;
|
private List<String> tags;
|
||||||
//
|
|
||||||
// @Schema(description = "标签")
|
@Schema(description = "描述")
|
||||||
// @JsonView(ReadView.class)
|
private String description;
|
||||||
// private List<String> tags;
|
|
||||||
//
|
|
||||||
// @Schema(description = "描述")
|
|
||||||
// @JsonView(ReadView.class)
|
|
||||||
// private String description;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ package com.cxx.food.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
import com.cxx.framework.data.AbstractEntity;
|
import com.cxx.framework.data.AbstractEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@TableName("user")
|
@TableName("user")
|
||||||
@@ -13,9 +17,36 @@ public class User extends AbstractEntity {
|
|||||||
@TableField("username")
|
@TableField("username")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
@TableField("gender")
|
||||||
|
private Integer gender;
|
||||||
|
|
||||||
@TableField("password")
|
@TableField("password")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@TableField("phone_number")
|
||||||
|
private String phoneNumber;
|
||||||
|
|
||||||
|
@TableField("email")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@TableField("birth_date")
|
||||||
|
private Date birthDate;
|
||||||
|
|
||||||
@TableField("avatar")
|
@TableField("avatar")
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
|
@TableField(value = "area", typeHandler = JacksonTypeHandler.class)
|
||||||
|
private List<String> area;
|
||||||
|
|
||||||
|
@TableField("address")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@TableField("job")
|
||||||
|
private String job;
|
||||||
|
|
||||||
|
@TableField(value = "tags", typeHandler = JacksonTypeHandler.class)
|
||||||
|
private List<String> tags;
|
||||||
|
|
||||||
|
@TableField("description")
|
||||||
|
private String description;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.cxx.food.service;
|
package com.cxx.food.service;
|
||||||
|
|
||||||
|
|
||||||
import com.cxx.food.dto.SessionDto;
|
|
||||||
import com.cxx.food.dto.UserDto;
|
import com.cxx.food.dto.UserDto;
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
Boolean register(UserDto userDto);
|
Boolean register(String username, String password);
|
||||||
|
|
||||||
|
|
||||||
|
UserDto queryUser(Long id);
|
||||||
|
|
||||||
|
Boolean updateUser(Long id, UserDto userDto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,16 +19,46 @@ public class UserServiceImpl implements UserService {
|
|||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean register(UserDto userDto) {
|
public Boolean register(String username, String password) {
|
||||||
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
if (userMapper.exists(queryWrapper.eq(User::getUsername, userDto.getUsername()))) {
|
if (userMapper.exists(queryWrapper.eq(User::getUsername, username))) {
|
||||||
throw new CustomException("该用户已注册");
|
throw new CustomException("该用户已注册");
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
BeanUtils.copyProperties(userDto, user);
|
user.setUsername(username);
|
||||||
user.setPassword(BCrypt.hashpw(userDto.getPassword(), BCrypt.gensalt()));
|
user.setPassword(BCrypt.hashpw(password, BCrypt.gensalt()));
|
||||||
|
|
||||||
return userMapper.insert(user) == 1;
|
return userMapper.insert(user) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDto queryUser(Long id) {
|
||||||
|
User user = userMapper.selectById(id);
|
||||||
|
if (user == null) {
|
||||||
|
throw new CustomException("未查询到该用户");
|
||||||
|
}
|
||||||
|
|
||||||
|
UserDto userDto = new UserDto();
|
||||||
|
BeanUtils.copyProperties(user, userDto);
|
||||||
|
return userDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateUser(Long id, UserDto userDto) {
|
||||||
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (!userMapper.exists(queryWrapper.eq(User::getId, id))) {
|
||||||
|
throw new CustomException("该用户不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
queryWrapper.clear();
|
||||||
|
if (userMapper.exists(queryWrapper.eq(User::getUsername, userDto.getUsername()).ne(User::getId, id))) {
|
||||||
|
throw new CustomException("该用户已经存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
BeanUtils.copyProperties(userDto, user);
|
||||||
|
user.setId(id);
|
||||||
|
return userMapper.updateById(user) == 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user