Skip to content

Commit

Permalink
Added sort order in Questions
Browse files Browse the repository at this point in the history
  • Loading branch information
shilpigoel-goaco committed Oct 3, 2024
1 parent aedfe97 commit eec9f7f
Show file tree
Hide file tree
Showing 12 changed files with 1,888 additions and 15 deletions.
18 changes: 12 additions & 6 deletions Services/CO.CDP.DataSharing.WebApi.Tests/EntityFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ private static PersistenceForms.FormSection GivenSection(Guid sectionId, Persist
NextQuestionAlternative = null,
CreatedOn = DateTimeOffset.UtcNow,
UpdatedOn = DateTimeOffset.UtcNow,
Section = GivenSection(Guid.NewGuid(), form)
Section = GivenSection(Guid.NewGuid(), form),
SortOrder = 1
},
new PersistenceForms.FormQuestion
{
Expand All @@ -309,7 +310,8 @@ private static PersistenceForms.FormSection GivenSection(Guid sectionId, Persist
NextQuestionAlternative = null,
CreatedOn = DateTimeOffset.UtcNow,
UpdatedOn = DateTimeOffset.UtcNow,
Section = GivenSection(Guid.NewGuid(), form)
Section = GivenSection(Guid.NewGuid(), form),
SortOrder = 2
},
new PersistenceForms.FormQuestion
{
Expand All @@ -326,7 +328,8 @@ private static PersistenceForms.FormSection GivenSection(Guid sectionId, Persist
NextQuestionAlternative = null,
CreatedOn = DateTimeOffset.UtcNow,
UpdatedOn = DateTimeOffset.UtcNow,
Section = GivenSection(Guid.NewGuid(), form)
Section = GivenSection(Guid.NewGuid(), form),
SortOrder = 3
},
new PersistenceForms.FormQuestion
{
Expand All @@ -343,7 +346,8 @@ private static PersistenceForms.FormSection GivenSection(Guid sectionId, Persist
NextQuestionAlternative = null,
CreatedOn = DateTimeOffset.UtcNow,
UpdatedOn = DateTimeOffset.UtcNow,
Section = GivenSection(Guid.NewGuid(), form)
Section = GivenSection(Guid.NewGuid(), form),
SortOrder = 4
},
new PersistenceForms.FormQuestion
{
Expand All @@ -360,7 +364,8 @@ private static PersistenceForms.FormSection GivenSection(Guid sectionId, Persist
NextQuestionAlternative = null,
CreatedOn = DateTimeOffset.UtcNow,
UpdatedOn = DateTimeOffset.UtcNow,
Section = GivenSection(Guid.NewGuid(), form)
Section = GivenSection(Guid.NewGuid(), form),
SortOrder = 5
},
new PersistenceForms.FormQuestion
{
Expand All @@ -377,7 +382,8 @@ private static PersistenceForms.FormSection GivenSection(Guid sectionId, Persist
NextQuestionAlternative = null,
CreatedOn = DateTimeOffset.UtcNow,
UpdatedOn = DateTimeOffset.UtcNow,
Section = GivenSection(Guid.NewGuid(), form)
Section = GivenSection(Guid.NewGuid(), form),
SortOrder = 6
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public DataSharingProfile()
.ForMember(m => m.Text, o => o.MapFrom(m => m.Description))
.ForMember(m => m.IsRequired, o => o.MapFrom(m => m.IsRequired))
.ForMember(m => m.SectionName, o => o.MapFrom(m => m.Section.Title))
.ForMember(m => m.Options, o => o.MapFrom(m => m.Options.Choices));
.ForMember(m => m.Options, o => o.MapFrom(m => m.Options.Choices))
.ForMember(m => m.SortOrder, o => o.MapFrom(m => m.SortOrder));

CreateMap<Persistence.FormQuestionChoice, FormQuestionOption>()
.ForMember(m => m.Id, o => o.MapFrom(m => m.Id))
Expand Down
2 changes: 2 additions & 0 deletions Services/CO.CDP.DataSharing.WebApi/Model/FormQuestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public record FormQuestion
public required string SectionName { get; init; }

public List<FormQuestionOption>? Options { get; init; }

public required int SortOrder { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public async Task ItReturnsTheSectionWithQuestions()
NextQuestionAlternative = null,
Options = new CO.CDP.OrganisationInformation.Persistence.Forms.FormQuestionOptions(),
Section = section,
SortOrder = 0
},
new CO.CDP.OrganisationInformation.Persistence.Forms.FormQuestion
{
Expand All @@ -100,6 +101,7 @@ public async Task ItReturnsTheSectionWithQuestions()
NextQuestionAlternative = null,
Options = new CO.CDP.OrganisationInformation.Persistence.Forms.FormQuestionOptions(),
Section = section,
SortOrder = 0
}
};
section.Questions = questions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public async Task GetQuestionsAsync_WhenSectionExists_ReturnsQuestions()
IsRequired = true,
NextQuestion = null,
NextQuestionAlternative = null,
Options = new FormQuestionOptions()
Options = new FormQuestionOptions(),
SortOrder = 0
};

var question2 = new FormQuestion
Expand All @@ -136,7 +137,8 @@ public async Task GetQuestionsAsync_WhenSectionExists_ReturnsQuestions()
IsRequired = true,
NextQuestion = null,
NextQuestionAlternative = null,
Options = new FormQuestionOptions()
Options = new FormQuestionOptions(),
SortOrder = 0
};

section.Questions.Add(question1);
Expand Down Expand Up @@ -406,7 +408,8 @@ public async Task GetFormAnswerSetAsync_WhenFormAnswerSetsExists_ReturnsFormAnsw
NextQuestion = null,
NextQuestionAlternative = null,
CreatedOn = DateTimeOffset.UtcNow,
UpdatedOn = DateTimeOffset.UtcNow
UpdatedOn = DateTimeOffset.UtcNow,
SortOrder = 0
};
section.Questions.Add(question);

Expand Down Expand Up @@ -442,7 +445,10 @@ public async Task GetFormAnswerSetAsync_WhenFormAnswerSetsExists_ReturnsFormAnsw
BoolValue = true,
AddressValue = new FormAddress
{
StreetAddress = "456 Elm St", Locality = "London", PostalCode = "G67890", CountryName = "UK",
StreetAddress = "456 Elm St",
Locality = "London",
PostalCode = "G67890",
CountryName = "UK",
Country = "GB"
},
CreatedOn = DateTimeOffset.UtcNow,
Expand Down Expand Up @@ -511,7 +517,8 @@ public async Task GetQuestionsAsync_WhenOptionsAreSimple_ReturnsCorrectOptions()
IsRequired = true,
NextQuestion = null,
NextQuestionAlternative = null,
Options = simpleOptions
Options = simpleOptions,
SortOrder = 0
};

section.Questions.Add(question);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ private static FormQuestion GivenYesOrNoQuestion(FormSection section)
NextQuestion = null,
NextQuestionAlternative = null,
Caption = null,
Options = new()
Options = new(),
SortOrder = 0
};
section.Questions.Add(question);
return question;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static FormQuestion GivenFormQuestion(
NextQuestionAlternative = null,
Options = new FormQuestionOptions(),
Section = theSection,
SortOrder = 0
};
theSection.Questions.Add(question);
return question;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<IEnumerable<SharedConsent>> GetShareCodesAsync(Guid organisati
.ThenInclude(a => a.Question)
.Include(sc => sc.Form)
.ThenInclude(f => f.Sections)
.ThenInclude(s => s.Questions)
.ThenInclude(s => s.Questions.OrderBy(q => q.SortOrder))
.FirstOrDefaultAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class FormQuestion : IEntityDate
public required Guid Guid { get; set; }
public required FormQuestion? NextQuestion { get; set; } = null;
public required FormQuestion? NextQuestionAlternative { get; set; } = null;
public required int SortOrder { get; set; } = 0;
public required int SortOrder { get; set; } = 0; // To return Question's sort order mirroring with NextQuestionID/NextQuestionAlternative
public required FormSection Section { get; set; }
public required FormQuestionType Type { get; set; }
public required bool IsRequired { get; set; } = true;
Expand Down
Loading

0 comments on commit eec9f7f

Please sign in to comment.