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:
Philip Molares 2021-05-01 23:01:42 +02:00 committed by GitHub
parent 4a18e51c83
commit 9cf7980334
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 268 additions and 164 deletions

View file

@ -12,7 +12,7 @@ export interface Config {
banner: BannerConfig,
customAuthNames: CustomAuthNames,
useImageProxy: boolean,
specialLinks: SpecialLinks,
specialUrls: SpecialUrls,
version: BackendVersion,
plantumlServer: string | null,
maxDocumentLength: number,
@ -35,9 +35,11 @@ export interface BannerConfig {
}
export interface BackendVersion {
version: string,
sourceCodeUrl: string
issueTrackerUrl: string
major: number
minor: number
patch: number
preRelease?: string
commit?: string
}
export interface AuthProvidersState {
@ -60,7 +62,7 @@ export interface CustomAuthNames {
saml: string;
}
export interface SpecialLinks {
export interface SpecialUrls {
privacy: string,
termsOfUse: string,
imprint: string,

11
src/api/group/types.d.ts vendored Normal file
View file

@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
export interface GroupInfoDto {
name: string
displayName: string
special: boolean
}

View file

@ -8,13 +8,13 @@ import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
import { HistoryEntryDto, HistoryEntryPutDto, HistoryEntryUpdateDto } from './types'
export const getHistory = async (): Promise<HistoryEntryDto[]> => {
const response = await fetch(getApiUrl() + '/history')
const response = await fetch(getApiUrl() + '/me/history')
expectResponseCode(response)
return await response.json() as Promise<HistoryEntryDto[]>
}
export const postHistory = async (entries: HistoryEntryPutDto[]): Promise<void> => {
const response = await fetch(getApiUrl() + '/history', {
const response = await fetch(getApiUrl() + '/me/history', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify(entries)
@ -23,7 +23,7 @@ export const postHistory = async (entries: HistoryEntryPutDto[]): Promise<void>
}
export const updateHistoryEntryPinStatus = async (noteId: string, entry: HistoryEntryUpdateDto): Promise<void> => {
const response = await fetch(getApiUrl() + '/history/' + noteId, {
const response = await fetch(getApiUrl() + '/me/history/' + noteId, {
...defaultFetchConfig,
method: 'PUT',
body: JSON.stringify(entry)
@ -32,7 +32,7 @@ export const updateHistoryEntryPinStatus = async (noteId: string, entry: History
}
export const deleteHistoryEntry = async (noteId: string): Promise<void> => {
const response = await fetch(getApiUrl() + '/history/' + noteId, {
const response = await fetch(getApiUrl() + '/me/history/' + noteId, {
...defaultFetchConfig,
method: 'DELETE'
})
@ -40,7 +40,7 @@ export const deleteHistoryEntry = async (noteId: string): Promise<void> => {
}
export const deleteHistory = async (): Promise<void> => {
const response = await fetch(getApiUrl() + '/history', {
const response = await fetch(getApiUrl() + '/me/history', {
...defaultFetchConfig,
method: 'DELETE'
})

View file

@ -6,9 +6,10 @@
import { UserResponse } from '../users/types'
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
import { isMockMode } from '../../utils/test-modes'
export const getMe = async (): Promise<UserResponse> => {
const response = await fetch(getApiUrl() + '/me', {
const response = await fetch(getApiUrl() + `/me${ isMockMode() ? '-get' : '' }`, {
...defaultFetchConfig
})
expectResponseCode(response)

View 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
}
}

View file

@ -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
View 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
}

View file

@ -12,3 +12,10 @@ export interface UserResponse {
photo: string
provider: LoginProvider
}
export interface UserInfoDto {
userName: string
displayName: string
photo: string
email: string
}