From f3019db1fa37b7a503eead7ae1d90052b92b53d4 Mon Sep 17 00:00:00 2001
From: robban64 <carl@schonfelder.se>
Date: Thu, 8 Apr 2021 10:02:23 +0200
Subject: [PATCH] fix: server response and small changes in client

---
 client/src/interfaces/Competition.ts          |  4 +---
 .../pages/admin/components/AddCompetition.tsx |  1 -
 .../admin/components/CompetitionManager.tsx   |  2 +-
 .../pages/admin/components/UserManager.tsx    |  4 ++--
 server/app/core/dto.py                        |  4 ++--
 server/app/core/rich_schemas.py               |  3 ---
 server/app/core/schemas.py                    | 21 +++++++++++++++++++
 7 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/client/src/interfaces/Competition.ts b/client/src/interfaces/Competition.ts
index 7a9c7032..d36d97da 100644
--- a/client/src/interfaces/Competition.ts
+++ b/client/src/interfaces/Competition.ts
@@ -1,8 +1,6 @@
-import { City } from './City'
-
 export interface Competition {
   name: string
   id: number
-  city: City
+  city_id: number
   year: number
 }
diff --git a/client/src/pages/admin/components/AddCompetition.tsx b/client/src/pages/admin/components/AddCompetition.tsx
index d80195e5..b67714ba 100644
--- a/client/src/pages/admin/components/AddCompetition.tsx
+++ b/client/src/pages/admin/components/AddCompetition.tsx
@@ -59,7 +59,6 @@ const AddCompetition: React.FC = (props: any) => {
       name: values.model.name,
       year: values.model.year,
       city_id: selectedCity?.id as number,
-      style_id: 1,
     }
     await axios
       .post<ServerResponse>('/competitions', params)
diff --git a/client/src/pages/admin/components/CompetitionManager.tsx b/client/src/pages/admin/components/CompetitionManager.tsx
index ff73a994..2acce64b 100644
--- a/client/src/pages/admin/components/CompetitionManager.tsx
+++ b/client/src/pages/admin/components/CompetitionManager.tsx
@@ -152,7 +152,7 @@ const CompetitionManager: React.FC = (props: any) => {
                       {row.name}
                     </Button>
                   </TableCell>
-                  <TableCell align="right">{cities.find((city) => city.id === row.city.id)?.name || ''}</TableCell>
+                  <TableCell align="right">{cities.find((city) => city.id === row.city_id)?.name || ''}</TableCell>
                   <TableCell align="right">{row.year}</TableCell>
                   <TableCell align="right">
                     <Button onClick={(event) => handleClick(event, row.id)}>
diff --git a/client/src/pages/admin/components/UserManager.tsx b/client/src/pages/admin/components/UserManager.tsx
index bc3d55d4..7bea8713 100644
--- a/client/src/pages/admin/components/UserManager.tsx
+++ b/client/src/pages/admin/components/UserManager.tsx
@@ -136,8 +136,8 @@ const UserManager: React.FC = (props: any) => {
               <MenuItem value={noFilterText} onClick={() => handleFilterChange({ ...filterParams, roleId: undefined })}>
                 {noFilterText}
               </MenuItem>
-              {cities &&
-                cities.map((role) => (
+              {roles &&
+                roles.map((role) => (
                   <MenuItem
                     key={role.name}
                     value={role.name}
diff --git a/server/app/core/dto.py b/server/app/core/dto.py
index 3378a17b..5eca7963 100644
--- a/server/app/core/dto.py
+++ b/server/app/core/dto.py
@@ -13,13 +13,13 @@ class AuthDTO:
 class UserDTO:
     api = Namespace("users")
     schema = rich_schemas.UserSchemaRich(many=False)
-    list_schema = rich_schemas.UserSchemaRich(many=True)
+    list_schema = schemas.UserSchema(many=True)
 
 
 class CompetitionDTO:
     api = Namespace("competitions")
     schema = rich_schemas.CompetitionSchemaRich(many=False)
-    list_schema = rich_schemas.CompetitionSchemaRich(many=True)
+    list_schema = schemas.CompetitionSchema(many=True)
 
 
 class SlideDTO:
diff --git a/server/app/core/rich_schemas.py b/server/app/core/rich_schemas.py
index f9510488..e4dc4a84 100644
--- a/server/app/core/rich_schemas.py
+++ b/server/app/core/rich_schemas.py
@@ -1,7 +1,6 @@
 import app.core.models as models
 import app.core.schemas as schemas
 from app.core import ma
-from marshmallow import fields as fields2
 from marshmallow_sqlalchemy import fields
 
 
@@ -34,5 +33,3 @@ class CompetitionSchemaRich(RichSchema):
     city = fields.Nested(schemas.CitySchema, many=False)
 
 
-class UserListSchema(ma.Schema):
-    users = fields2.Nested(UserSchemaRich, many=False)
diff --git a/server/app/core/schemas.py b/server/app/core/schemas.py
index 0450034a..26fba469 100644
--- a/server/app/core/schemas.py
+++ b/server/app/core/schemas.py
@@ -70,3 +70,24 @@ class TeamSchema(BaseSchema):
     id = ma.auto_field()
     name = ma.auto_field()
     competition_id = ma.auto_field()
+
+
+class UserSchema(BaseSchema):
+    class Meta(BaseSchema.Meta):
+        model = models.User
+
+    id = ma.auto_field()
+    name = ma.auto_field()
+    email = ma.auto_field()
+    role_id = ma.auto_field()
+    city_id = ma.auto_field()
+
+
+class CompetitionSchema(BaseSchema):
+    class Meta(BaseSchema.Meta):
+        model = models.Competition
+
+    id = ma.auto_field()
+    name = ma.auto_field()
+    year = ma.auto_field()
+    city_id = ma.auto_field()
-- 
GitLab