chore: update memo relation types (#1658)

This commit is contained in:
boojack 2023-05-14 23:17:05 +08:00 committed by GitHub
parent 7726ed4245
commit 2cc5691efd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 79 additions and 63 deletions

View File

@ -24,63 +24,63 @@ jobs:
CGO_ENABLED: 1
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2
- name: Clone Memos
run: git clone https://github.com/usememos/memos.git
- name: Clone Memos
run: git clone https://github.com/usememos/memos.git
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18.12.1'
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "18"
- name: Build frontend (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
cd memos/web
npm install -g pnpm
pnpm i --frozen-lockfile
pnpm build
Remove-Item -Path ../server/dist -Recurse -Force
mv dist ../server/
- name: Build frontend (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
cd memos/web
npm install -g pnpm
pnpm i --frozen-lockfile
pnpm build
Remove-Item -Path ../server/dist -Recurse -Force
mv dist ../server/
- name: Build frontend (non-Windows)
if: matrix.os != 'windows-latest'
run: |
cd memos/web
npm install -g pnpm
pnpm i --frozen-lockfile
pnpm build
rm -rf ../server/dist
mv dist ../server/
- name: Build frontend (non-Windows)
if: matrix.os != 'windows-latest'
run: |
cd memos/web
npm install -g pnpm
pnpm i --frozen-lockfile
pnpm build
rm -rf ../server/dist
mv dist ../server/
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.19.3'
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Install mingw-w64 (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install mingw
echo ${{ matrix.cgo_env }} >> $GITHUB_ENV
- name: Install mingw-w64 (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install mingw
echo ${{ matrix.cgo_env }} >> $GITHUB_ENV
- name: Install gcc-aarch64-linux-gnu (Ubuntu ARM64)
if: matrix.os == 'ubuntu-latest' && matrix.goarch == 'arm64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Install gcc-aarch64-linux-gnu (Ubuntu ARM64)
if: matrix.os == 'ubuntu-latest' && matrix.goarch == 'arm64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Build backend
run: |
cd memos
go build -o memos-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.os == 'windows-latest' && '.exe' || '' }} ./main.go
- name: Build backend
run: |
cd memos
go build -o memos-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.os == 'windows-latest' && '.exe' || '' }} ./main.go
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: memos-binary-${{ matrix.os }}-${{ matrix.goarch }}
path: memos/memos-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: memos-binary-${{ matrix.os }}-${{ matrix.goarch }}
path: memos/memos-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}

View File

@ -57,8 +57,8 @@ type MemoCreate struct {
Content string `json:"content"`
// Related fields
ResourceIDList []int `json:"resourceIdList"`
MemoRelationList []*MemoRelationUpsert `json:"memoRelationList"`
ResourceIDList []int `json:"resourceIdList"`
RelationList []*MemoRelationUpsert `json:"relationList"`
}
type MemoPatch struct {
@ -74,8 +74,8 @@ type MemoPatch struct {
Visibility *Visibility `json:"visibility"`
// Related fields
ResourceIDList []int `json:"resourceIdList"`
MemoRelationList []*MemoRelationUpsert `json:"memoRelationList"`
ResourceIDList []int `json:"resourceIdList"`
RelationList []*MemoRelationUpsert `json:"relationList"`
}
type MemoFind struct {

View File

@ -8,12 +8,12 @@ const (
)
type MemoRelation struct {
MemoID int
RelatedMemoID int
Type MemoRelationType
MemoID int `json:"memoId"`
RelatedMemoID int `json:"relatedMemoId"`
Type MemoRelationType `json:"type"`
}
type MemoRelationUpsert struct {
RelatedMemoID int
Type MemoRelationType
RelatedMemoID int `json:"relatedMemoId"`
Type MemoRelationType `json:"type"`
}

View File

@ -103,7 +103,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
if s.Profile.IsDev() {
for _, memoRelationUpsert := range memoCreate.MemoRelationList {
for _, memoRelationUpsert := range memoCreate.RelationList {
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelationMessage{
MemoID: memo.ID,
RelatedMemoID: memoRelationUpsert.RelatedMemoID,
@ -171,7 +171,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
if s.Profile.IsDev() {
for _, memoRelationUpsert := range memoPatch.MemoRelationList {
for _, memoRelationUpsert := range memoPatch.RelationList {
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelationMessage{
MemoID: memo.ID,
RelatedMemoID: memoRelationUpsert.RelatedMemoID,

View File

@ -35,7 +35,7 @@ func TestMemoRelationServer(t *testing.T) {
require.Equal(t, "test memo", memo.Content)
memo2, err := s.postMemoCreate(&api.MemoCreate{
Content: "test memo2",
MemoRelationList: []*api.MemoRelationUpsert{
RelationList: []*api.MemoRelationUpsert{
{
RelatedMemoID: memo.ID,
Type: api.MemoRelationReference,

View File

@ -240,6 +240,7 @@ const MemoEditor = () => {
content,
visibility: editorState.memoVisibility,
resourceIdList: editorState.resourceList.map((resource) => resource.id),
relationList: [],
});
filterStore.clearFilter();
}

View File

@ -16,11 +16,13 @@ interface Memo {
creatorName: string;
resourceList: Resource[];
relationList: MemoRelation[];
}
interface MemoCreate {
content: string;
resourceIdList: ResourceId[];
relationList: MemoRelationUpsert[];
visibility?: Visibility;
}
@ -30,6 +32,7 @@ interface MemoPatch {
rowStatus?: RowStatus;
content?: string;
resourceIdList?: ResourceId[];
relationList?: MemoRelationUpsert[];
visibility?: Visibility;
}

12
web/src/types/modules/memoRelation.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
type MemoRelationType = "REFERENCE" | "ADDITIONAL";
interface MemoRelation {
memoId: MemoId;
relatedMemoId: MemoId;
type: MemoRelationType;
}
interface MemoRelationUpsert {
relatedMemoId: MemoId;
type: MemoRelationType;
}