add: 目标crud
This commit is contained in:
64
src/main/java/com/dota/nexus/controller/GoalController.java
Normal file
64
src/main/java/com/dota/nexus/controller/GoalController.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package com.dota.nexus.controller;
|
||||
|
||||
import com.dota.nexus.entity.Goal;
|
||||
import com.dota.nexus.entity.R;
|
||||
import com.dota.nexus.service.GoalService;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("goal")
|
||||
public class GoalController {
|
||||
GoalService goalService;
|
||||
|
||||
public GoalController(GoalService goalService) {
|
||||
this.goalService = goalService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增目标
|
||||
*/
|
||||
@GetMapping
|
||||
public R addGoal(Goal goal) {
|
||||
goalService.save(goal);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除目标
|
||||
*/
|
||||
@DeleteMapping
|
||||
public R deleteGoal(Integer id) {
|
||||
goalService.removeById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成目标
|
||||
*/
|
||||
@PostMapping("done")
|
||||
public R doneGoal(Integer id) {
|
||||
goalService.doneGoal(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标进行中
|
||||
*/
|
||||
@PostMapping("doing")
|
||||
public R doingGoal(Integer id) {
|
||||
goalService.doingGoal(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消目标
|
||||
*/
|
||||
@PostMapping("cancel")
|
||||
public R cancelGoal(Integer id) {
|
||||
goalService.cancelGoal(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
@@ -1,15 +1,16 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Entity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
Integer id;
|
||||
|
||||
Integer status;
|
||||
|
||||
LocalDateTime createTime;
|
||||
|
||||
LocalDateTime updateTime;
|
||||
|
@@ -6,6 +6,8 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class Goal extends Entity {
|
||||
private GoalEnum status;
|
||||
|
||||
private String name;
|
||||
|
||||
private String tag;
|
||||
|
16
src/main/java/com/dota/nexus/entity/GoalEnum.java
Normal file
16
src/main/java/com/dota/nexus/entity/GoalEnum.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum GoalEnum {
|
||||
DOING("进行中"),
|
||||
DONE("完成"),
|
||||
CANCEL("已取消");
|
||||
|
||||
private final String value;
|
||||
|
||||
GoalEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
22
src/main/java/com/dota/nexus/entity/R.java
Normal file
22
src/main/java/com/dota/nexus/entity/R.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class R {
|
||||
private Integer code;
|
||||
private String msg;
|
||||
private Object data;
|
||||
|
||||
public static R ok() {
|
||||
return ok(null);
|
||||
}
|
||||
|
||||
public static R ok(Object data) {
|
||||
var r = new R();
|
||||
r.setCode(200);
|
||||
r.setMsg("ok");
|
||||
r.setData(data);
|
||||
return r;
|
||||
}
|
||||
}
|
@@ -4,4 +4,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.dota.nexus.entity.Goal;
|
||||
|
||||
public interface GoalService extends IService<Goal> {
|
||||
void doneGoal(Integer id);
|
||||
|
||||
void doingGoal(Integer id);
|
||||
|
||||
void cancelGoal(Integer id);
|
||||
}
|
||||
|
@@ -1,10 +1,35 @@
|
||||
package com.dota.nexus.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.dota.nexus.entity.Goal;
|
||||
import com.dota.nexus.entity.GoalEnum;
|
||||
import com.dota.nexus.mapper.GoalMapper;
|
||||
import com.dota.nexus.service.GoalService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class GoalServiceImpl extends ServiceImpl<GoalMapper, Goal> implements GoalService {
|
||||
|
||||
@Override
|
||||
public void doneGoal(Integer id) {
|
||||
updateStatus(id, GoalEnum.DONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doingGoal(Integer id) {
|
||||
updateStatus(id, GoalEnum.DOING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelGoal(Integer id) {
|
||||
updateStatus(id, GoalEnum.CANCEL);
|
||||
}
|
||||
|
||||
private void updateStatus(Integer id, GoalEnum status) {
|
||||
var update = new LambdaUpdateWrapper<Goal>();
|
||||
update.eq(Goal::getId, id);
|
||||
update.set(Goal::getStatus, status);
|
||||
this.baseMapper.update(update);
|
||||
}
|
||||
}
|
@@ -1,10 +1,9 @@
|
||||
package com.dota.nexus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.dota.nexus.entity.Goal;
|
||||
import com.dota.nexus.entity.GoalEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -21,7 +20,7 @@ public class GoalMapperTest {
|
||||
@Test
|
||||
public void testInsert() {
|
||||
var g = new Goal();
|
||||
g.setStatus(1);
|
||||
g.setStatus(GoalEnum.DONE);
|
||||
g.setCreateTime(LocalDateTime.now());
|
||||
g.setTag("test");
|
||||
g.setName("测试");
|
||||
|
Reference in New Issue
Block a user