Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson save #62

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions TeacherWorkout.Api/GraphQL/Resolvers/LessonSaveResolver.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
using TeacherWorkout.Domain.Common;
using TeacherWorkout.Domain.Lessons;
using TeacherWorkout.Domain.Models;
using TeacherWorkout.Domain.Models.Inputs;
using TeacherWorkout.Domain.Models.Payloads;

namespace TeacherWorkout.Api.GraphQL.Resolvers

{
public static class LessonSaveResolver
public class LessonSaveResolver : IOperation<LessonSaveInput, LessonSavePayload>
{
public static LessonSavePayload Resolve(LessonSaveInput lessonSave)

private IContext _context;
private ILessonStatusRepository _lessonStatusRepository;
private ILessonRepository _lessonRepository;

public LessonSaveResolver (IContext context, ILessonStatusRepository lessonStatusRepository, ILessonRepository lessonRepository)
{
return new() {Lesson = MockData(lessonSave)};
}
_context = context;
_lessonStatusRepository = lessonStatusRepository;
_lessonRepository = lessonRepository;

private static Lesson MockData(LessonSaveInput lessonSave)
}

public LessonSavePayload Execute(LessonSaveInput input)
{
return new()
Lesson lesson = _lessonRepository.Find(input.LessonId);

_lessonStatusRepository.Insert(new LessonStatus()
{
Id = lessonSave.LessonId,
Title = "Lorem Ipsum",
Thumbnail = new Image
{
Description = "For Challenged People",
Url = "https://example.com"
},
Theme = new Theme
{
Id = "1",
Title = "Lorem Ipsum",
Thumbnail = new Image
{
Description = "For Challenged People",
Url = "https://example.com"
}
},
Duration = new Duration
{
Value = 45,
Unit = DurationUnit.Minutes
}
Lesson = lesson,
PercentCompleted = 0,
User = _context.CurentUser
});

return new LessonSavePayload()
{
Lesson = lesson
};
}



}
}
7 changes: 4 additions & 3 deletions TeacherWorkout.Api/GraphQL/TeacherWorkoutMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace TeacherWorkout.Api.GraphQL
{
public class TeacherWorkoutMutation : ObjectGraphType<object>
{
public TeacherWorkoutMutation(CompleteStep completeStep)
public TeacherWorkoutMutation(CompleteStep completeStep, LessonSaveResolver lessonSaveResolver)
{
Name = "Mutation";

Field<NonNullGraphType<LessonSavePayloadType>>(
"lessonSave",
arguments: new QueryArguments(
Expand All @@ -22,7 +22,8 @@ public TeacherWorkoutMutation(CompleteStep completeStep)
resolve: context =>
{
var lessonSave = context.GetArgument<LessonSaveInput>("input");
return LessonSaveResolver.Resolve(lessonSave);

return lessonSaveResolver.Execute(lessonSave);
});

Field<StepCompletePayloadType>(
Expand Down
5 changes: 4 additions & 1 deletion TeacherWorkout.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using TeacherWorkout.Api.GraphQL;
using TeacherWorkout.Data;
using TeacherWorkout.Domain.Common;
using TeacherWorkout.Domain.Models;

namespace TeacherWorkout.Api
{
Expand All @@ -28,7 +29,7 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
EnsureReferencedAssembliesAreLoaded();

services.AddCors(options =>
{
options.AddDefaultPolicy(builder =>
Expand Down Expand Up @@ -57,6 +58,8 @@ public void ConfigureServices(IServiceCollection services)

services.AddDbContext<TeacherWorkoutContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("TeacherWorkoutContext")));

services.AddSingleton<IContext>(new Context() { CurentUser = new User() { Id = "1", Name = "Test user" }});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
7 changes: 6 additions & 1 deletion TeacherWorkout.Data/Repositories/LessonRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public LessonRepository(TeacherWorkoutContext context)
{
_context = context;
}


public Lesson Find(string ID)
{
return _context.Lessons.Find(ID);
}

public PaginatedResult<Lesson> PaginatedList(LessonFilter filter)
{
var result = _context.Lessons.AsQueryable()
Expand Down
14 changes: 14 additions & 0 deletions TeacherWorkout.Domain/Common/IUser.cs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the file to match the contents.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using TeacherWorkout.Domain.Models;

namespace TeacherWorkout.Domain.Common
{
public interface IContext

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract the interface into a separate file.

{
public User CurentUser { get; }
}

public class Context : IContext
{
public User CurentUser { get; set; }
}
}
4 changes: 4 additions & 0 deletions TeacherWorkout.Domain/Lessons/ILessonRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ namespace TeacherWorkout.Domain.Lessons
public interface ILessonRepository
{
PaginatedResult<Lesson> PaginatedList(LessonFilter filter);

Lesson Find(string ID);

}

}
1 change: 1 addition & 0 deletions TeacherWorkout.Domain/Lessons/ILessonStatusRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ namespace TeacherWorkout.Domain.Lessons
public interface ILessonStatusRepository
{
IEnumerable<LessonStatus> List(LessonStatusFilter filter);
LessonStatus Insert(LessonStatus lessonStatus);
}
}
2 changes: 2 additions & 0 deletions TeacherWorkout.Domain/Models/LessonStaus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public class LessonStatus
public int PercentCompleted { get; set; }

public ILessonStep CurrentLessonStep { get; set; }

public User User { get; set; }
}
}
12 changes: 12 additions & 0 deletions TeacherWorkout.Domain/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using TeacherWorkout.Domain.Common;

namespace TeacherWorkout.Domain.Models
{
public class User : IIdentifiable
{
public string Id { get; set; }

public string Name { get; set; }

}
}
29 changes: 29 additions & 0 deletions TeacherWorkout.MockData/Repositories/LessonRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ namespace TeacherWorkout.MockData.Repositories
{
public class LessonRepository : ILessonRepository
{
public Lesson Find(string ID)
{
return new()
{
Id = "2",
Title = "Dolor sit amet",
Thumbnail = new Image
{
Description = "Another Cat Photo",
Url = "https://static.toiimg.com/thumb/msid-67586673,width-800,height-600,resizemode-75,imgsize-3918697,pt-32,y_pad-40/67586673.jpg"
},
Theme = new Theme
{
Id = "1",
Title = "Lorem Ipsum",
Thumbnail = new Image
{
Description = "Cat Photo",
Url = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Felis_catus-cat_on_snow.jpg/640px-Felis_catus-cat_on_snow.jpg"
}
},
Duration = new Duration
{
Value = 32,
Unit = DurationUnit.Minutes
}
};
}

public PaginatedResult<Lesson> PaginatedList(LessonFilter filter)
{
return new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace TeacherWorkout.MockData.Repositories
{
public class LessonStatusRepository : ILessonStatusRepository
{
public LessonStatus Insert(LessonStatus lessonStatus)
{
return lessonStatus;
}

public IEnumerable<LessonStatus> List(LessonStatusFilter filter)
{
return filter.LessonIds
Expand Down
Loading