add: 周年纪念日
This commit is contained in:
@@ -25,4 +25,17 @@ create table habit_record
|
||||
update_time datetime null,
|
||||
goal_id int unsigned not null
|
||||
)
|
||||
comment '习惯记录表';
|
||||
comment '习惯记录表';
|
||||
|
||||
drop table if exists `anniversary`
|
||||
|
||||
create table `anniversary`
|
||||
(
|
||||
id int unsigned auto_increment,
|
||||
create_time datetime null,
|
||||
update_time datetime null,
|
||||
date date not null comment '重要的日期',
|
||||
type enum ('anniversary', 'commemoration') default 'anniversary' not null
|
||||
)
|
||||
comment '周年纪念日';
|
||||
|
||||
|
@@ -0,0 +1,34 @@
|
||||
package com.dota.nexus.controller;
|
||||
|
||||
import com.dota.nexus.entity.Anniversary;
|
||||
import com.dota.nexus.entity.R;
|
||||
import com.dota.nexus.service.AnniversaryService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("anniversary")
|
||||
public class AnniversaryController {
|
||||
AnniversaryService anniversaryService;
|
||||
|
||||
public AnniversaryController(AnniversaryService anniversaryService) {
|
||||
this.anniversaryService = anniversaryService;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public R add(Anniversary anniversary) {
|
||||
anniversaryService.save(anniversary);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public R del(Integer id) {
|
||||
anniversaryService.removeById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public R update(Anniversary anniversary) {
|
||||
anniversaryService.saveOrUpdate(anniversary);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
@@ -3,12 +3,10 @@ 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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController("goal")
|
||||
@RestController
|
||||
@RequestMapping("goal")
|
||||
public class GoalController {
|
||||
GoalService goalService;
|
||||
|
||||
@@ -19,7 +17,7 @@ public class GoalController {
|
||||
/**
|
||||
* 新增目标
|
||||
*/
|
||||
@GetMapping
|
||||
@PostMapping
|
||||
public R addGoal(Goal goal) {
|
||||
goalService.save(goal);
|
||||
return R.ok();
|
||||
|
@@ -5,11 +5,13 @@ import com.dota.nexus.entity.R;
|
||||
import com.dota.nexus.service.HabitRecordService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@RestController("habit_record")
|
||||
@RestController
|
||||
@RequestMapping("habit")
|
||||
public class HabitRecordController {
|
||||
HabitRecordService habitRecordService;
|
||||
|
||||
@@ -25,7 +27,7 @@ public class HabitRecordController {
|
||||
return R.ok(habitRecordService.getHabitRecordsByGoalId(id));
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
@PostMapping
|
||||
public R addHabitRecord(Integer id) {
|
||||
var habit = new HabitRecord();
|
||||
habit.setCreateTime(LocalDateTime.now());
|
||||
|
14
src/main/java/com/dota/nexus/entity/Anniversary.java
Normal file
14
src/main/java/com/dota/nexus/entity/Anniversary.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Anniversary extends Entity{
|
||||
private LocalDate date;
|
||||
|
||||
private type;
|
||||
}
|
15
src/main/java/com/dota/nexus/entity/AnniversaryEnum.java
Normal file
15
src/main/java/com/dota/nexus/entity/AnniversaryEnum.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum AnniversaryEnum {
|
||||
ANNIVERSARY("周年日"),
|
||||
COMMEMORATION("纪念日");
|
||||
|
||||
private String value;
|
||||
|
||||
AnniversaryEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@@ -8,15 +8,34 @@ public class R {
|
||||
private String msg;
|
||||
private Object data;
|
||||
|
||||
public R(Integer code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public R (Integer code, String msg, Object data) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.data = 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;
|
||||
return new R(200, "ok", data);
|
||||
}
|
||||
|
||||
public static R error(){
|
||||
return new R(500, "服务端发生未知错误");
|
||||
}
|
||||
|
||||
public static R unauthorized() {
|
||||
return new R(401, "未授权,客户端没有提供认证信息");
|
||||
}
|
||||
|
||||
public static R forbidden(){
|
||||
return new R(403, "没有权限");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
package com.dota.nexus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.dota.nexus.entity.Anniversary;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface AnniversaryMapper extends BaseMapper<Anniversary> {
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.dota.nexus.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.dota.nexus.entity.Anniversary;
|
||||
|
||||
public interface AnniversaryService extends IService<Anniversary> {
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.dota.nexus.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.dota.nexus.entity.Anniversary;
|
||||
import com.dota.nexus.mapper.AnniversaryMapper;
|
||||
import com.dota.nexus.service.AnniversaryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AnniversaryServiceImpl extends ServiceImpl<AnniversaryMapper, Anniversary> implements AnniversaryService {
|
||||
}
|
Reference in New Issue
Block a user