Skip to content

Adding Item Types

In this section we will explain the steps to add a new Item Type in the Suite Inspections service.

Template and Inspection

  • Add the Item name (Foo from now on) to the ItemType enum.
  • Create its class named TemplateFooItem, inherit from TemplateItem and add the new specific (if has) properties.
  • Create another class named InspectionFooItem that is basically the clone of TemplateFooItem and inherit from InspectionItem.
  • We need to add the corresponding Visit method for the new Item in the IBaseNodeVisitor interface, for example:
C#
void VisitFooItem(TemplateFooItem fooItem);

Important

Create the implementation in the InspectionCreationDataBuilderVisitor class. You can check the already done implementations to have an idea on how to do it.

  • Add a new record in the CreationInspectionMessage interface, named FooItemInspectionCreation and inherit from ItemInspectionCreation. In that record add the properties that should be mapped to the Inspection counterpart.
  • We need to add another Visit method in the IInspectionCreationVisitor interface, for example:
C#
void VisitFooItem(CreateInspectionMessage.FooItemInspectionCreation fooItem);

Important

Create the implementation in the InspectionCreationVisitor class. You can check the already done implementations to have an idea on how to do it.

  • Add a new entry to the dictionary in the ItemInspectionCreationJsonConverter class, for example:
C#
1
2
3
4
5
private readonly Dictionary<ItemType, Type> itemTypes = new()
{
    // ...
    { ItemType.Foo, typeof(FooItemInspectionCreation) },
};
  • Add the Visit for the Template Item Creation Visitor : TBD.

  • Create the DTOs and its mappings.

Grading

  • Create the class for grading, named FooItemGrade and inherit from ItemGrade.
  • Create the DTOs and its mappings.
  • Go to Application.Contracts.DataTransfer.V1.ItemGrade.Serialization folder and create a class named FooItemGradeData and inherit from ItemGradeData. The generic is the type of the Grade, for example: string is the grade type of TextItem and IEnumerable<ResponseDto> for QuestionItem.

Note

In this abstraction layer we are using the Dto version of the grade entity. For example: IEnumerable<ResponseDto> for QuestionItem.

  • We need to add another Visit method in the IGradeDataVisitor interface, for example:
C#
void VisitFooItem(FooItemGradeData fooItemGradeData);

Important

Create the implementation in the GradingVisitor class. You can check the already done implementations to have an idea on how to do it. In this visitor we have DI available if we need to inject something, a repository for example.

  • Add a new entry to the dictionary in the ItemGradeJsonConverter class. For example:
C#
1
2
3
4
5
private readonly Dictionary<ItemType, Type> itemTypes = new()
{
    // ...
    { ItemType.Foo, typeof(FooItemGradeData) },
};