Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed May 21, 2024
1 parent f13ea45 commit d6c0606
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 38 deletions.
34 changes: 28 additions & 6 deletions backend/api/serializers/checks_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@


class FileExtensionSerializer(serializers.ModelSerializer):
extension = serializers.CharField(
required=True,
max_length=10
)

class Meta:
model = FileExtension
fields = ["extension"]
fields = ["id", "extension"]


class StructureCheckSerializer(serializers.ModelSerializer):
Expand All @@ -33,24 +38,41 @@ def validate(self, attrs):
"""Validate the structure check"""
project: Project = self.context["project"]

# The structure check path should not exist already
if project.structure_checks.filter(path=attrs["path"]).exists():
raise ValidationError(_("project.error.structure_checks.already_existing"))

# The same extension should not be in both blocked and obligated
blocked = set([ext["extension"] for ext in attrs["blocked_extensions"]])
obligated = set([ext["extension"] for ext in attrs["obligated_extensions"]])

if blocked.intersection(obligated):
raise ValidationError(_("project.error.structure_checks.blocked_obligated"))

return attrs

def create(self, validated_data):
def create(self, validated_data: dict) -> StructureCheck:
"""Create a new structure check"""
blocked = validated_data.pop("blocked_extensions")
obligated = validated_data.pop("obligated_extensions")
check: StructureCheck = StructureCheck.objects.create(**validated_data)

check: StructureCheck = StructureCheck.objects.create(
path=validated_data.pop("path"),
**validated_data
)

for ext in obligated:
check.obligated_extensions.create(**ext)
ext, _ = FileExtension.objects.get_or_create(
extension=ext["extension"]
)
check.obligated_extensions.add(ext)

# Add blocked extensions

for ext in blocked:
check.blocked_extensions.create(**ext)
ext, _ = FileExtension.objects.get_or_create(
extension=ext["extension"]
)
check.blocked_extensions.add(ext)

return check

Expand Down
1 change: 1 addition & 0 deletions backend/api/views/project_view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from rest_framework.exceptions import ValidationError
from rest_framework.parsers import MultiPartParser

from api.models.group import Group
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/forms/ErrorMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Message from 'primevue/message';
/* Props */
defineProps<{ field: any }>();
</script>

