mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-28 22:15:12 -04:00
Fix Communication between frontend and backend (#1201)
Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
4a18e51c83
commit
9cf7980334
38 changed files with 268 additions and 164 deletions
28
src/api/notes/dto-methods.ts
Normal file
28
src/api/notes/dto-methods.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { NoteDto } from './types'
|
||||
import { NoteDetails } from '../../redux/note-details/types'
|
||||
import { DateTime } from 'luxon'
|
||||
import { initialState } from '../../redux/note-details/reducers'
|
||||
|
||||
export const noteDtoToNoteDetails = (note: NoteDto): NoteDetails => {
|
||||
return {
|
||||
markdownContent: note.content,
|
||||
frontmatter: initialState.frontmatter,
|
||||
id: note.metadata.id,
|
||||
noteTitle: initialState.noteTitle,
|
||||
createTime: DateTime.fromISO(note.metadata.createTime),
|
||||
lastChange: {
|
||||
userName: note.metadata.updateUser.userName,
|
||||
timestamp: DateTime.fromISO(note.metadata.updateTime)
|
||||
},
|
||||
firstHeading: initialState.firstHeading,
|
||||
viewCount: note.metadata.viewCount,
|
||||
alias: note.metadata.alias,
|
||||
authorship: note.metadata.editedBy
|
||||
}
|
||||
}
|
|
@ -5,31 +5,17 @@
|
|||
*/
|
||||
|
||||
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
|
||||
import { NoteDto } from './types'
|
||||
import { isMockMode } from '../../utils/test-modes'
|
||||
|
||||
interface LastChange {
|
||||
userId: string
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
export interface Note {
|
||||
id: string
|
||||
alias: string
|
||||
lastChange: LastChange
|
||||
viewCount: number
|
||||
createTime: number
|
||||
content: string
|
||||
authorship: number[]
|
||||
preVersionTwoNote: boolean
|
||||
}
|
||||
|
||||
export const getNote = async (noteId: string): Promise<Note> => {
|
||||
export const getNote = async (noteId: string): Promise<NoteDto> => {
|
||||
// The "-get" suffix is necessary, because in our mock api (filesystem) the note id might already be a folder.
|
||||
// TODO: [mrdrogdrog] replace -get with actual api route as soon as api backend is ready.
|
||||
const response = await fetch(getApiUrl() + `/notes/${ noteId }-get`, {
|
||||
const response = await fetch(getApiUrl() + `/notes/${ noteId }${ isMockMode() ? '-get' : '' }`, {
|
||||
...defaultFetchConfig
|
||||
})
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<Note>
|
||||
return await response.json() as Promise<NoteDto>
|
||||
}
|
||||
|
||||
export const deleteNote = async (noteId: string): Promise<void> => {
|
||||
|
|
53
src/api/notes/types.d.ts
vendored
Normal file
53
src/api/notes/types.d.ts
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { UserInfoDto } from '../users/types'
|
||||
import { GroupInfoDto } from '../group/types'
|
||||
|
||||
export interface NoteDto {
|
||||
content: string
|
||||
metadata: NoteMetadataDto
|
||||
editedByAtPosition: NoteAuthorshipDto[]
|
||||
}
|
||||
|
||||
export interface NoteMetadataDto {
|
||||
id: string
|
||||
alias: string
|
||||
version: number
|
||||
title: string
|
||||
description: string
|
||||
tags: string[]
|
||||
updateTime: string
|
||||
updateUser: UserInfoDto
|
||||
viewCount: number
|
||||
createTime: string
|
||||
editedBy: string[]
|
||||
permissions: NotePermissionsDto
|
||||
}
|
||||
|
||||
export interface NoteAuthorshipDto {
|
||||
userName: string
|
||||
startPos: number
|
||||
endPos: number
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface NotePermissionsDto {
|
||||
owner: UserInfoDto
|
||||
sharedToUsers: NoteUserPermissionEntryDto[]
|
||||
sharedToGroups: NoteGroupPermissionEntryDto[]
|
||||
}
|
||||
|
||||
export interface NoteUserPermissionEntryDto {
|
||||
user: UserInfoDto
|
||||
canEdit: boolean
|
||||
}
|
||||
|
||||
export interface NoteGroupPermissionEntryDto {
|
||||
group: GroupInfoDto
|
||||
canEdit: boolean
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue