Skip to content

Commit

Permalink
Merge pull request #14 from HakierGrzonzo/9-przystosowanie-frontendu-…
Browse files Browse the repository at this point in the history
…do-zmian-w-backendzie

9 przystosowanie frontendu do zmian w backendzie
  • Loading branch information
HakierGrzonzo authored Mar 21, 2022
2 parents 2bea7e9 + aaadc84 commit 2ceef03
Show file tree
Hide file tree
Showing 37 changed files with 624 additions and 418 deletions.
20 changes: 10 additions & 10 deletions backend/backend/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from starlette.responses import FileResponse, Response
from typing import Tuple
from fastapi_redis_cache import cache_one_day, cache
from .models import FileRefrence, User
from .models import FileReference, User
from .database import get_async_session, Files, Measurements
from fastapi.routing import APIRouter
from os import environ, unlink
Expand All @@ -24,8 +24,8 @@ def __init__(self, fastapi_users: FastAPIUsers, prefix: str) -> None:
self.fastapi_users = fastapi_users
self.prefix = prefix

def _table_to_file_refrence(self, source: Files) -> FileRefrence:
return FileRefrence(
def _table_to_file_refrence(self, source: Files) -> FileReference:
return FileReference(
file_id=source.id,
owner=source.author_id,
mime=source.mime,
Expand All @@ -46,7 +46,7 @@ async def get_my_files(self, session: AsyncSession, user: User):

async def insert_file_to_db(
self, session: AsyncSession, user: User, file: Files
) -> FileRefrence:
) -> FileReference:
measurement = await session.execute(
select(Measurements).filter(Measurements.id == file.measurement_id)
)
Expand Down Expand Up @@ -86,25 +86,25 @@ async def delete_file(
def get_router(self) -> APIRouter:
router = APIRouter()

@router.get("/", response_model=list[FileRefrence])
@router.get("/", response_model=list[FileReference])
@cache(expire=120)
async def get_all_files(
session: AsyncSession = Depends(get_async_session),
_: User = Depends(self.fastapi_users.current_user()),
) -> list[FileRefrence]:
) -> list[FileReference]:
return await self.get_all_files(session)

@router.get("/mine", response_model=list[FileRefrence])
@router.get("/mine", response_model=list[FileReference])
async def get_my_files(
session: AsyncSession = Depends(get_async_session),
user: User = Depends(self.fastapi_users.current_user()),
) -> list[FileRefrence]:
) -> list[FileReference]:
return await self.get_my_files(session, user)

