This commit is contained in:
Jesse-Ma
2022-12-01 16:35:21 +08:00
parent 3ae8f94916
commit 17ff6e710c
5 changed files with 21 additions and 12 deletions

View File

@@ -49,15 +49,17 @@ public class NoteController {
public NoteMeta getNoteMeta(@PathVariable("key") String key) {
NoteMeta meta = new NoteMeta();
Note note = noteService.getNote(key);
meta.setKey(key);
if (null == note) {
return meta;
}
meta.setServerTime(new Date().getTime());
meta.setKey(key);
meta.setLock(note.getLock());
meta.setMd5(note.getMd5());
meta.setState(note.getState());
meta.setTtl(note.getTtl());
return meta;

View File

@@ -17,8 +17,6 @@ public class Note implements Serializable {
private String key;
private String text;
private String md5;
private Integer lock;

View File

@@ -16,6 +16,8 @@ public class NoteMeta implements Serializable {/**
private String key;
private Integer state;
private String cipher;
private Integer lock;

View File

@@ -3,10 +3,6 @@ package com.flagnote.note.service;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import com.flagnote.note.entity.Note;
@@ -14,6 +10,7 @@ import com.flagnote.note.repository.NoteMongoRepository;
import com.flagnote.note.utils.BizKeyUtils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
@Service
public class NoteServiceImpl implements NoteService {
@@ -33,11 +30,14 @@ public class NoteServiceImpl implements NoteService {
}
if (note.getState() != 1) {
return null;
note.setTextBytes(null);
return note;
}
if (note.getExpireTime().getTime() <= new Date().getTime()) {
return null;
note.setState(0);
note.setTextBytes(null);
return note;
}
return note;
@@ -63,8 +63,13 @@ public class NoteServiceImpl implements NoteService {
@Override
public void deleteNote(String key) {
String mixKey = BizKeyUtils.mixKey(key);
Note note = noteMongoRepository.findById(mixKey).orElse(null);
noteMongoRepository.deleteById(mixKey);
if(null!=note && ArrayUtil.isNotEmpty(note.getTextBytes())) {
note.setState(0);
note.setTextBytes(null);
noteMongoRepository.save(note);
}
}
}