From: Daniel Karbach Date: Wed, 17 Aug 2022 13:25:50 +0000 (+0200) Subject: tech data model X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=68aabaf6da8ed6e675bdea728702d5bd75066964;p=alttp.git tech data model --- diff --git a/app/Http/Controllers/TechniqueController.php b/app/Http/Controllers/TechniqueController.php new file mode 100644 index 0000000..97a45f0 --- /dev/null +++ b/app/Http/Controllers/TechniqueController.php @@ -0,0 +1,16 @@ +authorize('view', $tech); + return $tech->toJson(); + } + +} diff --git a/app/Models/Technique.php b/app/Models/Technique.php new file mode 100644 index 0000000..202c455 --- /dev/null +++ b/app/Models/Technique.php @@ -0,0 +1,11 @@ +isAdmin(); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\Technique $technique + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, Technique $technique) + { + return $user->isAdmin(); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Technique $technique + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, Technique $technique) + { + return $user->isAdmin(); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\Technique $technique + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, Technique $technique) + { + return $user->isAdmin(); + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Technique $technique + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, Technique $technique) + { + return $user->isAdmin(); + } +} diff --git a/database/migrations/2022_08_03_074936_create_techniques_table.php b/database/migrations/2022_08_03_074936_create_techniques_table.php new file mode 100644 index 0000000..5951115 --- /dev/null +++ b/database/migrations/2022_08_03_074936_create_techniques_table.php @@ -0,0 +1,35 @@ +id(); + $table->string('name')->unique(); + $table->text('title'); + $table->text('short'); + $table->text('description'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('techniques'); + } +}; diff --git a/resources/js/components/App.js b/resources/js/components/App.js index e5d3578..1f188fb 100644 --- a/resources/js/components/App.js +++ b/resources/js/components/App.js @@ -4,6 +4,7 @@ import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'; import Header from './common/Header'; import AlttpSeed from './pages/AlttpSeed'; +import Technique from './pages/Technique'; import Tournament from './pages/Tournament'; import User from './pages/User'; import AlttpBaseRomProvider from '../helpers/AlttpBaseRomContext'; @@ -55,6 +56,7 @@ const App = () => {
} /> + } /> } /> } /> } /> diff --git a/resources/js/components/pages/Technique.js b/resources/js/components/pages/Technique.js new file mode 100644 index 0000000..19b56b7 --- /dev/null +++ b/resources/js/components/pages/Technique.js @@ -0,0 +1,57 @@ +import axios from 'axios'; +import React, { useEffect, useState } from 'react'; +import { useParams } from 'react-router-dom'; + +import ErrorBoundary from '../common/ErrorBoundary'; +import ErrorMessage from '../common/ErrorMessage'; +import Loading from '../common/Loading'; +import NotFound from '../pages/NotFound'; +import Detail from '../techniques/Detail'; + +const Technique = () => { + const params = useParams(); + const { name } = params; + + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + const [technique, setTechnique] = useState(null); + + useEffect(() => { + const ctrl = new AbortController(); + setLoading(true); + axios + .get(`/api/tech/${name}`, { signal: ctrl.signal }) + .then(response => { + setError(null); + setLoading(false); + setTechnique(response.data); + window.document.title = response.data.title; + }) + .catch(error => { + setError(error); + setLoading(false); + setTechnique(null); + }); + return () => { + ctrl.abort(); + }; + }, [name]); + + if (loading) { + return ; + } + + if (error) { + return ; + } + + if (!technique) { + return ; + } + + return + + ; +}; + +export default Technique; diff --git a/resources/js/components/techniques/Detail.js b/resources/js/components/techniques/Detail.js new file mode 100644 index 0000000..88ce594 --- /dev/null +++ b/resources/js/components/techniques/Detail.js @@ -0,0 +1,17 @@ +import PropTypes from 'prop-types'; +import React from 'react'; +import { Container } from 'react-bootstrap'; + +const Detail = ({ technique }) => +

{technique.title}

+
+; + +Detail.propTypes = { + technique: PropTypes.shape({ + description: PropTypes.string, + title: PropTypes.string, + }), +}; + +export default Detail; diff --git a/routes/api.php b/routes/api.php index 1b0ea84..7ae308e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -42,6 +42,8 @@ Route::post('rounds/{round}/lock', 'App\Http\Controllers\RoundController@lock'); Route::post('rounds/{round}/setSeed', 'App\Http\Controllers\RoundController@setSeed'); Route::post('rounds/{round}/unlock', 'App\Http\Controllers\RoundController@unlock'); +Route::get('tech/{tech:name}', 'App\Http\Controllers\TechniqueController@single'); + Route::get('tournaments/{id}', 'App\Http\Controllers\TournamentController@single'); Route::post('tournaments/{tournament}/apply', 'App\Http\Controllers\TournamentController@apply'); Route::post('tournaments/{tournament}/close', 'App\Http\Controllers\TournamentController@close');