@router.post(
"/",
status_code=201,
response_model=FileRefrence,
response_model=FileReference,
responses={
404: {
"model": ErrorModel,
Expand All @@ -121,7 +121,7 @@ async def upload_new_file(
uploaded_file: UploadFile = File(...),
session: AsyncSession = Depends(get_async_session),
user: User = Depends(self.fastapi_users.current_user()),
) -> FileRefrence:
) -> FileReference:
"""
Upload a file and associate it with a measurement.
"""
Expand Down
4 changes: 2 additions & 2 deletions backend/backend/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
CreateMeasurement,
User,
UpdateMeasurement,
FileRefrence,
FileReference,
)
from .database import get_async_session, Measurements
from fastapi.routing import APIRouter
Expand All @@ -38,7 +38,7 @@ def _table_to_model(self, source: Measurements) -> Measurement:
laeq=source.laeq or 0,
files=list(
[
FileRefrence(
FileReference(
file_id=x.id,
owner=x.author_id,
mime=x.mime,
Expand Down
4 changes: 2 additions & 2 deletions backend/backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FileEntry(BaseModel):
owner: UUID4


class FileRefrence(FileEntry):
class FileReference(FileEntry):
link: str


Expand All @@ -54,7 +54,7 @@ class _protoMeasurement(BaseModel):

class Measurement(_protoMeasurement):
measurement_id: int
files: list[FileRefrence]
files: list[FileReference]


class CreateMeasurement(_protoMeasurement):
Expand Down
11 changes: 8 additions & 3 deletions frontend/editor/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
],
"rules": {
"indent": ["error", 2],
"quotes": ["error", "double"],
"semi": ["error", "always"],
//TODO: in production, use "error" in no-console
"no-console": "warn",
"no-unused-vars": ["warn", {
"argsIgnorePattern": "^_"
}],
"react/react-in-jsx-scope": "off",
"react/self-closing-comp": ["error", {
"component": true,
"html": true
}],
"comma-spacing": ["error", { "before": false, "after": true }],
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
"react/react-in-jsx-scope": "off",
"react/jsx-uses-react": "error",
"react/no-typos": "warn",
"max-len": ["error", { "code": 140 }]
Expand Down
187 changes: 94 additions & 93 deletions frontend/editor/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const hasJsxRuntime = (() => {
try {
require.resolve('react/jsx-runtime')
return true
} catch (e) {
}
catch (e) {
return false
}
})()
Expand Down Expand Up @@ -225,7 +226,7 @@ module.exports = function (webpackEnv) {
.relative(paths.appSrc, info.absoluteResourcePath)
.replace(/\\/g, '/')
: isEnvDevelopment &&
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'))
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'))
},
cache: {
type: 'filesystem',
Expand Down Expand Up @@ -420,8 +421,8 @@ module.exports = function (webpackEnv) {

plugins: [
isEnvDevelopment &&
shouldUseReactRefresh &&
require.resolve('react-refresh/babel')
shouldUseReactRefresh &&
require.resolve('react-refresh/babel')
].filter(Boolean),
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
Expand Down Expand Up @@ -591,8 +592,8 @@ module.exports = function (webpackEnv) {
// a network request.
// https://github.com/facebook/create-react-app/issues/5358
isEnvProduction &&
shouldInlineRuntimeChunk &&
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
shouldInlineRuntimeChunk &&
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
// Makes some environment variables available in index.html.
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
Expand All @@ -611,21 +612,21 @@ module.exports = function (webpackEnv) {
// Experimental hot reloading for React .
// https://github.com/facebook/react/tree/main/packages/react-refresh
isEnvDevelopment &&
shouldUseReactRefresh &&
new ReactRefreshWebpackPlugin({
overlay: false
}),
shouldUseReactRefresh &&
new ReactRefreshWebpackPlugin({
overlay: false
}),
// Watcher doesn't work well if you mistype casing in a path so we use
// a plugin that prints an error when you attempt to do this.
// See https://github.com/facebook/create-react-app/issues/240
isEnvDevelopment && new CaseSensitivePathsPlugin(),
isEnvProduction &&
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css'
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css'
}),
// Generate an asset manifest file with the following content:
// - "files" key: Mapping of all asset filenames to their corresponding
// output file so that tools can pick it up without having to parse
Expand Down Expand Up @@ -662,89 +663,89 @@ module.exports = function (webpackEnv) {
// Generate a service worker script that will precache, and keep up to date,
// the HTML & assets that are part of the webpack build.
isEnvProduction &&
fs.existsSync(swSrc) &&
new WorkboxWebpackPlugin.InjectManifest({
swSrc,
dontCacheBustURLsMatching: /\.[0-9a-f]{8}\./,
exclude: [/\.map$/, /asset-manifest\.json$/, /LICENSE/],
// Bump up the default maximum size (2mb) that's precached,
// to make lazy-loading failure scenarios less likely.
// See https://github.com/cra-template/pwa/issues/13#issuecomment-722667270
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024
}),
fs.existsSync(swSrc) &&
new WorkboxWebpackPlugin.InjectManifest({
swSrc,
dontCacheBustURLsMatching: /\.[0-9a-f]{8}\./,
exclude: [/\.map$/, /asset-manifest\.json$/, /LICENSE/],
// Bump up the default maximum size (2mb) that's precached,
// to make lazy-loading failure scenarios less likely.
// See https://github.com/cra-template/pwa/issues/13#issuecomment-722667270
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024
}),
// TypeScript type checking
useTypeScript &&
new ForkTsCheckerWebpackPlugin({
async: isEnvDevelopment,
typescript: {
typescriptPath: resolve.sync('typescript', {
basedir: paths.appNodeModules
}),
configOverwrite: {
compilerOptions: {
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
skipLibCheck: true,
inlineSourceMap: false,
declarationMap: false,
noEmit: true,
incremental: true,
tsBuildInfoFile: paths.appTsBuildInfoFile
}
},
context: paths.appPath,
diagnosticOptions: {
syntactic: true
},
mode: 'write-references'
// profile: true,
new ForkTsCheckerWebpackPlugin({
async: isEnvDevelopment,
typescript: {
typescriptPath: resolve.sync('typescript', {
basedir: paths.appNodeModules
}),
configOverwrite: {
compilerOptions: {
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
skipLibCheck: true,
inlineSourceMap: false,
declarationMap: false,
noEmit: true,
incremental: true,
tsBuildInfoFile: paths.appTsBuildInfoFile
}
},
issue: {
// This one is specifically to match during CI tests,
// as micromatch doesn't match
// '../cra-template-typescript/template/src/App.tsx'
// otherwise.
include: [
{ file: '../**/src/**/*.{ts,tsx}' },
{ file: '**/src/**/*.{ts,tsx}' }
],
exclude: [
{ file: '**/src/**/__tests__/**' },
{ file: '**/src/**/?(*.){spec|test}.*' },
{ file: '**/src/setupProxy.*' },
{ file: '**/src/setupTests.*' }
]
context: paths.appPath,
diagnosticOptions: {
syntactic: true
},
logger: {
infrastructure: 'silent'
}
}),
mode: 'write-references'
// profile: true,
},
issue: {
// This one is specifically to match during CI tests,
// as micromatch doesn't match
// '../cra-template-typescript/template/src/App.tsx'
// otherwise.
include: [
{ file: '../**/src/**/*.{ts,tsx}' },
{ file: '**/src/**/*.{ts,tsx}' }
],
exclude: [
{ file: '**/src/**/__tests__/**' },
{ file: '**/src/**/?(*.){spec|test}.*' },
{ file: '**/src/setupProxy.*' },
{ file: '**/src/setupTests.*' }
]
},
logger: {
infrastructure: 'silent'
}
}),
!disableESLintPlugin &&
new ESLintPlugin({
// Plugin options
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
context: paths.appSrc,
cache: true,
cacheLocation: path.resolve(
paths.appNodeModules,
'.cache/.eslintcache'
),
// ESLint class options
cwd: paths.appPath,
resolvePluginsRelativeTo: __dirname,
baseConfig: {
extends: [require.resolve('eslint-config-react-app/base')],
rules: {
...(!hasJsxRuntime && {
'react/react-in-jsx-scope': 'error'
})
}
new ESLintPlugin({
// Plugin options
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
context: paths.appSrc,
cache: true,
cacheLocation: path.resolve(
paths.appNodeModules,
'.cache/.eslintcache'
),
// ESLint class options
cwd: paths.appPath,
resolvePluginsRelativeTo: __dirname,
baseConfig: {
extends: [require.resolve('eslint-config-react-app/base')],
rules: {
...(!hasJsxRuntime && {
'react/react-in-jsx-scope': 'off'
})
}
})
}
})
].filter(Boolean),
// Turn off performance processing because we utilize
// our own hints via the FileSizeReporter
Expand Down
2 changes: 1 addition & 1 deletion frontend/editor/src/api/core/OpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type OpenAPIConfig = {

export const OpenAPI: OpenAPIConfig = {
BASE: '',
VERSION: '0.9.5',
VERSION: '0.10.0',
WITH_CREDENTIALS: false,
CREDENTIALS: 'include',
TOKEN: undefined,
Expand Down
Loading

0 comments on commit 2ceef03

Please sign in to comment.