Skip to content

Commit

Permalink
feat: Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanzhi33 committed Jul 20, 2024
1 parent 79b8122 commit 9ae1fa0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ public Result<Integer> deleteData(@PathVariable int id) {
return Result.success(dataService.deleteData(id));
}

@PutMapping("/rename")
public Result<Integer> renameData(@Valid @RequestBody RenameDTO renameDTO) {
int id = renameDTO.getId();
String newName = renameDTO.getNewName();
return Result.success(dataService.renameData(id, newName));
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cn.xuanzhi33.carprojectserver.mapper;

import cn.xuanzhi33.carprojectserver.pojo.SensorData;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.*;

import java.util.List;

Expand All @@ -25,4 +22,7 @@ public interface SensorDataMapper {

@Delete("delete from sensor_data where id = #{id}")
int deleteData(int id);

@Update("update sensor_data set user = #{newName} where id = #{id}")
int renameData(int id, String newName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cn.xuanzhi33.carprojectserver.pojo;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Size;
import lombok.Data;

@Data
public class RenameDTO {
@Min(value = 1, message = "id should be greater than 0")
private int id;
@Size(min = 1, max = 30, message = "newName should be between 1 and 30 characters")
private String newName;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cn.xuanzhi33.carprojectserver.pojo;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class SensorDataDTO {
@NotEmpty(message = "user should not be empty")
@Size(min = 1, max = 30, message = "user should be between 1 and 30 characters")
private String user;
@NotEmpty(message = "data should not be empty")
private String data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface SensorDataService {
Integer insertData(SensorData sensorData);

Integer deleteData(int id);

Integer renameData(int id, String newName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public Integer insertData(SensorData sensorData) {
public Integer deleteData(int id) {
return dataMapper.deleteData(id);
}

@Override
public Integer renameData(int id, String newName) {
return dataMapper.renameData(id, newName);
}
}

0 comments on commit 9ae1fa0

Please sign in to comment.