diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..765f02d --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,49 @@ +name: Codecov Coverage + +on: + push: + branches: + - main + - codecov-workflows + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + steps: + # Checkout code + - name: Checkout code + uses: actions/checkout@v2 + + # Setup .NET environment + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x # Use the version your project requires + + # Restore dependencies + - name: Restore dependencies + run: dotnet restore + + # Build the project + - name: Build + run: dotnet build --no-restore + + # Step 5: Run tests and collect code coverage + - name: Test and calculate coverage + run: | + dotnet test --no-build --verbosity normal \ + /p:CollectCoverage=true /p:CoverletOutputFormat=opencover \ + /p:CoverletOutput=./TestResults/coverage.opencover.xml + + # Step 6: Upload the code coverage report to Codecov + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} # Add the Codecov token in the GitHub secrets + files: ./TestResults/coverage.opencover.xml # Ensure the correct path for the coverage file + flags: unittests + fail_ci_if_error: true \ No newline at end of file diff --git a/.runsettings b/.runsettings new file mode 100644 index 0000000..e64ddcc --- /dev/null +++ b/.runsettings @@ -0,0 +1,13 @@ + + + + + + opencover + ./TestResults + [Tests*]* + + + + + diff --git a/Chemistry Cafe API.csproj b/Chemistry Cafe API.csproj index 4d0a3af..533ec80 100644 --- a/Chemistry Cafe API.csproj +++ b/Chemistry Cafe API.csproj @@ -9,9 +9,20 @@ Linux . AnyCPU + true + opencover + ../TestResults/ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/chemistry-cafe-database.sql b/chemistry-cafe-database.sql index 67380fb..3442c22 100644 --- a/chemistry-cafe-database.sql +++ b/chemistry-cafe-database.sql @@ -2,6 +2,7 @@ CREATE TABLE `User` ( `uuid` char(38) NOT NULL, `log_in_info` varchar(1000) DEFAULT NULL, `isDel` tinyint NOT NULL DEFAULT '0', + `role` ENUM('unverified', 'verified', 'admin') NOT NULL DEFAULT 'unverified', PRIMARY KEY (`uuid`), UNIQUE KEY `uuid` (`uuid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index b4b0d5e..1a545d8 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -8,10 +8,12 @@ import './index.css' const rootElement = document.getElementById('root'); const root = createRoot(rootElement!); - +//"534701394161-6gcjh4gd19u5p40gtagdl8i0bkg28rvg.apps.googleusercontent.com" preexisting +//"505816606185-4lkg5cmmod039i5kclktij01ct5in2ug.apps.googleusercontent.com" jmhh +//"257697450661-a69l9bv939uuso551n6pcf1gngpv9ql0.apps.googleusercontent.com"> chemcafe root.render( - + diff --git a/frontend/src/webPages/Roles/RoleManagement.tsx b/frontend/src/webPages/Roles/RoleManagement.tsx new file mode 100644 index 0000000..7a571f3 --- /dev/null +++ b/frontend/src/webPages/Roles/RoleManagement.tsx @@ -0,0 +1,138 @@ +import { useEffect, useState } from 'react'; +import axios from 'axios'; +import Button from '@mui/material/Button'; +import Box from '@mui/material/Box'; +import Typography from '@mui/material/Typography'; +import Modal from '@mui/material/Modal'; +import { Footer } from '../Components/HeaderFooter'; + +interface User { + id: string; + name: string; + email: string; + role: 'unverified' | 'verified' | 'admin'; // Define the possible roles +} + +const RoleManagement = () => { + const [users, setUsers] = useState([]); + const [selectedUser, setSelectedUser] = useState(null); + const [roleModalOpen, setRoleModalOpen] = useState(false); + + const handleRoleModalOpen = (user: User) => { + setSelectedUser(user); + setRoleModalOpen(true); + }; + + const handleRoleModalClose = () => { + setSelectedUser(null); + setRoleModalOpen(false); + }; + + // Fetch users from the backend + useEffect(() => { + const fetchUsers = async () => { + try { + const response = await axios.get('http://localhost:5173/api/User/all'); // Adjust the endpoint as needed + setUsers(response.data); + } catch (error) { + console.error('Error fetching users:', error); + } + }; + + fetchUsers(); + }, []); + + // Update user role + const updateUserRole = async (userId: string, newRole: 'unverified' | 'verified' | 'admin') => { + try { + await axios.patch(`/api/users/${userId}`, { role: newRole }); // Adjust the endpoint as needed + setUsers(prevUsers => + prevUsers.map(user => + user.id === userId ? { ...user, role: newRole } : user + ) + ); + handleRoleModalClose(); + } catch (error) { + console.error('Error updating user role:', error); + } + }; + + const style = { + position: 'absolute' as 'absolute', + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + width: 400, + bgcolor: 'background.paper', + border: '2px solid #000', + boxShadow: 24, + p: 4, + }; + + return ( +
+ + + Role Management + + + +
+ {users.map(user => ( + + {user.name} + Email: {user.email} + Role: {user.role} + + + ))} +
+ + + + Change Role + {selectedUser && ( + <> + User: {selectedUser.name} + Current Role: {selectedUser.role} + + + + + + )} + + + +
+
+
+
+ ); +}; + +export default RoleManagement; diff --git a/frontend/src/webPages/RoutingRenders/App.tsx b/frontend/src/webPages/RoutingRenders/App.tsx index dad7262..abd6625 100644 --- a/frontend/src/webPages/RoutingRenders/App.tsx +++ b/frontend/src/webPages/RoutingRenders/App.tsx @@ -3,6 +3,7 @@ import Settings from '../Settings/settings'; import LoggedIn from '../LogIn/loggedIn'; import FamilyPage from '../Family/family'; import LogIn from '../LogIn/logIn'; +import RoleManagement from '../Roles/RoleManagement'; function App() { return ( @@ -12,6 +13,7 @@ function App() { } /> } /> } /> + } /> } /> diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a95b566 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "chemistry-cafe-api", + "lockfileVersion": 3, + "requires": true, + "packages": {} +}