Skip to content
Snippets Groups Projects
Commit fb697a32 authored by robban64's avatar robban64
Browse files
parents 4d56dbb9 1bb8a56d
No related branches found
No related tags found
No related merge requests found
Pipeline #42124 passed
import axios from 'axios'
import { AppDispatch } from './../store'
import Types from './types'
export const getStatistics = () => async (dispatch: AppDispatch) => {
await axios
.get('/api/misc/statistics')
.then((res) => {
dispatch({
type: Types.SET_STATISTICS,
payload: res.data,
})
})
.catch((err) => console.log(err))
}
......@@ -29,4 +29,5 @@ export default {
SET_CITIES_TOTAL: 'SET_CITIES_TOTAL',
SET_CITIES_COUNT: 'SET_CITIES_COUNT',
SET_TYPES: 'SET_TYPES',
SET_STATISTICS: 'SET_STATISTICS',
}
......@@ -20,6 +20,7 @@ import React, { useEffect } from 'react'
import { Link, Route, Switch, useRouteMatch } from 'react-router-dom'
import { getCities } from '../../actions/cities'
import { getRoles } from '../../actions/roles'
import { getStatistics } from '../../actions/statistics'
import { getTypes } from '../../actions/typesAction'
import { logoutUser } from '../../actions/user'
import { useAppDispatch, useAppSelector } from '../../hooks'
......@@ -71,6 +72,7 @@ const AdminView: React.FC = () => {
dispatch(getCities())
dispatch(getRoles())
dispatch(getTypes())
dispatch(getStatistics())
}, [])
const menuAdminItems = [
......
import { Box, Typography } from '@material-ui/core'
import React, { useEffect } from 'react'
import { getCompetitions } from '../../../../actions/competitions'
import { useAppDispatch, useAppSelector } from '../../../../hooks'
import React from 'react'
import { useAppSelector } from '../../../../hooks'
const NumberOfCompetitions: React.FC = () => {
const competitions = useAppSelector((state) => state.competitions.competitions)
const dispatch = useAppDispatch()
const competitions = useAppSelector((state) => state.statistics.competitions)
const handleCount = () => {
if (competitions.length >= 1000000) {
;<div>{competitions.length / 1000000 + 'M'}</div>
} else if (competitions.length >= 1000) {
;<div>{competitions.length / 1000 + 'K'}</div>
if (competitions >= 1000000) {
;<div>{competitions / 1000000 + 'M'}</div>
} else if (competitions >= 1000) {
;<div>{competitions / 1000 + 'K'}</div>
}
return <div>{competitions.length}</div>
return <div>{competitions}</div>
}
useEffect(() => {
dispatch(getCompetitions())
}, [])
return (
<div>
<Box width="100%" height="100%">
......
......@@ -4,7 +4,7 @@ import { getCities } from '../../../../actions/cities'
import { useAppDispatch, useAppSelector } from '../../../../hooks'
const NumberOfRegions: React.FC = () => {
const regions = useAppSelector((state) => state.cities.total)
const regions = useAppSelector((state) => state.statistics.regions)
const dispatch = useAppDispatch()
const handleCount = () => {
......
......@@ -4,7 +4,7 @@ import { getSearchUsers } from '../../../../actions/searchUser'
import { useAppDispatch, useAppSelector } from '../../../../hooks'
const NumberOfUsers: React.FC = () => {
const usersTotal = useAppSelector((state) => state.searchUsers.total)
const usersTotal = useAppSelector((state) => state.statistics.users)
const dispatch = useAppDispatch()
const handleCount = () => {
......
......@@ -7,6 +7,7 @@ import editorReducer from './editorReducer'
import presentationReducer from './presentationReducer'
import rolesReducer from './rolesReducer'
import searchUserReducer from './searchUserReducer'
import statisticsReducer from './statisticsReducer'
import typesReducer from './typesReducer'
import uiReducer from './uiReducer'
import userReducer from './userReducer'
......@@ -22,5 +23,6 @@ const allReducers = combineReducers({
roles: rolesReducer,
searchUsers: searchUserReducer,
types: typesReducer,
statistics: statisticsReducer,
})
export default allReducers
import { AnyAction } from 'redux'
import Types from '../actions/types'
interface StatisticsState {
users: number
competitions: number
regions: number
}
const initialState: StatisticsState = {
users: 0,
competitions: 0,
regions: 0,
}
export default function (state = initialState, action: AnyAction) {
switch (action.type) {
case Types.SET_STATISTICS:
state = action.payload as StatisticsState
return state
default:
return state
}
}
import app.database.controller as dbc
from app.apis import check_jwt, item_response, list_response
from app.core import http_codes
from app.core.dto import MiscDTO
from app.database.models import City, ComponentType, MediaType, QuestionType, Role, ViewType
from app.database.models import City, Competition, ComponentType, MediaType, QuestionType, Role, User, ViewType
from flask_jwt_extended import jwt_required
from flask_restx import Resource, reqparse
......@@ -72,3 +73,13 @@ class Cities(Resource):
dbc.delete.default(item)
items = dbc.get.all(City)
return list_response(city_schema.dump(items))
@api.route("/statistics")
class Statistics(Resource):
@check_jwt(editor=True)
def get(self):
user_count = User.query.count()
competition_count = Competition.query.count()
region_count = City.query.count()
return {"users": user_count, "competitions": competition_count, "regions": region_count}, http_codes.OK
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment