Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ApiServiceBase } from './ApiServiceBase';
import { ISearchMoviesResponse,MovieResponse } from '@/types/apirequestresponsetypes/Movie';
import { Movie } from "@/types/MovieTypes"
import { DocumentNode, gql } from '@apollo/client/core';
import { plainToClass } from 'class-transformer';

class MovieApiService extends ApiServiceBase {
public async SearchMovies(
Expand All @@ -17,18 +16,14 @@ class MovieApiService extends ApiServiceBase {
releaseDate
title
cast{
edges{
node{
name
}
}
}
crew{
key
value{
name
}
}
},
crew{
key,
value{
name
}
}
}
}
`
Expand All @@ -43,7 +38,9 @@ class MovieApiService extends ApiServiceBase {
function ConvertToMovieDto(movieResponse:MovieResponse):Movie{
const movie = {
...movieResponse,
cast: movieResponse.cast?.edges?.map(edge=>({name:edge?.node?.name})) ?? [],
cast: movieResponse.cast?.map(m=> ({
name : m.name
})),
crew: movieResponse.crew?.map(kvp=>({
key : kvp.key,
value: kvp.value?.map((p)=>({ name: p.name}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ export interface MovieResponse {
title: string;
movieLanguage: string;
releaseDate: Date;
cast: CastResponse;
cast: PersonResponse[];
crew: KeyValuePair<string,PersonResponse[]>[];
}

export interface CastResponse{
edges : PersonEdgeResponse[]
}
export interface PersonEdgeResponse{
node: PersonResponse
Person : PersonResponse[]
}

export interface KeyValuePair<TKey,TValue> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MovieService.GraphQL.Queries;
using MovieService.GraphQL.Types;

namespace MovieService.Api.Helpers;

Expand All @@ -8,7 +7,7 @@ public static class GraphQL
public static void Register(IServiceCollection serviceCollection)
{
serviceCollection.AddGraphQLServer()
.AddQueryType<QueryType>()
.AddQueryType<MovieQuery>()
.AddFiltering();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class MovieEntity : Entity
[Field("title")]
public string Title { get; set; } = null!;

[Field("synopsis")]
public string Synopsis { get; set; } = string.Empty;

[Field("movie-language")]
public string? MovieLanguage { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using MovieService.Data.Interfaces.Entities;

namespace MovieService.Data.Interfaces.Services;
namespace MovieService.Data.Interfaces.Services;

public interface IMovieCrudService
{
Task CreateAsync(MovieEntity newBook);
IAsyncEnumerable<MovieEntity> SearchAsync(string searchTerm);
IAsyncEnumerable<MovieEntity> GetRecentMovies(int count = 10);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal class MalayalamMoviesSeed
{
new("Dulquer Salmaan"), new("Thilakan"), new("Nithya Menen")
}

},

new() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.Extensions.Options;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Entities;
using MovieService.Data.Interfaces.Entities;
using MovieService.Data.Interfaces.Services;
Expand Down Expand Up @@ -32,4 +30,21 @@ public async IAsyncEnumerable<MovieEntity> SearchAsync(string searchTerm)
}
}
}

public async IAsyncEnumerable<MovieEntity> GetRecentMovies(int count = 10)
{
if (count <= 0)
yield break;
var cursor = await DB.Find<MovieEntity>()
.Sort(x=>x.Descending(x => x.ReleaseDate))
.Limit(count)
.ExecuteCursorAsync();
while (await cursor.MoveNextAsync())
{
foreach (var movie in cursor.Current)
{
yield return movie;
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="HotChocolate" Version="13.9.12" />
<PackageReference Include="HotChocolate.Data" Version="13.9.13" />
<PackageReference Include="ValueInjecter" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using HotChocolate;
using MovieService.GraphQL.Types;
using MovieService.Service.Interfaces.Services;

namespace MovieService.GraphQL.Queries;

public class MovieQuery([Service]IMovieService movieService)
{
[GraphQLDescription("Find Movie by partial name")]
public async IAsyncEnumerable<MovieType> FindMovie([GraphQLName("searchTerm")]string searchTerm)
{
var movieResult = movieService.Search(searchTerm);

await foreach (var dto in movieResult)
{
yield return new MovieType
{
Title = dto.Title,
MovieLanguage = dto.MovieLanguage ?? "Unknown",
ReleaseDate = dto.ReleaseDate ?? DateTime.MinValue,
Synopsis = "Synopsis not provided", // Assuming no synopsis in DTO
Cast = dto.Cast?.Select(x=>new PersonType { Name = x.Name}).ToList() ?? [],
Crew = dto.Crew?.ToDictionary(
kvp => kvp.Key,
kvp => kvp.Value.Select(p => new PersonType { Name = p.Name }).ToList()) ?? []
};
}
}

[GraphQLDescription("Find recently released movies")]
public async IAsyncEnumerable<MovieType> GetRecentMovies([GraphQLName("count")]int count = 10)
{
var movieResult = movieService.GetRecentMovies(count);
await foreach (var dto in movieResult)
{
yield return new MovieType
{
Title = dto.Title,
MovieLanguage = dto.MovieLanguage ?? "Unknown",
ReleaseDate = dto.ReleaseDate ?? DateTime.MinValue,
Synopsis = "Synopsis not provided", // Assuming no synopsis in DTO
Cast = dto.Cast?.Select(x=>new PersonType { Name = x.Name}).ToList() ?? [],
Crew = dto.Crew?.ToDictionary(
kvp => kvp.Key,
kvp => kvp.Value.Select(p => new PersonType { Name = p.Name }).ToList()) ?? []
};
}
}
}



This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
using HotChocolate.Types;
using MovieService.Service.Interfaces.Dtos;
using HotChocolate;

namespace MovieService.GraphQL.Types;

public class MovieType : ObjectType<MovieDto>
public class MovieType
{
protected override void Configure(IObjectTypeDescriptor<MovieDto> descriptor)
{
descriptor.Description("Defines a movie");

descriptor.Field(x=>x.Title)
.Type<StringType>()
.Description("Title of Movie");
descriptor.Field(x=>x.MovieLanguage)
.Type<StringType>()
.Description("Language of movie");
descriptor.Field(x=>x.ReleaseDate)
.Type<DateTimeType>()
.Description("Release date of movie");
descriptor.Field(x => x.Cast)
.Type<ListType<PersonType>>()
.UsePaging<PersonType>()
.Description("Cast of the movie");
//descriptor.Field(x => x.Crew)
// .Type<AnyType>()
// .Description("Crew of the movie");
}
[GraphQLName("title")]
[GraphQLDescription("Title of movie.")]
public string Title { get; set; } = null!;

[GraphQLName("description")]
[GraphQLDescription("Synopsis of the movie")]
public string Synopsis { get; set; } = null!;

[GraphQLName("movieLanguage")]
[GraphQLDescription("Language")]
public string MovieLanguage { get; set; } = null!;


[GraphQLName("releaseDate")]
[GraphQLDescription("Release Date")]
public DateTime ReleaseDate { get; set; }


[GraphQLName("cast")]
[GraphQLDescription("Cast of the movie")]
public List<PersonType> Cast { get; set; } = [];

[GraphQLName("crew")]
[GraphQLDescription("Crew of the movie")]
public Dictionary<string, List<PersonType>>? Crew { get; set; } = [];
}

public class PersonType : ObjectType<PersonDto>
public class PersonType
{
protected override void Configure(IObjectTypeDescriptor<PersonDto> descriptor)
{
descriptor.Description("Defines a Person");

descriptor.Field(x => x.Name)
.Type<NonNullType<StringType>>()
.Description("Name of the person");
}
[GraphQLName("name")]
[GraphQLDescription("Name")]
public string Name { get; set; } = null!;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public record MovieDto
{
public string Title { get; set; } = null!;

public string Synopsis { get; set; } = string.Empty;

public string? MovieLanguage { get; set; }

public DateTime? ReleaseDate { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public interface IMovieService
{
Task<MovieDto> CreateMovie(MovieDto movie);
IAsyncEnumerable<MovieDto> Search(string searchTerm);
IAsyncEnumerable<MovieDto> GetRecentMovies(int count = 10);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MovieService.Service.Interfaces.Services;
using Omu.ValueInjecter;
using System.Linq;
using System.Threading.Tasks;

namespace MovieService.Service.Services;

Expand Down Expand Up @@ -41,6 +42,18 @@ public async Task<MovieDto> CreateMovie(MovieDto movie)

}

public async IAsyncEnumerable<MovieDto> GetRecentMovies(int count = 10)
{
if (count <= 0)
yield break;

await foreach(var movie in _movieCrudService.GetRecentMovies(count))
{
yield return Mapper.Map<MovieDto>(movie);
}

}

public async IAsyncEnumerable<MovieDto> Search(string searchTerm)
{
if(string.IsNullOrEmpty(searchTerm))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReviewService.Application.DTO.Reviews;
namespace ReviewService.Application.DTO.Reviews;

public class Review
{
public Guid ReviewId { get; set; }
public string MovieTitle { get; set; }
public string MovieTitle { get; set; } = null!;
}
Loading