<template>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/projects/ProjectForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const rules = computed(() => {
});
const v$ = useVuelidate(rules, form, {
$scope: 'form'
$scope: 'form',
});
/**
Expand Down Expand Up @@ -119,7 +119,7 @@ watchEffect(() => {
<div class="grid">
<!-- Start date of the project -->
<div class="field col">
<label for="projectStartDate">{{ t('views.projects.start_date') }}</label>
<label for="projectStartDate">{{ t('views.projects.startDate') }}</label>
<Calendar
id="projectStartDate"
class="w-full"
Expand Down Expand Up @@ -152,15 +152,15 @@ watchEffect(() => {
<!-- Group size for the project -->
<div class="field col">
<label for="groupSize">
{{ t('views.projects.group_size') }}
{{ t('views.projects.groupSize') }}
</label>
<InputNumber input-id="groupSize" class="w-full" v-model="form.group_size" :min="1" />
<ErrorMessage :field="v$.group_size" />
</div>

<!-- Max score for the project -->
<div class="field col">
<label for="maxScore">{{ t('views.projects.max_score') }}</label>
<label for="maxScore">{{ t('views.projects.maxScore') }}</label>
<InputNumber
input-id="maxScore"
class="w-full"
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/projects/ProjectStructureTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ function deleteStructureCheck(check: StructureCheck): void {
*/
function updateStructureCheckName(input: HTMLInputElement): void {
if (editingStructureCheck.value !== null && structureChecks.value !== undefined) {
const editing = editingStructureCheck.value;
const oldPath = editing.path;
const editing: StructureCheck = editingStructureCheck.value;
const oldPath: string = editing.path;
editing.setLastFolderName(input.value);
Expand Down Expand Up @@ -196,6 +196,7 @@ function newTreeNode(check: StructureCheck, key: string, label: string, leaf: bo
<InputText
:model-value="node.label"
@change="updateStructureCheckName($event.target as HTMLInputElement)"
@keydown.enter="updateStructureCheckName($event.target as HTMLInputElement)"
>
</InputText>
</template>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/unit/services/project_service.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { describe, it, expect } from 'vitest';
import { describe, it } from 'vitest';

describe('placeholder', (): void => {
it('aaaaaaaa', () => {});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/unit/types/structureCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { describe, it } from 'vitest';
// import { createStructureCheck } from './helper';

describe('structureCheck type', () => {
it('aaaa')
it('aaaa');
// it('create instance of structureCheck with correct properties', () => {
// const structureCheck = createStructureCheck(structureCheckData);
//
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/ApiResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type HyperlinkedRelation = string;
21 changes: 9 additions & 12 deletions frontend/src/types/Course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ export class Course {
public id: string = '',
public name: string = '',
public excerpt: string = '',
public description: string | null = '',
public description: string = '',
public academic_startyear: number = getAcademicYear(),
public private_course: boolean = false,
public invitation_link: string | null = null,
public invitation_link_expires: Date | null = null,
public invitation_link: string = '',
public invitation_link_expires: Date = new Date(),
public parent_course: Course | null = null,
public faculty: Faculty | null = null,
public teachers: Teacher[] | null = null,
public assistants: Assistant[] | null = null,
public students: Student[] | null = null,
public projects: Project[] | null = null,
public faculty: Faculty = new Faculty(),
public teachers: Teacher[] = [],
public assistants: Assistant[] = [],
public students: Student[] = [],
public projects: Project[] = [],
) {}

/**
Expand Down Expand Up @@ -63,9 +63,6 @@ export class Course {
* @param course
*/
static fromJSON(course: Course): Course {
const faculty =
course.faculty !== undefined && course.faculty !== null ? Faculty.fromJSON(course.faculty) : null;

return new Course(
course.id,
course.name,
Expand All @@ -76,7 +73,7 @@ export class Course {
course.invitation_link,
course.invitation_link_expires,
course.parent_course,
faculty,
course.faculty,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/types/Faculty.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class Faculty {
constructor(
public id: string,
public name: string,
public id: string = '',
public name: string = '',
) {}

/**
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/types/FileExtension.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
export class FileExtension {
constructor(public extension: string) {}
constructor(
public id: string = '',
public extension: string = '',
) {}

/**
* Convert a file extension object to a file extension instance.
*
* @param extension
*/
static fromJSON(extension: FileExtension): FileExtension {
return new FileExtension(extension.extension);
return new FileExtension(extension.id, extension.extension);
}
}
15 changes: 10 additions & 5 deletions frontend/src/types/StructureCheck.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FileExtension } from './FileExtension.ts';
import { type Project } from './Project.ts';
import { Project } from './Project.ts';

export class StructureCheck {
constructor(
public id: string = '',
public path: string = '',
public obligated_extensions: FileExtension[] = [],
public blocked_extensions: FileExtension[] = [],
public project: Project | null = null,
public project: Project = new Project(),
) {}

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ export class StructureCheck {
* @param extensions
*/
public setBlockedExtensionList(extensions: string[]): void {
this.blocked_extensions = extensions.map((extension) => new FileExtension(extension));
this.blocked_extensions = extensions.map((extension) => new FileExtension('', extension));
}

/**
Expand All @@ -60,7 +60,7 @@ export class StructureCheck {
* @param extensions
*/
public setObligatedExtensionList(extensions: string[]): void {
this.obligated_extensions = extensions.map((extension) => new FileExtension(extension));
this.obligated_extensions = extensions.map((extension) => new FileExtension('', extension));
}

/**
Expand Down Expand Up @@ -103,6 +103,11 @@ export class StructureCheck {
* @param structureCheck
*/
static fromJSON(structureCheck: StructureCheck): StructureCheck {
return new StructureCheck(structureCheck.id, structureCheck.path);
return new StructureCheck(
structureCheck.id,
structureCheck.path,
structureCheck.obligated_extensions.map(FileExtension.fromJSON),
structureCheck.blocked_extensions.map(FileExtension.fromJSON),
);
}
}
5 changes: 3 additions & 2 deletions frontend/src/views/projects/UpdateProjectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ async function saveProject(newProject: Project): Promise<void> {
await setExtraChecks(newProject.extra_checks ?? [], project.value.id);
// Delete the deleted checks
const deletedChecks = (project.value.extra_checks ?? []).filter(
(check) => !(newProject.extra_checks ?? []).find((newCheck: ExtraCheck) => newCheck.id === check.id),
const deletedChecks = project.value.extra_checks.filter(
(check) =>
newProject.extra_checks.find((newCheck: ExtraCheck) => newCheck.id === check.id) === undefined,
);
for (const check of deletedChecks) {
Expand Down

0 comments on commit d6c0606

Please sign in to comment.