Skip to content

Commit

Permalink
last styling fixes before deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasSirotek committed Dec 17, 2023
1 parent 7900b3c commit 9204fee
Show file tree
Hide file tree
Showing 41 changed files with 516 additions and 585 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
using Microsoft.AspNetCore.Http;
using SkillSphere.Application.Common.Interfaces;
using SkillSphere.Application.Features.Courses.Commands.CreateCourse;
using SkillSphere.Application.Features.Courses.Queries.GetAllCourses;
using SkillSphere.Domain.Entities;

namespace SkillSphere.Application.Features.Courses.Commands.PublishCourse;

public class PublishCourseCommandHandler : IRequestHandler<PublishCourseCommand, IResult>
{
private readonly IApplicationDbContext _context;
private readonly IMapper _mapper;


public PublishCourseCommandHandler(IApplicationDbContext context)
public PublishCourseCommandHandler(IApplicationDbContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}

public async Task<IResult> Handle(PublishCourseCommand request, CancellationToken cancellationToken)
{
var course = await _context.Courses.FindAsync(request.CourseId);

var course = await _context.Courses
.Include(c => c.Chapters)
.Include(ca => ca.Categories)
.Where(c => c.Id == request.CourseId)
.FirstOrDefaultAsync(cancellationToken);


if (course == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,23 @@ public async Task Handle(SaveCourseDraftCommand request, CancellationToken cance

private async Task UpdateChapters(Course existingCourse, IList<PutChapterDto> requestChapters, CancellationToken cancellationToken)
{
var chaptersToRemove = existingCourse.Chapters.ToList();
existingCourse.Chapters.Clear();

foreach (var requestChapter in requestChapters)
{


var existingChapter = existingCourse.Chapters.FirstOrDefault(c => c.Id == requestChapter.Id);

if (existingChapter != null)
{
// Update existing chapter
existingChapter.Title = requestChapter.Title;
existingChapter.Description = requestChapter.Description;
existingChapter.VideoURL = requestChapter.VideoURL;
existingChapter.Position = requestChapter.Position;
existingChapter.IsFree = requestChapter.IsFree;

}
else
existingCourse.Chapters.Add(new Chapter
{
existingCourse.Chapters.Add(new Chapter
{
// Set properties based on requestChapter
Title = requestChapter.Title,
Description = requestChapter.Description,
VideoURL = requestChapter.VideoURL,
Position = requestChapter.Position,
IsFree = requestChapter.IsFree,
});
}
Title = requestChapter.Title,
Description = requestChapter.Description,
VideoURL = requestChapter.VideoURL,
Position = requestChapter.Position,
IsFree = requestChapter.IsFree,
});
}

// Remove any chapters that were not in the request
foreach (var chapterToRemove in chaptersToRemove)
{
existingCourse.Chapters.Remove(chapterToRemove);
}

// Save changes to the database
await _context.SaveChangesAsync(cancellationToken);
}

private async Task UpdateCategories(Course existingCourse, IList<PutCategoryDto> categoriesList,
CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using SkillSphere.Application.Common.Interfaces;
using SkillSphere.Application.Common.Security;
using SkillSphere.Application.Features.Courses.Queries.GetAllCourses;
using SkillSphere.Domain.Entities;

namespace SkillSphere.Application.Features.Courses.Queries.GetCourseById;

Expand All @@ -24,21 +23,8 @@ public GetCoursesQueryHandler(IApplicationDbContext context, IMapper mapper, IUs

public async Task<QueryDto> Handle(GetCourseByIdQuery request, CancellationToken cancellationToken)
{
// get ccourse by id and return it
// var test = await _context.Courses
// .AsNoTracking()
// .Include(c => c.Categories)
// .Include(c => c.Chapters)
// .Where(c => c.Id == request.CourseId)
// .ProjectTo<QueryDto>(_mapper.ConfigurationProvider)
// .FirstOrDefaultAsync(cancellationToken);
//
// Guard.Against.Null(test, nameof(test));
//
// return test;


var course = await _context.Courses
var course = await _context.Courses
.Include(c => c.Chapters)
.Where(c => c.Id == request.CourseId)
.ProjectTo<QueryDto>(_mapper.ConfigurationProvider)
Expand All @@ -48,14 +34,10 @@ public async Task<QueryDto> Handle(GetCourseByIdQuery request, CancellationToken

var userOwnsCourse = await _context.OwnedCourses
.AnyAsync(oc => oc.CourseId == course.Id && oc.UserId == _user.Id, cancellationToken);
// Check if the user has purchased the course

var userCreatedCourse = await _context.UsersCourses
.AnyAsync(oc => oc.CourseId == course.Id && oc.UserId == _user.Id, cancellationToken);


// If the user has purchased the course, update chapter visibility
if (userOwnsCourse || userCreatedCourse)
if (userOwnsCourse )
{
foreach (var chapter in course.Chapters)
{
Expand Down
13 changes: 6 additions & 7 deletions src/Infrastructure/Data/ApplicationDbContextInitialiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using skillSphere.Infrastructure.Data;
using SkillSphere.Infrastructure.Identity;
using Roles = SkillSphere.Domain.Constants.Roles;

namespace SkillSphere.Infrastructure.Data;
Expand Down Expand Up @@ -66,7 +67,6 @@ public async Task SeedAsync()

public async Task TrySeedAsync()
{
// Default roles
// Default roles
var administratorRole = new ApplicationRole();
administratorRole.Name = Roles.Administrator;
Expand All @@ -77,24 +77,24 @@ public async Task TrySeedAsync()
}

// Default users
var administrator = new ApplicationUser { UserName = "administrator@localhost", Email = "administrator@localhost" };
var administrator = new ApplicationUser { UserName = "Peter", Email = "administrator@localhost.com" };

if (_userManager.Users.All(u => u.UserName != administrator.UserName))
{
await _userManager.CreateAsync(administrator, "Administrator1!");
await _userManager.CreateAsync(administrator, "Administrator1!");
if (!string.IsNullOrWhiteSpace(administratorRole.Name))
{
await _userManager.AddToRolesAsync(administrator, new [] { administratorRole.Name });
}
}

// SEED DATA
// SEED DATA
if (!_context.Courses.Any())
{
var course1 = new Course
{
Title = "Extreme web development",
Description = "This is a course about web development",
Description = "Unlock the world of web development with our comprehensive Introduction to Web Development course. Whether you're a beginner taking your first steps into the digital realm or an experienced programmer looking to expand your skill set, this course is designed to provide a solid foundation in the dynamic field of web development.",
CoverImageRelativePath = "https://ipfs.io/ipfs/QmW1MBApm4XvwgoSKf45ZtsqJU5cDYdcsW2GBSEUqXWE3T",
Price = 19.99f,
Likes = 0,
Expand All @@ -116,8 +116,7 @@ public async Task TrySeedAsync()
new Chapter { Title = "Chapter 2", Description = "Chapter 2 Description",Position = 1,IsFree = false,},
new Chapter { Title = "Chapter 3", Description = "Chapter 3 Description",Position = 2,IsFree = false,},
new Chapter { Title = "Chapter 4", Description = "Chapter 4 Description",Position = 3,IsFree = false,},
}

},
};

_context.Courses.Add(course1);
Expand Down
52 changes: 19 additions & 33 deletions src/UI/src/app/core/auth/service/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
import {Injectable, OnDestroy, inject} from '@angular/core';
import {HttpClient, HttpResponse} from '@angular/common/http';
import {environment} from '../../../../environments/environment';
import { Injectable, OnDestroy, inject } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { environment } from '../../../../environments/environment';
import { catchError, map, shareReplay, switchMap } from 'rxjs/operators';
import { tap } from 'rxjs/operators';
import {BehaviorSubject, Observable, Observer, forkJoin, of} from 'rxjs';
import { BehaviorSubject, Observable, Observer, forkJoin, of } from 'rxjs';
import { AuthResponse } from '../models/login';
import { Register } from '../models/register';
import { Course } from 'src/app/modules/management/models/course';
import { AuthService } from './auth.service';

@Injectable({
providedIn: 'root'
providedIn: 'root',
})



export class UserService {


constructor(private _http: HttpClient, private authService: AuthService) {



}


public loadWishList(userId: string): Observable<Course[]> {
return this._http.get<{ courses: Course[] }>(`${environment.baseUrl}/courses/${userId}/wishlist`)
.pipe(
map(response => response.courses),
catchError(error => {
console.error('HTTP request error:', error);
return of([]); // Return an empty array in case of an error
})
);
}





constructor(private _http: HttpClient, private authService: AuthService) {}

public loadWishList(userId: string): Observable<Course[]> {
return this._http
.get<{ courses: Course[] }>(
`${environment.baseUrl}/courses/${userId}/wishlist`
)
.pipe(
map((response) => response.courses),
catchError((error) => {
return of([]); // Return an empty array in case of an error
})
);
}
}
5 changes: 0 additions & 5 deletions src/UI/src/app/core/constant/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ export class Menu {
label: 'Store',
route: '/courses',
},
{
icon:' heroHeart',
label: 'Wishlist',
route: '/wishlist',
},
{
icon: 'heroSquares2x2',
label: 'Dashboard',
Expand Down
5 changes: 5 additions & 0 deletions src/UI/src/app/modules/dashboard/dashboard-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ const routes: Routes = [
{
path: '',
component: DashboardComponent,
data: { breadcrumb: 'Dashboard' },
},
{
path: 'my-courses',
component: TeachingComponent,
data: { breadcrumb: 'My Courses' },

},
{
path: 'my-courses/:id',
component: CoursesDetailComponent,
data: { breadcrumb: 'Course Detail' },

},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
<div class="rounded-md shadow overflow-hidden">
<ngx-skeleton-loader
count="1"
[theme]="{
'height.px': 250,
'background-color': 'grey',
'width.px': '300'
}"
[theme]="{ 'height.px': 330, 'background-color': 'grey ', 'width.px': '400','opacity': 0.1 }"
></ngx-skeleton-loader>
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
[class.text-green-700]="i === selectedIdx"
[class.border-green-300]="i === selectedIdx"
[class.bg-green-50]="i === selectedIdx"
[class.dark:bg-gray-800]="i === selectedIdx"
[class.dark:bg-gray-900]="i === selectedIdx"
[class.dark:border-green-800]="i === selectedIdx"
[class.dark:border]="i === selectedIdx"
[class.dark:border-green-800]="i === selectedIdx"
Expand All @@ -54,6 +54,5 @@ <h3 class="font-medium">{{ item.name }}</h3>

<app-boxes-table [selectedValue]="selectedValue" (emitLikeCourseChange)="handleEmitLikeCourseChange($event)" />

<!-- LIST OF ALL USERS OR COURSE DRAFTS AND PUBLISHED COURSES -->
<!-- <app-user-courses></app-user-courses> -->

</div>
Loading

0 comments on commit 9204fee

Please sign in to comment.