This repository was archived by the owner on Sep 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
backend interfaces #3
Open
DUHsoALEX
wants to merge
7
commits into
main
Choose a base branch
from
backend-interfaces
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cc76d52
backend interfaces
DUHsoALEX d80eef1
convert local backend interface to singleton class
DUHsoALEX f1e8e63
using Records, returning promises, error throwing
DUHsoALEX 702aeed
filters page implements local mode
DUHsoALEX 720285c
filters shows wikis, enable/disable filter stubs
DUHsoALEX 64bbe56
enabled + hit properties
DUHsoALEX 77490ce
controllers
DUHsoALEX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/frontend/discussions-abusefilter-app/src/interfaces/BackendInterface.ts
This file contains hidden or 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,9 @@ | ||
| import type { Filter, FilterMetadata } from '@shared/filters'; | ||
|
|
||
| export interface BackendInterface { | ||
| getFilters: <T = any>() => Promise<T> | FilterMetadata[], | ||
| getFilter: <T = any>(filterId: string) => Promise<T> | { filterDetails: Filter | undefined, filterMetadata: FilterMetadata | undefined }, | ||
DUHsoALEX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| createFilter: (filter: Filter, filterMetadata: FilterMetadata) => void, | ||
| updateFilter: (filterId: string, filter: Filter, filterMetadata: FilterMetadata) => void, | ||
| deleteFilter: (filterId: string) => void, | ||
| } | ||
kcnotes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
38 changes: 38 additions & 0 deletions
38
src/frontend/discussions-abusefilter-app/src/interfaces/LocalBackendInterface.ts
This file contains hidden or 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,38 @@ | ||
| import type { Filter, FilterMetadata } from '@shared/filters'; | ||
| import type { BackendInterface } from './BackendInterface'; | ||
|
|
||
| export class LocalBackendInterface implements BackendInterface { | ||
| filters: Filter[]; | ||
| filtersMetadata: FilterMetadata[]; | ||
DUHsoALEX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| constructor(filters: Filter[], filtersMetadata: FilterMetadata[]) { | ||
| this.filters = filters; | ||
| this.filtersMetadata = filtersMetadata; | ||
| } | ||
|
|
||
| getFilters(): FilterMetadata[] { | ||
| return this.filtersMetadata; | ||
| } | ||
|
|
||
| getFilter(filterId: string): { filterDetails: Filter | undefined, filterMetadata: FilterMetadata | undefined } { | ||
| return { | ||
| filterDetails: this.filters.find(({ id }) => id === filterId), | ||
| filterMetadata: this.filtersMetadata.find(({ id }) => id === filterId), | ||
| }; | ||
| } | ||
|
|
||
| createFilter(filter: Filter, filterMetadata: FilterMetadata) { | ||
| this.filters.push(filter); | ||
| this.filtersMetadata.push(filterMetadata); | ||
| } | ||
|
|
||
| updateFilter(filterId: string, filter: Filter, filterMetadata: FilterMetadata) { | ||
| this.filters[this.filters.findIndex(f=> f.id === filterId)] = filter; | ||
| this.filtersMetadata[this.filtersMetadata.findIndex(f => f.id === filterId)] = filterMetadata; | ||
| } | ||
|
|
||
| deleteFilter(filterId: string) { | ||
| this.filters.splice(this.filters.findIndex(filter => filter.id === filterId), 1); | ||
| this.filtersMetadata.splice(this.filtersMetadata.findIndex(filter => filter.id === filterId), 1); | ||
| } | ||
| } | ||
62 changes: 62 additions & 0 deletions
62
src/frontend/discussions-abusefilter-app/src/interfaces/ProductionBackendInterface.ts
This file contains hidden or 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,62 @@ | ||
| import type { Filter } from '@shared/filters'; | ||
| import type { BackendInterface } from './BackendInterface'; | ||
|
|
||
| const baseApiUrl = ''; | ||
|
|
||
| export class ProductionBackendInterface implements BackendInterface { | ||
| userToken: string; | ||
|
|
||
| constructor({ userToken } : { | ||
| userToken: string | ||
| }) { | ||
| this.userToken = userToken; | ||
| } | ||
|
|
||
| getFilters<T = any>(): Promise<T> { | ||
| return fetch(`${baseApiUrl}/filters`, { | ||
| method: 'GET', | ||
| headers: { | ||
| token: this.userToken, | ||
| }, | ||
| }) | ||
| .then(res => res.json()) | ||
| .catch(e => console.log(e)); | ||
| } | ||
|
|
||
| getFilter<T = any>(filterId: string): Promise<T> { | ||
| return fetch(`${baseApiUrl}/filter/${filterId}`, { | ||
| method: 'GET', | ||
| headers: { | ||
| token: this.userToken, | ||
| }, | ||
| }) | ||
| .then(res => res.json()) | ||
| .catch(e => console.log(e)); | ||
| } | ||
|
|
||
| createFilter(filter: Filter) { | ||
| return fetch(`${baseApiUrl}/filter/new`, { | ||
| method: 'POST', | ||
| headers: { | ||
| token: this.userToken, | ||
| }, | ||
| body: JSON.stringify(filter), | ||
| }) | ||
| .catch(e => console.log(e)); | ||
| } | ||
|
|
||
| updateFilter(filterId: string, filter: Filter) { | ||
| return fetch(`${baseApiUrl}/filter/${filterId}`, { | ||
| method: 'POST', | ||
| headers: { | ||
| token: this.userToken, | ||
| }, | ||
| body: JSON.stringify(filter), | ||
| }) | ||
| .catch(e => console.log(e)); | ||
| } | ||
|
|
||
| deleteFilter(filterId: string) { | ||
| return filterId; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.