Skip to content
Snippets Groups Projects
Commit e1211e0a authored by robban64's avatar robban64
Browse files

fix: return media object instead of media_id

parent 9ec6c20c
No related branches found
No related tags found
No related merge requests found
Pipeline #42682 passed with warnings
Showing
with 42 additions and 38 deletions
......@@ -26,7 +26,7 @@ it('dispatches no actions when failing to get competitions', async () => {
})
it('dispatches correct actions when setting slide', () => {
const testSlide: Slide = { competition_id: 0, id: 5, order: 5, timer: 20, title: '' }
const testSlide: Slide = { competition_id: 0, id: 5, order: 5, timer: 20, title: '', background_image_id: 0 }
const expectedActions = [{ type: Types.SET_PRESENTATION_SLIDE, payload: testSlide }]
const store = mockStore({})
setCurrentSlide(testSlide)(store.dispatch)
......
......@@ -38,13 +38,14 @@ export interface Slide {
order: number
timer: number
title: string
background_image?: Media
}
export interface Competition extends NameID {
font: string
city_id: number
year: number
background_image_id: number
background_image?: Media
}
export interface Team extends NameID {
......@@ -69,7 +70,7 @@ export interface QuestionAnswer {
id: number
question_id: number
team_id: number
data: string
answer: string
score: number
}
......@@ -83,8 +84,7 @@ export interface Component {
}
export interface ImageComponent extends Component {
media_id: number
filename: string
media: Media
}
export interface TextComponent extends Component {
......
......@@ -7,6 +7,7 @@ export interface RichCompetition {
city_id: number
slides: RichSlide[]
teams: RichTeam[]
background_image?: Media
}
export interface RichSlide {
......@@ -15,9 +16,9 @@ export interface RichSlide {
timer: number
title: string
competition_id: number
background_image?: Media
components: Component[]
questions: RichQuestion[]
medias: Media[]
}
export interface RichTeam {
......
......@@ -5,7 +5,15 @@ import ImageComponentDisplay from './ImageComponentDisplay'
it('renders competition settings', () => {
render(
<ImageComponentDisplay
component={{ id: 0, x: 0, y: 0, w: 0, h: 0, data: { media_id: 0, filename: '' }, type_id: 2 }}
component={{
id: 0,
x: 0,
y: 0,
w: 0,
h: 0,
media: { id: 0, mediatype_id: 0, user_id: 0, filename: '' },
type_id: 2,
}}
width={0}
height={0}
/>
......
......@@ -10,7 +10,7 @@ type ImageComponentProps = {
const ImageComponentDisplay = ({ component, width, height }: ImageComponentProps) => {
return (
<img
src={`http://localhost:5000/static/images/${component.filename}`}
src={`http://localhost:5000/static/images/${component.media?.filename}`}
height={height}
width={width}
draggable={false}
......
......@@ -65,7 +65,7 @@ const Images = ({ activeSlide, competitionId }: ImagesProps) => {
const handleCloseimageClick = async (image: ImageComponent) => {
// Removes selected image component and deletes its file from the server.
await axios
.delete(`/api/media/images/${image.media_id}`)
.delete(`/api/media/images/${image.media?.id}`)
.then(() => {
dispatch(getEditorCompetition(competitionId))
})
......@@ -98,9 +98,9 @@ const Images = ({ activeSlide, competitionId }: ImagesProps) => {
images.map((image) => (
<div key={image.id}>
<ListItem divider button>
<ImportedImage src={`http://localhost:5000/static/images/thumbnail_${image.filename}`} />
<ImportedImage src={`http://localhost:5000/static/images/thumbnail_${image.media?.filename}`} />
<Center>
<ListItemText primary={image.filename} />
<ListItemText primary={image.media?.filename} />
</Center>
<CloseIcon onClick={() => handleCloseimageClick(image)} />
</ListItem>
......
......@@ -16,6 +16,7 @@ const initialState: EditorState = {
city_id: 1,
slides: [],
teams: [],
background_image: undefined,
},
activeSlideId: -1,
loading: true,
......
......@@ -19,6 +19,7 @@ const initialState: PresentationState = {
slides: [],
year: 0,
teams: [],
background_image: undefined,
},
slide: {
competition_id: 0,
......@@ -26,6 +27,7 @@ const initialState: PresentationState = {
order: 0,
timer: 0,
title: '',
background_image: undefined,
},
code: '',
timer: {
......
......@@ -10,12 +10,12 @@ schema = QuestionAnswerDTO.schema
list_schema = QuestionAnswerDTO.list_schema
question_answer_parser = reqparse.RequestParser()
question_answer_parser.add_argument("data", type=dict, required=True, location="json")
question_answer_parser.add_argument("answer", type=str, required=True, location="json")
question_answer_parser.add_argument("score", type=int, required=True, location="json")
question_answer_parser.add_argument("question_id", type=int, required=True, location="json")
question_answer_edit_parser = reqparse.RequestParser()
question_answer_edit_parser.add_argument("data", type=dict, default=None, location="json")
question_answer_edit_parser.add_argument("answer", type=str, default=None, location="json")
question_answer_edit_parser.add_argument("score", type=int, default=None, location="json")
......
......@@ -18,6 +18,9 @@ competition_parser.add_argument("name", type=str, location="json")
competition_parser.add_argument("year", type=int, location="json")
competition_parser.add_argument("city_id", type=int, location="json")
competition_edit_parser = competition_parser.copy()
competition_edit_parser.add_argument("background_image_id", default=None, type=int, location="json")
competition_search_parser = search_parser.copy()
competition_search_parser.add_argument("name", type=str, default=None, location="args")
competition_search_parser.add_argument("year", type=int, default=None, location="args")
......@@ -48,7 +51,7 @@ class Competitions(Resource):
@check_jwt(editor=True)
def put(self, competition_id):
args = competition_parser.parse_args(strict=True)
args = competition_edit_parser.parse_args(strict=True)
item = dbc.get.one(Competition, competition_id)
item = dbc.edit.default(item, **args)
......
......@@ -13,6 +13,7 @@ slide_parser = reqparse.RequestParser()
slide_parser.add_argument("order", type=int, default=None, location="json")
slide_parser.add_argument("title", type=str, default=None, location="json")
slide_parser.add_argument("timer", type=int, default=None, location="json")
slide_parser.add_argument("background_image_id", default=None, type=int, location="json")
@api.route("")
......
......@@ -42,8 +42,7 @@ class SlideSchemaRich(RichSchema):
title = ma.auto_field()
timer = ma.auto_field()
competition_id = ma.auto_field()
background_image_id = ma.auto_field()
background_image = ma.Function(lambda x: x.background_image.filename if x.background_image is not None else "")
background_image = fields.Nested(schemas.MediaSchema, many=False)
questions = fields.Nested(QuestionSchemaRich, many=True)
components = fields.Nested(schemas.ComponentSchema, many=True)
......@@ -56,8 +55,7 @@ class CompetitionSchemaRich(RichSchema):
name = ma.auto_field()
year = ma.auto_field()
city_id = ma.auto_field()
background_image_id = ma.auto_field()
background_image = ma.Function(lambda x: x.background_image.filename if x.background_image is not None else "")
background_image = fields.Nested(schemas.MediaSchema, many=False)
slides = fields.Nested(
SlideSchemaRich,
......
......@@ -65,7 +65,7 @@ class QuestionAnswerSchema(BaseSchema):
model = models.QuestionAnswer
id = ma.auto_field()
data = ma.Function(lambda obj: obj.data)
answer = ma.auto_field()
score = ma.auto_field()
question_id = ma.auto_field()
team_id = ma.auto_field()
......@@ -116,8 +116,7 @@ class SlideSchema(BaseSchema):
title = ma.auto_field()
timer = ma.auto_field()
competition_id = ma.auto_field()
background_image_id = ma.auto_field()
background_image = ma.Function(lambda x: x.background_image.filename if x.background_image is not None else "")
background_image = fields.Nested(MediaSchema, many=False)
class TeamSchema(BaseSchema):
......@@ -148,20 +147,13 @@ class CompetitionSchema(BaseSchema):
name = ma.auto_field()
year = ma.auto_field()
city_id = ma.auto_field()
background_image_id = ma.auto_field()
background_image = ma.Function(lambda x: x.background_image.filename if x.background_image is not None else "")
background_image = fields.Nested(MediaSchema, many=False)
class ComponentSchema(BaseSchema):
class Meta(BaseSchema.Meta):
model = models.Component
@post_dump
def handle_filename(self, data, *args, **kwargs):
if data["filename"] == "":
del data["filename"]
return data
id = ma.auto_field()
x = ma.auto_field()
y = ma.auto_field()
......@@ -171,5 +163,4 @@ class ComponentSchema(BaseSchema):
type_id = ma.auto_field()
text = fields.fields.String()
media_id = fields.fields.Integer()
filename = ma.Function(lambda x: x.media.filename if hasattr(x, "media_id") else "")
media = fields.Nested(MediaSchema, many=False)
......@@ -246,5 +246,5 @@ def question_alternative(text, value, question_id):
return db_add(QuestionAlternative(text, value, question_id))
def question_answer(data, score, question_id, team_id):
return db_add(QuestionAnswer(data, score, question_id, team_id))
def question_answer(answer, score, question_id, team_id):
return db_add(QuestionAnswer(answer, score, question_id, team_id))
......@@ -77,8 +77,7 @@ def slide_to_competition(item_slide_old, item_competition):
item_slide_new.body = item_slide_old.body
item_slide_new.timer = item_slide_old.timer
item_slide_new.settings = item_slide_old.settings
# TODO: Add background image
item_slide_new.background_image_id = item_slide_old.background_image_id
for item_component in item_slide_old.components:
_component(item_component, item_slide_new)
......@@ -109,6 +108,7 @@ def competition(item_competition_old):
item_competition_old.font,
)
# TODO: Add background image
item_competition_new.background_image_id = item_competition_old.background_image_id
for item_slide in item_competition_old.slides:
slide_to_competition(item_slide, item_competition_new)
......
from app.core import bcrypt, db
from app.database import Dictionary
from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property
from app.database.types import ID_IMAGE_COMPONENT, ID_TEXT_COMPONENT
......@@ -175,7 +174,7 @@ class QuestionAlternative(db.Model):
class QuestionAnswer(db.Model):
__table_args__ = (db.UniqueConstraint("question_id", "team_id"),)
id = db.Column(db.Integer, primary_key=True)
data = db.Column(Dictionary(), nullable=False)
answer = db.Column(db.String(STRING_SIZE), nullable=False)
score = db.Column(db.Integer, nullable=False, default=0)
question_id = db.Column(db.Integer, db.ForeignKey("question.id"), nullable=False)
......
......@@ -20,7 +20,7 @@ class Config:
class DevelopmentConfig(Config):
DEBUG = False
DEBUG = True
SQLALCHEMY_ECHO = False
# HOST = "localhost"
# PORT = 5432
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment