Skip to content

Commit

Permalink
feat: Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanzhi33 committed Jul 20, 2024
1 parent 6fa9e3e commit 5af36c8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public Result<Integer> insertData(@Valid @RequestBody SensorDataDTO sensorDataDT
return Result.success(lines);
}

@DeleteMapping("/delete/{id}")
public Result<Integer> deleteData(@PathVariable int id) {
return Result.success(dataService.deleteData(id));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public Result<String> handleException(Exception e) {
return Result.serverError(e.getMessage());
public ResponseEntity<Result<String>> handleException(Exception e) {
return new ResponseEntity<>(Result.serverError(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(NoResourceFoundException.class)
public ResponseEntity<Result<String>> handleNoResourceFoundException(NoResourceFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +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;
Expand All @@ -21,4 +22,7 @@ public interface SensorDataMapper {

@Insert("insert into sensor_data(user, data) values(#{user}, #{data})")
int insertData(SensorData sensorData);

@Delete("delete from sensor_data where id = #{id}")
int deleteData(int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@

public interface SensorDataService {
PagedSensorDataVO getPagedData(int page, int pageSize);
int insertData(SensorData sensorData);
Integer insertData(SensorData sensorData);

Integer deleteData(int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public PagedSensorDataVO getPagedData(int page, int pageSize) {
}

@Override
public int insertData(SensorData sensorData) {
public Integer insertData(SensorData sensorData) {
return dataMapper.insertData(sensorData);
}

@Override
public Integer deleteData(int id) {
return dataMapper.deleteData(id);
}
}

0 comments on commit 5af36c8

Please sign in to comment.