Skip to content

Commit

Permalink
Restructured Plugin API Responses
Browse files Browse the repository at this point in the history
  • Loading branch information
philgei committed Aug 26, 2024
1 parent 933c5a8 commit 47d4136
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 52 deletions.
4 changes: 2 additions & 2 deletions AdLerBackend.API.UnitTests/BackendConfigExtentionTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Configuration;
using AdLerBackend.API;
using AdLerBackend.Application.Configuration;
using Microsoft.AspNetCore.Mvc.DataAnnotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using Microsoft.Extensions.DependencyInjection;

namespace AdLerBackend.API.UnitTests;

[TestFixture]
public class BackendConfigExtensionsTests
{
Expand Down
2 changes: 2 additions & 0 deletions AdLerBackend.Infrastructure.UnitTests/DTOTests/DtosTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using AdLerBackend.Infrastructure.Moodle.ApiResponses;
using AdLerBackend.Infrastructure.Moodle.ApiResponses.Common;
using AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;
using AutoBogus;
using FluentAssertions;
using Force.DeepCloner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using AdLerBackend.Application.Configuration;
using AdLerBackend.Infrastructure.Moodle;
using AdLerBackend.Infrastructure.Moodle.ApiResponses;
using AdLerBackend.Infrastructure.Moodle.ApiResponses.Common;
using AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses;
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.Common;

internal class ResponseWithData<T>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses;
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.Common;

internal class ResponseWithDataArray<T>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;

public class PluginAdaptivityAnsweredQuestionResponse
{
public AdaptivityModuleInfo Module { get; set; }
public IList<PluginAdaptivityTaskResponse> Tasks { get; set; }
public IList<PluginAdaptivityQuestionsDetailResponse.PluginAdaptivityQuestion> Questions { get; set; }

public class AdaptivityModuleInfo
{
public string Status { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using JetBrains.Annotations;
using System.Text.Json.Serialization;
using JetBrains.Annotations;

namespace AdLerBackend.Infrastructure.Moodle.ApiResponses;
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;

[UsedImplicitly]
public class PluginQuestionsDetailResponse
public class PluginAdaptivityQuestionsDetailResponse
{
public List<PluginAdaptivityQuestion> Questions { get; set; }

Expand All @@ -13,6 +14,8 @@ public class PluginAdaptivityQuestion
public string Uuid { get; set; }

public string Status { get; set; }
[JsonPropertyName("status_best_try")]
public string StatusBestTry { get; set; }
public string? Answers { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;

public class PluginAdaptivityTaskResponse
{
public string Uuid { get; set; }
public string Status { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;

public class PluginAdaptivityTasksResponse
{
public IList<PluginAdaptivityTaskResponse> Tasks { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses;
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;

internal class PluginCourseCreationResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses;
namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;

internal class PluginElementScoreData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Text.Json.Serialization;

namespace AdLerBackend.Infrastructure.Moodle.ApiResponses;

public class PluginUUIDResponse
{
[JsonPropertyName("course_id")] public string CourseId { get; set; }

[JsonPropertyName("element_type")] public string ElementType { get; set; }

[JsonPropertyName("Uuid")] public Guid Uuid { get; set; }

[JsonPropertyName("moodle_id")] public int MoodleId { get; set; }

[JsonPropertyName("context_id")] public int ContextId { get; set; }
using System.Text.Json.Serialization;

namespace AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;

public class PluginUUIDResponse
{
[JsonPropertyName("course_id")] public string CourseId { get; set; }

[JsonPropertyName("element_type")] public string ElementType { get; set; }

[JsonPropertyName("Uuid")] public Guid Uuid { get; set; }

[JsonPropertyName("moodle_id")] public int MoodleId { get; set; }

[JsonPropertyName("context_id")] public int ContextId { get; set; }
}

This file was deleted.

8 changes: 5 additions & 3 deletions AdLerBackend.Infrastructure/Moodle/MoodleWebApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using AdLerBackend.Application.Common.Responses.LMSAdapter.Adaptivity;
using AdLerBackend.Application.Configuration;
using AdLerBackend.Infrastructure.Moodle.ApiResponses;
using AdLerBackend.Infrastructure.Moodle.ApiResponses.Common;
using AdLerBackend.Infrastructure.Moodle.ApiResponses.PluginResponses;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

Expand Down Expand Up @@ -90,7 +92,7 @@ public async Task DeleteCourseAsync(string token, int courseId)
public async Task<IEnumerable<LMSAdaptivityQuestionStateResponse>> GetAdaptivityElementDetailsAsync(string token,
int elementId)
{
var rawResponse = await MoodleCallAsync<ResponseWithData<PluginQuestionsDetailResponse>>(
var rawResponse = await MoodleCallAsync<ResponseWithData<PluginAdaptivityQuestionsDetailResponse>>(
new Dictionary<string, HttpContent>
{
{"wstoken", new StringContent(token)},
Expand All @@ -117,7 +119,7 @@ public async Task<IEnumerable<LMSAdaptivityQuestionStateResponse>> GetAdaptivity
public async Task<IEnumerable<LMSAdaptivityTaskStateResponse>> GetAdaptivityTaskDetailsAsync(string token,
int elementId)
{
var rawResponse = await MoodleCallAsync<ResponseWithData<PluginTasksResponse>>(
var rawResponse = await MoodleCallAsync<ResponseWithData<PluginAdaptivityTasksResponse>>(
new Dictionary<string, HttpContent>
{
{"wstoken", new StringContent(token)},
Expand Down Expand Up @@ -289,7 +291,7 @@ public async Task<AdaptivityModuleStateResponseAfterAnswer> AnswerAdaptivityQues
wsParams.Add($"questions[{i}][answer]", new StringContent(answeredQuestions.ElementAt(i).Answer));
}

var result = await MoodleCallAsync<ResponseWithData<AdaptivityModuleAnsweredResponse>>(wsParams);
var result = await MoodleCallAsync<ResponseWithData<PluginAdaptivityAnsweredQuestionResponse>>(wsParams);

return new AdaptivityModuleStateResponseAfterAnswer
{
Expand Down

0 comments on commit 47d4136

Please sign in to comment.