-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
726 additions
and
511 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:editing/domain/common.dart'; | ||
|
||
import '../database/database.dart'; | ||
|
||
class Category { | ||
int? id; | ||
String name; | ||
EncryptType encryptType; | ||
String? encryptArguments; | ||
DateTime createTime; | ||
DateTime lastUpdateTime; | ||
|
||
Category( | ||
{this.id, | ||
required this.name, | ||
required this.encryptType, | ||
this.encryptArguments, | ||
required this.createTime, | ||
required this.lastUpdateTime}); | ||
|
||
static Category fromEntity(CategoryEntity entity) { | ||
return Category( | ||
id: entity.id, | ||
name: entity.name, | ||
encryptType: EncryptType.getByValue(entity.encryptType), | ||
encryptArguments: entity.encryptArguments, | ||
createTime: DateTime.parse(entity.createTime), | ||
lastUpdateTime: DateTime.parse(entity.lastUpdateTime), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
enum EncryptType { | ||
plain(0), | ||
aes(1); | ||
|
||
final int value; | ||
|
||
const EncryptType(this.value); | ||
|
||
static EncryptType getByValue(num i) { | ||
return EncryptType.values.firstWhere((x) => x.value == i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import 'package:drift/drift.dart'; | ||
import 'package:editing/domain/category.dart'; | ||
|
||
import '../database/database.dart'; | ||
import 'common.dart'; | ||
|
||
enum NoteType { | ||
journal(1), | ||
note(2), | ||
idea(3), | ||
todo(4); | ||
|
||
final int value; | ||
|
||
const NoteType(this.value); | ||
|
||
static NoteType getByValue(num i) { | ||
return NoteType.values.firstWhere((x) => x.value == i); | ||
} | ||
} | ||
|
||
enum NoteFormat { | ||
plain(0), | ||
quill(1); | ||
|
||
final int value; | ||
|
||
const NoteFormat(this.value); | ||
|
||
static NoteFormat getByValue(num i) { | ||
return NoteFormat.values.firstWhere((x) => x.value == i); | ||
} | ||
} | ||
|
||
class Note { | ||
int? id; | ||
NoteType type; | ||
NoteFormat format; | ||
String title; | ||
String content; | ||
String? abstract; | ||
List<String>? tags; | ||
String? location; | ||
String? weather; | ||
String? mood; | ||
EncryptType encryptType; | ||
String? encryptArguments; | ||
DateTime createTime; | ||
DateTime lastUpdateTime; | ||
Category? category; | ||
|
||
Note( | ||
{this.id, | ||
required this.type, | ||
required this.format, | ||
required this.title, | ||
required this.content, | ||
this.abstract, | ||
this.tags, | ||
this.location, | ||
this.weather, | ||
this.mood, | ||
required this.encryptType, | ||
this.encryptArguments, | ||
required this.createTime, | ||
required this.lastUpdateTime, | ||
this.category}); | ||
|
||
NotesCompanion toCompanion() { | ||
return NotesCompanion( | ||
id: Value.absentIfNull(id), | ||
type: Value(type.value), | ||
format: Value(format.value), | ||
title: Value(title), | ||
content: Value(content), | ||
abstract: Value.absentIfNull(abstract), | ||
tags: Value.absentIfNull(tags?.join(",")), | ||
location: Value.absentIfNull(location), | ||
weather: Value.absentIfNull(weather), | ||
mood: Value.absentIfNull(mood), | ||
encryptType: Value(encryptType.value), | ||
encryptArguments: Value.absentIfNull(encryptArguments), | ||
createTime: Value(createTime.toIso8601String()), | ||
lastUpdateTime: Value(lastUpdateTime.toIso8601String()), | ||
categoryId: Value.absentIfNull(category?.id), | ||
); | ||
} | ||
|
||
static Note fromEntity(NoteEntity entity, CategoryEntity? category) { | ||
if (entity.categoryId != null) { | ||
assert(category != null && category.id == entity.categoryId); | ||
} | ||
return Note( | ||
id: entity.id, | ||
type: NoteType.getByValue(entity.type), | ||
format: NoteFormat.getByValue(entity.format), | ||
title: entity.title, | ||
content: entity.content, | ||
abstract: entity.abstract, | ||
tags: entity.tags?.split(","), | ||
location: entity.location, | ||
weather: entity.weather, | ||
mood: entity.mood, | ||
encryptType: EncryptType.getByValue(entity.encryptType), | ||
encryptArguments: entity.encryptArguments, | ||
createTime: DateTime.parse(entity.createTime), | ||
lastUpdateTime: DateTime.parse(entity.lastUpdateTime), | ||
category: category != null ? Category.fromEntity(category) : null, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.