This commit is contained in:
2026-04-29 14:58:02 +08:00
parent e729f9bd31
commit b98c66ca21
370 changed files with 55094 additions and 0 deletions
@@ -0,0 +1,30 @@
package com.cyynote;
import com.cyynote.dso.AuthProcessorImpl;
import com.cyynote.dso.DsHelper;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.noear.solon.auth.AuthProcessor;
import org.noear.solon.auth.AuthUtil;
import org.noear.wood.cache.ICacheServiceEx;
import org.noear.wood.cache.LocalCache;
@Configuration
public class Config {
public static final ICacheServiceEx cache = (new LocalCache("test", 60)).nameSet("test");
@Bean(value = "db1", typed = true)
public DataSource db1(@Inject("${test.db1}") HikariDataSource dataSource) {
DsHelper.initData((DataSource)dataSource);
return (DataSource)dataSource;
}
@Bean
public void authAdapter() {
AuthUtil.adapter()
.processor((AuthProcessor)new AuthProcessorImpl());
}
}
@@ -0,0 +1,12 @@
package com.cyynote;
import org.noear.solon.Solon;
import org.noear.wood.WoodConfig;
public class WebApp {
public static void main(String[] args) {
Solon.start(com.cyynote.WebApp.class, args);
WoodConfig.onExecuteAft(cmd -> System.out.println("[Wood]" + cmd.text + "\r\n" + cmd.paramMap()));
}
}
@@ -0,0 +1,103 @@
package com.cyynote.controller;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONObject;
import com.cyynote.controller.BaseController;
import com.cyynote.model.NoteModel;
import com.cyynote.model.UserModel;
import com.cyynote.payload.request.LoginRequest;
import com.cyynote.payload.request.SignupRequest;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Logger;
import com.cyynote.payload.request.UpdatePasswordRequest;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Result;
import org.noear.wood.DbContext;
import org.noear.wood.DbTableQuery;
import org.noear.wood.annotation.Db;
@Mapping("/api/auth")
@Controller
public class AuthController extends BaseController {
private static final Logger log = Logger.getLogger(com.cyynote.controller.AuthController.class.getName());
@Db
DbContext db;
@Mapping("/logout")
public void logout(Context ctx) {
ctx.sessionClear();
}
@Post
@Mapping("/signin")
public Result signin(Context ctx, @Body LoginRequest loginRequest) throws SQLException {
log.info("name:" + loginRequest.getUsername());
log.info("password:" + loginRequest.getPassword());
long count = db.table("user").selectCount();
log.info("countUser:" + count);
List<UserModel> all = ((DbTableQuery)this.db.table("user")).selectList("*", UserModel.class);
log.info( all.toString());
UserModel model = (UserModel)((DbTableQuery)((DbTableQuery)this.db.table("user").whereEq("username", loginRequest.getUsername())).andEq("password", loginRequest.getPassword())).selectItem("*", UserModel.class);
if ("admin".equals(model.getUsername())) {
ctx.sessionSet("user_name", loginRequest.getUsername());
ctx.sessionSet("user_id", model.getId());
JSONObject obj = new JSONObject();
String token = ctx.sessionState().sessionToken();
obj.put("accessToken", token);
obj.put("id", Integer.valueOf(1));
obj.put("username", loginRequest.getUsername());
obj.put("email", "1");
obj.put("roles", "1");
int flag = ((DbTableQuery)this.db.table("user").set("token", token).set("logintime", DateUtil.now()).whereEq("id", model.getId())).update();
System.out.println(flag);
return Result.succeed(obj);
}
return Result.failure();
}
@Post
@Mapping("/updatePassword")
public Result updatePassword(Context ctx, @Body UpdatePasswordRequest loginRequest) throws SQLException {
log.info("name:" + loginRequest.getUsername());
log.info("old - password:" + loginRequest.getOldpassword());
log.info("new - password:" + loginRequest.getNewpassword());
long count = db.table("user").selectCount();
log.info("countUser:" + count);
List<UserModel> all = ((DbTableQuery)this.db.table("user")).selectList("*", UserModel.class);
log.info( all.toString());
UserModel model = (UserModel)((DbTableQuery)((DbTableQuery)this.db.table("user").whereEq("username", loginRequest.getUsername())).andEq("password", loginRequest.getOldpassword())).selectItem("*", UserModel.class);
if ("admin".equals(model.getUsername())) {
int flag = ((DbTableQuery)this.db.table("user").set("password", loginRequest.getNewpassword()).whereEq("id", model.getId())).update();
System.out.println(flag);
return Result.succeed(flag);
}
return Result.failure();
}
@Post
@Mapping("/signup")
public Result signup(@Body SignupRequest signUpRequest) {
log.info("signUpRequest:" + JSONObject.toJSONString(signUpRequest, new com.alibaba.fastjson2.JSONWriter.Feature[0]));
JSONObject obj = new JSONObject();
return Result.succeed(obj);
}
}
@@ -0,0 +1,6 @@
package com.cyynote.controller;
import org.noear.solon.web.cors.annotation.CrossOrigin;
@CrossOrigin(origins = "*")
public class BaseController {}
@@ -0,0 +1,55 @@
package com.cyynote.controller;
import com.cyynote.controller.BaseController;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Delete;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Patch;
import org.noear.solon.annotation.Post;
import org.noear.solon.annotation.Put;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.ModelAndView;
@Controller
public class DemoController extends BaseController {
@Mapping("/demo")
public Object test() {
ModelAndView model = new ModelAndView("beetl.htm");
model.put("title", "dock");
model.put("message", "world!");
return model;
}
@Post
@Mapping("post")
public String test_post(Context context) {
return context.param("name");
}
@Put
@Mapping("put")
public String test_put(Context context, String name) {
return context.param("name");
}
@Delete
@Mapping("delete")
public String test_delete(Context context, String name) {
return context.param("name");
}
@Patch
@Mapping("patch")
public String test_patch(Context context, String name) {
return context.param("name");
}
@Get
@Mapping("get")
public String test_post_get(Context context) {
return context.path();
}
}
@@ -0,0 +1,44 @@
package com.cyynote.controller;
import io.jsonwebtoken.Claims;
import org.noear.solon.annotation.Component;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Handler;
import org.noear.solon.core.handle.Result;
import org.noear.solon.core.route.RouterInterceptor;
import org.noear.solon.core.route.RouterInterceptorChain;
import org.noear.solon.sessionstate.jwt.JwtUtils;
@Component
public class JwtInterceptor implements RouterInterceptor {
public void doIntercept(Context ctx, Handler mainHandler, RouterInterceptorChain chain) throws Throwable {
boolean flag = true;
if ("/api/auth/signup".equals(ctx.path()) ||
"/api/auth/signin".equals(ctx.path()) ||
"/demo".equals(ctx.path()) ||
"/api/auth/logout".equals(ctx.path())
)
flag = false;
if (flag)
if (null != ctx.header("Authorization")) {
String token = ctx.header("Authorization");
token = token.replace("Bearer ", "");
System.out.println("token:" + token);
Claims claims = JwtUtils.parseJwt(token);
System.out.println("claims:" + claims);
if (null != claims) {
System.out.println("username:" + claims.get("user_name"));
System.out.println("exp:" + claims.get("exp"));
} else {
ctx.status(401);
ctx.render(Result.failure(401, ""));
}
} else {
ctx.status(401);
ctx.render(Result.failure(401, ""));
}
chain.doIntercept(ctx, mainHandler);
}
}
@@ -0,0 +1,207 @@
package com.cyynote.controller;
import cn.hutool.*;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONObject;
import com.cyynote.controller.BaseController;
import com.cyynote.dso.NoteSqlAnnotation;
import com.cyynote.model.HistoryModel;
import com.cyynote.model.NoteModel;
import com.cyynote.payload.request.NoteRequest;
import com.cyynote.util.TreeBuild;
import com.cyynote.util.TreeNode;
import io.jsonwebtoken.Claims;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Path;
import org.noear.solon.annotation.Post;
import org.noear.solon.annotation.Put;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Result;
import org.noear.solon.sessionstate.jwt.JwtUtils;
import org.noear.solon.web.cors.annotation.CrossOrigin;
import org.noear.wood.DbContext;
import org.noear.wood.DbTableQuery;
import org.noear.wood.annotation.Db;
@Mapping("/api/note")
@Controller
public class NoteController extends BaseController {
private static final Logger log = Logger.getLogger(com.cyynote.controller.NoteController.class.getName());
@Db
NoteSqlAnnotation mapper;
@Db
DbContext db;
private static final String QUERY_F = "id,pid,title,createtime,updatetime,viewtime,flag";
@Get
@Mapping("get1")
public String test_post_get(Context context, @Path String appname) {
return context.path();
}
@Post
@Mapping("post")
public String test_post(Context context) {
return context.param("name");
}
@Put
@Mapping("put")
public String test_put(Context context, String name) {
return context.param("name");
}
@Get
@Mapping("/all")
public Result noteAccess(Context ctx) throws Exception {
List<NoteModel> all = ((DbTableQuery)this.db.table("note").whereEq("flag", Integer.valueOf(1))).selectList("id,pid,title,createtime,updatetime,viewtime,flag", NoteModel.class);
List<TreeNode> treeNodeList = new ArrayList<>();
for (NoteModel n : all) {
TreeNode treeNode = new TreeNode(n.getId().intValue(), n.getPid().intValue(), n.getTitle(), String.valueOf(n.getId()), String.valueOf(n.getId()));
treeNodeList.add(treeNode);
}
TreeBuild bb = new TreeBuild(treeNodeList);
List<TreeNode> collect = bb.buildTree();
return Result.succeed(JSONArray.parseArray(JSONArray.toJSONString(collect)));
}
@Get
@Mapping("/home")
public Result noteHome(Context ctx, @Path int type, @Path String search) throws Exception {
System.out.println(type);
System.out.println(search);
List<NoteModel> all = new ArrayList<>();
if (type == 0) {
all = ((DbTableQuery)((DbTableQuery)this.db.table("note").whereLk("context", "%" + search + "%")).andLk("title", "%" + search + "%")).selectList("id,pid,title,createtime,updatetime,viewtime,flag", NoteModel.class);
} else if (type == 1) {
all = ((DbTableQuery)((DbTableQuery)((DbTableQuery)this.db.table("note").whereEq("flag", Integer.valueOf(1))).orderByDesc("updatetime")).limit(20)).selectList("id,pid,title,createtime,updatetime,viewtime,flag", NoteModel.class);
} else if (type == 2) {
all = ((DbTableQuery)((DbTableQuery)((DbTableQuery)this.db.table("note").whereEq("flag", Integer.valueOf(1))).orderByDesc("createtime")).limit(20)).selectList("id,pid,title,createtime,updatetime,viewtime,flag", NoteModel.class);
} else if (type == 3) {
all = ((DbTableQuery)((DbTableQuery)((DbTableQuery)this.db.table("note").whereEq("flag", Integer.valueOf(1))).orderByDesc("viewtime")).limit(20)).selectList("id,pid,title,createtime,updatetime,viewtime,flag", NoteModel.class);
} else if (type == 4) {
all = ((DbTableQuery)((DbTableQuery)((DbTableQuery)this.db.table("note").whereEq("flag", Integer.valueOf(0))).orderByDesc("updatetime")).limit(10000)).selectList("id,pid,title,createtime,updatetime,viewtime,flag", NoteModel.class);
}
return Result.succeed(JSONArray.parseArray(JSONArray.toJSONString(all)));
}
@Get
@Mapping("/get")
public Result getNote(Context ctx, @Path int id) throws Exception {
NoteModel model = (NoteModel)((DbTableQuery)this.db.table("note").whereEq("id", Integer.valueOf(id))).selectItem("*", NoteModel.class);
String time = DateUtil.now();
System.out.println(time);
int flag = ((DbTableQuery)this.db.table("note").set("viewtime", time).whereEq("id", Integer.valueOf(id))).update();
System.out.println(flag);
log.info(JSONObject.toJSONString(model, new com.alibaba.fastjson2.JSONWriter.Feature[0]));
return Result.succeed(model);
}
@Get
@Mapping("/add")
public Result addNote(Context ctx, @Path int pid) throws Exception {
String userid = getUserInfoId(ctx);
if (null == userid)
return Result.failure(401);
NoteModel note = new NoteModel();
note.setPid(Integer.valueOf(pid));
note.setTitle("未命名Note");
note.setFlag(Integer.valueOf(1));
note.setCreatetime(DateUtil.now());
note.setContext("{\"root\":{\"children\":[{\"children\":[{\"detail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\"未命名Note\",\"type\":\"text\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"paragraph\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"root\",\"version\":1}}");
// note.setContext("{\"root\": {\"type\": \"root\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"type\": \"paragraph\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [], \"direction\": null}], \"direction\": null}}");
this.db.table("note").setEntityIf(note, (k, v) -> Boolean.valueOf((v != null))).insert();
return Result.succeed("ok");
}
@Post
@Mapping("/update")
public Result updateNote(@Body NoteRequest noteRequest) throws SQLException {
NoteModel note = (NoteModel)((DbTableQuery)this.db.table("note").whereEq("id", noteRequest.getId())).selectItem("id,pid,title,createtime,updatetime,viewtime,flag", NoteModel.class);
note.setTitle(noteRequest.getTitle());
note.setUpdatetime(DateUtil.now());
String cc = noteRequest.getContext();
JSONObject ar = JSONObject.parseObject(cc);
note.setContext(ar.toJSONString());
int flag = ((DbTableQuery)this.db.table("note").set("title", noteRequest.getTitle()).set("updatetime", DateUtil.now()).set("context", ar.toJSONString()).whereEq("id", noteRequest.getId())).update();
log.info("updateNote+ flag");
HistoryModel history = new HistoryModel();
history.setNid(Integer.valueOf(noteRequest.getId().intValue()));
history.setTitle(noteRequest.getTitle());
history.setFlag(Integer.valueOf(1));
history.setCreatetime(DateUtil.now());
history.setContext(ar.toJSONString());
long his = this.db.table("history").setEntityIf(history, (k, v) -> Boolean.valueOf((v != null))).insert();
log.info("history+ his");
return Result.succeed("ok");
}
@Post
@Mapping("/delete")
public Result deleteNote(@Body NoteRequest noteRequest) throws SQLException {
int flag = ((DbTableQuery)this.db.table("note").set("title", noteRequest.getTitle()).set("flag", Integer.valueOf(0)).whereEq("id", noteRequest.getId())).update();
System.out.println(flag);
return Result.succeed("ok");
}
@Get
@Mapping("/deleteBack")
public Result deleteBack(@Path int id) throws Exception {
int flag = ((DbTableQuery)this.db.table("note").set("flag", Integer.valueOf(1)).whereEq("id", Integer.valueOf(id))).update();
System.out.println(flag);
return Result.succeed("ok");
}
@Get
@Mapping("/historyQueryOrDelete")
public Result historyQueryOrDelete(@Path int flag) throws Exception {
log.info("history+ flag" + flag);
if(flag==0){
long count = db.table("history").selectCount();
log.info("count:" + count);
return Result.succeed(count);
}else if(flag==1){
int flagdb = db.table("history").whereEq("flag",1).delete();
log.info("flagdb:" + flagdb);
return Result.succeed(0);
}
return null;
}
private String getUserInfoId(Context ctx) {
String userId = "";
if (null != ctx.header("Authorization")) {
String token = ctx.header("Authorization");
token = token.replace("Bearer ", "");
System.out.println("token:" + token);
Claims claims = JwtUtils.parseJwt(token);
System.out.println("claims:" + claims);
if (null != claims) {
System.out.println("username:" + claims.get("user_name"));
System.out.println("userid:" + claims.get("user_id"));
System.out.println("exp:" + claims.get("exp"));
userId = claims.get("user_id").toString();
return userId;
}
return null;
}
return null;
}
}
@@ -0,0 +1,34 @@
package com.cyynote.controller;
import com.cyynote.controller.BaseController;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Mapping;
@Controller
@Mapping("/api/test")
public class Test2Controller extends BaseController {
@Get
@Mapping("/all")
public String allAccess() {
return "Public Content.";
}
@Get
@Mapping("/user")
public String userAccess() {
return "User Content.";
}
@Get
@Mapping("/mod")
public String moderatorAccess() {
return "Moderator Board.";
}
@Get
@Mapping("/admin")
public String adminAccess() {
return "Admin Board.";
}
}
@@ -0,0 +1,26 @@
package com.cyynote.dso;
import java.util.ArrayList;
import java.util.List;
import org.noear.solon.auth.AuthProcessorBase;
public class AuthProcessorImpl extends AuthProcessorBase {
public boolean verifyLogined() {
return true;
}
protected List<String> getPermissions() {
List<String> list = new ArrayList<>();
list.add("user:add");
list.add("user:demo");
return list;
}
protected List<String> getRoles() {
List<String> list = new ArrayList<>();
list.add("admin1");
list.add("admin2");
return list;
}
}
@@ -0,0 +1,19 @@
package com.cyynote.dso;
import com.cyynote.model.UserModel;
import java.util.Map;
import org.noear.wood.BaseMapper;
import org.noear.wood.annotation.Db;
import org.noear.wood.annotation.Sql;
@Db
public interface AuthSqlAnnotation extends BaseMapper<UserModel> {
@Sql("select app_id from appx limit 1")
int user_get() throws Exception;
@Sql(value = "select * from user where id = @{id} limit 1", caching = "test", cacheTag = "app_${id}")
UserModel user_get2(int paramInt) throws Exception;
@Sql(value = "select * from ${tb} where id = @{id} limit 1", cacheClear = "test")
Map<String, Object> user_get3(String paramString, int paramInt) throws Exception;
}
@@ -0,0 +1,59 @@
package com.cyynote.dso;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
public class DsHelper {
private static boolean inited = false;
public static void initData(DataSource ds) {
if (inited)
return;
inited = true;
Connection conn = null;
try {
conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement("SELECT name FROM sqlite_master WHERE type='table' AND name='appx';");
ResultSet res = ps.executeQuery();
if (!res.next()) {
String[] sqls = getSqlFromFile();
for (String sql : sqls)
runSql(conn, sql);
}
ps.close();
} catch (SQLException sqlException) {
throw new RuntimeException(sqlException);
} finally {
try {
if (conn != null)
conn.close();
} catch (SQLException sQLException) {}
}
}
private static String[] getSqlFromFile() {
try {
InputStream ins = com.cyynote.dso.DsHelper.class.getResourceAsStream("/db/schema.sql");
int len = ins.available();
byte[] bs = new byte[len];
ins.read(bs);
String str = new String(bs, "UTF-8");
String[] sql = str.split(";");
return sql;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
private static void runSql(Connection conn, String sql) throws SQLException {
System.out.println(sql);
PreparedStatement ps = conn.prepareStatement(sql);
ps.executeUpdate();
ps.close();
}
}
@@ -0,0 +1,32 @@
package com.cyynote.dso;
import com.cyynote.model.NoteModel;
import java.util.List;
import java.util.Map;
import org.noear.wood.BaseMapper;
import org.noear.wood.annotation.Db;
import org.noear.wood.annotation.Sql;
@Db
public interface NoteSqlAnnotation extends BaseMapper<NoteModel> {
@Sql("select id from note limit 1")
int note_get() throws Exception;
@Sql("select * from note where flag =1 limit 10000")
List<NoteModel> findAll() throws Exception;
@Sql(value = "select * from note where id = @{id} limit 1", caching = "test", cacheTag = "app_${id}")
NoteModel note_get2(int paramInt) throws Exception;
@Sql(value = "select * from ${tb} where id = @{id} limit 1", cacheClear = "test")
Map<String, Object> note_get3(String paramString, int paramInt) throws Exception;
@Sql("insert into note (`pid`,`title`,`context`,`createtime`,`flag`) values (@{pid},${title},${context},${createtime},@{flag})")
Map<String, Object> insert(int paramInt1, String paramString1, String paramString2, String paramString3, int paramInt2) throws Exception;
@Sql("update note set id = @{id} where id = @{id} ")
Map<String, Object> update(String paramString, int paramInt) throws Exception;
@Sql("update note set viewtime = @{viewtime} where id = @{id}")
Map<String, Object> updateViewtime(String paramString, int paramInt) throws Exception;
}
@@ -0,0 +1,26 @@
package com.cyynote.dso;
import com.cyynote.model.AppxModel;
import java.util.List;
import java.util.Map;
import org.noear.wood.BaseMapper;
import org.noear.wood.annotation.Db;
import org.noear.wood.annotation.Sql;
@Db
public interface SqlAnnotation extends BaseMapper<AppxModel> {
@Sql("select app_id from appx limit 1")
int appx_get() throws Exception;
@Sql(value = "select * from appx where app_id = @{app_id} limit 1", caching = "test", cacheTag = "app_${app_id}")
AppxModel appx_get2(int paramInt) throws Exception;
@Sql(value = "select * from ${tb} where app_id = @{app_id} limit 1", cacheClear = "test")
Map<String, Object> appx_get3(String paramString, int paramInt) throws Exception;
@Sql("select * from appx where app_id>@{app_id} order by app_id asc limit 4")
List<AppxModel> appx_getlist(int paramInt) throws Exception;
@Sql("select app_id from appx limit 4")
List<Integer> appx_getids() throws Exception;
}
@@ -0,0 +1,20 @@
package com.cyynote.dso;
import com.cyynote.model.AppxModel;
import java.util.List;
import java.util.Map;
import org.noear.wood.BaseMapper;
import org.noear.wood.xml.Namespace;
@Namespace("webapp.dso")
public interface SqlMapper extends BaseMapper<AppxModel> {
int appx_get() throws Exception;
AppxModel appx_get2(int paramInt) throws Exception;
Map<String, Object> appx_get3(String paramString, int paramInt) throws Exception;
List<AppxModel> appx_getlist(int paramInt) throws Exception;
List<Integer> appx_getids() throws Exception;
}
@@ -0,0 +1,17 @@
package com.cyynote.model;
import org.noear.wood.annotation.PrimaryKey;
public class Appx {
@PrimaryKey
public int app_id;
public int agroup_id;
public String note;
public String app_key;
public int ar_is_examine;
}
@@ -0,0 +1,20 @@
package com.cyynote.model;
import lombok.Getter;
import lombok.Setter;
import org.noear.wood.annotation.PrimaryKey;
import org.noear.wood.annotation.Table;
@Getter
@Setter
@Table("appx")
public class AppxModel {
@PrimaryKey
private int app_id;
private int agroup_id;
private String note;
private String app_key;
private int ar_is_examine;
}
@@ -0,0 +1,86 @@
package com.cyynote.model;
import lombok.Data;
import org.noear.wood.annotation.PrimaryKey;
import org.noear.wood.annotation.Table;
@Data
@Table("history")
public class HistoryModel {
@PrimaryKey
public Integer id;
public Integer nid;
public String title;
public String context;
public String conjson;
public String createtime;
public Integer flag;
public void setId(Integer id) {
this.id = id;
}
public void setNid(Integer nid) {
this.nid = nid;
}
public void setTitle(String title) {
this.title = title;
}
public void setContext(String context) {
this.context = context;
}
public void setConjson(String conjson) {
this.conjson = conjson;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public void setFlag(Integer flag) {
this.flag = flag;
}
public String toString() {
return "HistoryModel(id=" + getId() + ", nid=" + getNid() + ", title=" + getTitle() + ", context=" + getContext() + ", conjson=" + getConjson() + ", createtime=" + getCreatetime() + ", flag=" + getFlag() + ")";
}
public Integer getId() {
return this.id;
}
public Integer getNid() {
return this.nid;
}
public String getTitle() {
return this.title;
}
public String getContext() {
return this.context;
}
public String getConjson() {
return this.conjson;
}
public String getCreatetime() {
return this.createtime;
}
public Integer getFlag() {
return this.flag;
}
}
@@ -0,0 +1,107 @@
package com.cyynote.model;
import lombok.Data;
import org.noear.wood.annotation.PrimaryKey;
import org.noear.wood.annotation.Table;
@Data
@Table("note")
public class NoteModel {
@PrimaryKey
public Integer id;
public Integer pid;
public String title;
public String context;
public String conjson;
public String createtime;
public String updatetime;
public String viewtime;
public Integer flag;
public void setId(Integer id) {
this.id = id;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public void setTitle(String title) {
this.title = title;
}
public void setContext(String context) {
this.context = context;
}
public void setConjson(String conjson) {
this.conjson = conjson;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public void setUpdatetime(String updatetime) {
this.updatetime = updatetime;
}
public void setViewtime(String viewtime) {
this.viewtime = viewtime;
}
public void setFlag(Integer flag) {
this.flag = flag;
}
public String toString() {
return "NoteModel(id=" + getId() + ", pid=" + getPid() + ", title=" + getTitle() + ", context=" + getContext() + ", conjson=" + getConjson() + ", createtime=" + getCreatetime() + ", updatetime=" + getUpdatetime() + ", viewtime=" + getViewtime() + ", flag=" + getFlag() + ")";
}
public Integer getId() {
return this.id;
}
public Integer getPid() {
return this.pid;
}
public String getTitle() {
return this.title;
}
public String getContext() {
return this.context;
}
public String getConjson() {
return this.conjson;
}
public String getCreatetime() {
return this.createtime;
}
public String getUpdatetime() {
return this.updatetime;
}
public String getViewtime() {
return this.viewtime;
}
public Integer getFlag() {
return this.flag;
}
}
@@ -0,0 +1,85 @@
package com.cyynote.model;
import lombok.Data;
import org.noear.wood.annotation.PrimaryKey;
import org.noear.wood.annotation.Table;
@Data
@Table("user")
public class UserModel {
@PrimaryKey
public Integer id;
public String email;
public String password;
public String username;
public String role;
public String token;
public String logintime;
public void setId(Integer id) {
this.id = id;
}
public void setEmail(String email) {
this.email = email;
}
public void setPassword(String password) {
this.password = password;
}
public void setUsername(String username) {
this.username = username;
}
public void setRole(String role) {
this.role = role;
}
public void setToken(String token) {
this.token = token;
}
public void setLogintime(String logintime) {
this.logintime = logintime;
}
public String toString() {
return "UserModel(id=" + getId() + ", email=" + getEmail() + ", password=" + getPassword() + ", username=" + getUsername() + ", role=" + getRole() + ", token=" + getToken() + ", logintime=" + getLogintime() + ")";
}
public Integer getId() {
return this.id;
}
public String getEmail() {
return this.email;
}
public String getPassword() {
return this.password;
}
public String getUsername() {
return this.username;
}
public String getRole() {
return this.role;
}
public String getToken() {
return this.token;
}
public String getLogintime() {
return this.logintime;
}
}
@@ -0,0 +1,25 @@
package com.cyynote.payload.request;
public class LoginRequest {
private String username;
private String password;
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
}
@@ -0,0 +1,44 @@
package com.cyynote.payload.request;
public class NoteRequest {
private Long id;
private Long pid;
private String title;
private String context;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Long getPid() {
return this.pid;
}
public void setPid(Long pid) {
this.pid = pid;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContext() {
return this.context;
}
public void setContext(String context) {
this.context = context;
}
}
@@ -0,0 +1,47 @@
package com.cyynote.payload.request;
import java.util.Set;
public class SignupRequest {
private String username;
private String email;
private Set<String> role;
private String password;
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public Set<String> getRole() {
return this.role;
}
public void setRole(Set<String> role) {
this.role = role;
}
}
@@ -0,0 +1,17 @@
package com.cyynote.payload.request;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class UpdatePasswordRequest {
private String username;
private String oldpassword;
private String newpassword;
}
@@ -0,0 +1,70 @@
package com.cyynote.payload.response;
import java.util.List;
public class JwtResponse {
private String token;
private String type = "Bearer";
private Long id;
private String username;
private String email;
private List<String> roles;
public JwtResponse(String accessToken, Long id, String username, String email, List<String> roles) {
this.token = accessToken;
this.id = id;
this.username = username;
this.email = email;
this.roles = roles;
}
public String getAccessToken() {
return this.token;
}
public void setAccessToken(String accessToken) {
this.token = accessToken;
}
public String getTokenType() {
return this.type;
}
public void setTokenType(String tokenType) {
this.type = tokenType;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public List<String> getRoles() {
return this.roles;
}
}
@@ -0,0 +1,17 @@
package com.cyynote.payload.response;
public class MessageResponse {
private String message;
public MessageResponse(String message) {
this.message = message;
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
}
@@ -0,0 +1,42 @@
package com.cyynote.util;
import com.cyynote.util.TreeNode;
import java.util.ArrayList;
import java.util.List;
public class TreeBuild {
public List<TreeNode> nodeList = new ArrayList<>();
public TreeBuild(List<TreeNode> nodeList) {
this.nodeList = nodeList;
}
public List<TreeNode> getRootNode() {
List<TreeNode> rootNodeList = new ArrayList<>();
for (TreeNode treeNode : this.nodeList) {
if (0 == treeNode.getPid())
rootNodeList.add(treeNode);
}
return rootNodeList;
}
public List<TreeNode> buildTree() {
List<TreeNode> treeNodes = new ArrayList<>();
for (TreeNode treeRootNode : getRootNode()) {
treeRootNode = buildChildTree(treeRootNode);
treeNodes.add(treeRootNode);
}
return treeNodes;
}
public TreeNode buildChildTree(TreeNode pNode) {
List<TreeNode> childTree = new ArrayList<>();
for (TreeNode treeNode : this.nodeList) {
if (treeNode.getPid() == pNode.getId())
childTree.add(buildChildTree(treeNode));
}
pNode.setChildren(childTree);
return pNode;
}
}
@@ -0,0 +1,74 @@
package com.cyynote.util;
import java.util.List;
public class TreeNode {
private int id;
private int pid;
private String label;
private String value;
private String key;
private List<com.cyynote.util.TreeNode> children;
public TreeNode(int id, int pid, String label, String value, String key) {
this.id = id;
this.pid = pid;
this.label = label;
this.value = value;
this.key = key;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public int getPid() {
return this.pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
public String getKey() {
return this.key;
}
public void setKey(String key) {
this.key = key;
}
public List<com.cyynote.util.TreeNode> getChildren() {
return this.children;
}
public void setChildren(List<com.cyynote.util.TreeNode> children) {
this.children = children;
}
}