-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
777 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Core.Application.DTOs.Genres | ||
{ | ||
public class TmdbGenreApiResponseDto | ||
{ | ||
public List<TmdbGenreResponseDto>? genres { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Core.Application.DTOs.Genres | ||
{ | ||
public class TmdbGenreResponseDto | ||
{ | ||
public int id { get; set; } | ||
public string name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Core.Application.DTOs.Genres | ||
{ | ||
public class TmdbGenreResponseListDto | ||
{ | ||
public List<TmdbGenreResponseDto>? Movies { get; set; } | ||
public List<TmdbGenreResponseDto>? Series { get; set; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
Core.Application/Features/GenreModule/Commands/GetAllGenres/GetAllGenresCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Core.Application.DTOs.General; | ||
using Core.Application.Helpers.TMDB; | ||
using Core.Application.Interface.Repositories; | ||
using Core.Domain.Entities.GeneralMovie; | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Core.Application.Features.GenreModule.Commands.GetAllGenres | ||
{ | ||
public class GetAllGenresCommand : IRequest<GenericApiResponse<string>> | ||
{ | ||
} | ||
public class GetAllGenresCommandHandler : IRequestHandler<GetAllGenresCommand, GenericApiResponse<string>> | ||
{ | ||
private readonly GetTMDBData _getTMDBData; | ||
private readonly IGenreRepository _genreRepository; | ||
|
||
public GetAllGenresCommandHandler(GetTMDBData getTMDBData, IGenreRepository genreRepository) | ||
{ | ||
_getTMDBData = getTMDBData; | ||
_genreRepository = genreRepository; | ||
} | ||
|
||
public async Task<GenericApiResponse<string>> Handle(GetAllGenresCommand request, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
int i = 0; | ||
var res = await _getTMDBData.GetAllGenres(); | ||
foreach (var m in res.Movies) | ||
{ | ||
var InDb = await _genreRepository.Exist(m.id); | ||
if (!InDb) | ||
{ | ||
i++; | ||
await _genreRepository.AddAsync(new Genre | ||
{ | ||
GenreID = m.id, | ||
Name = m.name, | ||
IsMovie = true | ||
}); | ||
} | ||
} | ||
foreach (var m in res.Series) | ||
{ | ||
var InDb = await _genreRepository.Exist(m.id); | ||
if (!InDb) | ||
{ | ||
i++; | ||
await _genreRepository.AddAsync(new Genre | ||
{ | ||
GenreID = m.id, | ||
Name = m.name, | ||
IsMovie = false | ||
}); | ||
} | ||
} | ||
return new GenericApiResponse<string> | ||
{ | ||
Statuscode = 200, | ||
Message = $"{i} Genres Added Successfully", | ||
Payload = HttpStatusCode.OK.ToString(), | ||
Success = true | ||
}; | ||
} | ||
catch (Exception e) | ||
{ | ||
return new GenericApiResponse<string> | ||
{ | ||
Statuscode = 500, | ||
Message = e.Message, | ||
Payload = HttpStatusCode.InternalServerError.ToString(), | ||
Success = false | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.