diff --git a/client/nt.webclient/vue3withtypescript/nt/src/apiService/MovieApiService.ts b/client/nt.webclient/vue3withtypescript/nt/src/apiService/MovieApiService.ts index 3fe0965a..0ebb74e8 100644 --- a/client/nt.webclient/vue3withtypescript/nt/src/apiService/MovieApiService.ts +++ b/client/nt.webclient/vue3withtypescript/nt/src/apiService/MovieApiService.ts @@ -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( @@ -17,18 +16,14 @@ class MovieApiService extends ApiServiceBase { releaseDate title cast{ - edges{ - node{ - name - } - } - } - crew{ - key - value{ name - } - } + }, + crew{ + key, + value{ + name + } + } } } ` @@ -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})) diff --git a/client/nt.webclient/vue3withtypescript/nt/src/types/apirequestresponsetypes/Movie.ts b/client/nt.webclient/vue3withtypescript/nt/src/types/apirequestresponsetypes/Movie.ts index 8bcd59d9..55e722e1 100644 --- a/client/nt.webclient/vue3withtypescript/nt/src/types/apirequestresponsetypes/Movie.ts +++ b/client/nt.webclient/vue3withtypescript/nt/src/types/apirequestresponsetypes/Movie.ts @@ -9,15 +9,12 @@ export interface MovieResponse { title: string; movieLanguage: string; releaseDate: Date; - cast: CastResponse; + cast: PersonResponse[]; crew: KeyValuePair[]; } export interface CastResponse{ - edges : PersonEdgeResponse[] -} -export interface PersonEdgeResponse{ - node: PersonResponse + Person : PersonResponse[] } export interface KeyValuePair { diff --git a/server/nt.microservice/services/MovieService/MovieService.Api/Helpers/GraphQL.cs b/server/nt.microservice/services/MovieService/MovieService.Api/Helpers/GraphQL.cs index 60b99d0f..c0c5d7b2 100644 --- a/server/nt.microservice/services/MovieService/MovieService.Api/Helpers/GraphQL.cs +++ b/server/nt.microservice/services/MovieService/MovieService.Api/Helpers/GraphQL.cs @@ -1,5 +1,4 @@ using MovieService.GraphQL.Queries; -using MovieService.GraphQL.Types; namespace MovieService.Api.Helpers; @@ -8,7 +7,7 @@ public static class GraphQL public static void Register(IServiceCollection serviceCollection) { serviceCollection.AddGraphQLServer() - .AddQueryType() + .AddQueryType() .AddFiltering(); } } diff --git a/server/nt.microservice/services/MovieService/MovieService.Data.Interfaces/Entities/MovieEntity.cs b/server/nt.microservice/services/MovieService/MovieService.Data.Interfaces/Entities/MovieEntity.cs index cf268184..a5a37c26 100644 --- a/server/nt.microservice/services/MovieService/MovieService.Data.Interfaces/Entities/MovieEntity.cs +++ b/server/nt.microservice/services/MovieService/MovieService.Data.Interfaces/Entities/MovieEntity.cs @@ -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; } diff --git a/server/nt.microservice/services/MovieService/MovieService.Data.Interfaces/Services/IMovieCrudService.cs b/server/nt.microservice/services/MovieService/MovieService.Data.Interfaces/Services/IMovieCrudService.cs index b6bf37d6..0e687b01 100644 --- a/server/nt.microservice/services/MovieService/MovieService.Data.Interfaces/Services/IMovieCrudService.cs +++ b/server/nt.microservice/services/MovieService/MovieService.Data.Interfaces/Services/IMovieCrudService.cs @@ -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 SearchAsync(string searchTerm); + IAsyncEnumerable GetRecentMovies(int count = 10); } diff --git a/server/nt.microservice/services/MovieService/MovieService.Data/Seed/MalayalamMoviesSeed.cs b/server/nt.microservice/services/MovieService/MovieService.Data/Seed/MalayalamMoviesSeed.cs index 573da96e..ffb44eca 100644 --- a/server/nt.microservice/services/MovieService/MovieService.Data/Seed/MalayalamMoviesSeed.cs +++ b/server/nt.microservice/services/MovieService/MovieService.Data/Seed/MalayalamMoviesSeed.cs @@ -20,6 +20,7 @@ internal class MalayalamMoviesSeed { new("Dulquer Salmaan"), new("Thilakan"), new("Nithya Menen") } + }, new() { diff --git a/server/nt.microservice/services/MovieService/MovieService.Data/Services/MovieCrudService.cs b/server/nt.microservice/services/MovieService/MovieService.Data/Services/MovieCrudService.cs index 9921ab0a..d74753f0 100644 --- a/server/nt.microservice/services/MovieService/MovieService.Data/Services/MovieCrudService.cs +++ b/server/nt.microservice/services/MovieService/MovieService.Data/Services/MovieCrudService.cs @@ -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; @@ -32,4 +30,21 @@ public async IAsyncEnumerable SearchAsync(string searchTerm) } } } + + public async IAsyncEnumerable GetRecentMovies(int count = 10) + { + if (count <= 0) + yield break; + var cursor = await DB.Find() + .Sort(x=>x.Descending(x => x.ReleaseDate)) + .Limit(count) + .ExecuteCursorAsync(); + while (await cursor.MoveNextAsync()) + { + foreach (var movie in cursor.Current) + { + yield return movie; + } + } + } } diff --git a/server/nt.microservice/services/MovieService/MovieService.GraphQL/Class1.cs b/server/nt.microservice/services/MovieService/MovieService.GraphQL/Class1.cs deleted file mode 100644 index 598a5acd..00000000 --- a/server/nt.microservice/services/MovieService/MovieService.GraphQL/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MovieService.GraphQL -{ - public class Class1 - { - - } -} diff --git a/server/nt.microservice/services/MovieService/MovieService.GraphQL/MovieService.GraphQL.csproj b/server/nt.microservice/services/MovieService/MovieService.GraphQL/MovieService.GraphQL.csproj index 29151e29..86761107 100644 --- a/server/nt.microservice/services/MovieService/MovieService.GraphQL/MovieService.GraphQL.csproj +++ b/server/nt.microservice/services/MovieService/MovieService.GraphQL/MovieService.GraphQL.csproj @@ -9,6 +9,7 @@ + diff --git a/server/nt.microservice/services/MovieService/MovieService.GraphQL/Queries/MovieQuery.cs b/server/nt.microservice/services/MovieService/MovieService.GraphQL/Queries/MovieQuery.cs new file mode 100644 index 00000000..0765b241 --- /dev/null +++ b/server/nt.microservice/services/MovieService/MovieService.GraphQL/Queries/MovieQuery.cs @@ -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 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 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()) ?? [] + }; + } + } +} + + + diff --git a/server/nt.microservice/services/MovieService/MovieService.GraphQL/Queries/Query.cs b/server/nt.microservice/services/MovieService/MovieService.GraphQL/Queries/Query.cs deleted file mode 100644 index f8e550ec..00000000 --- a/server/nt.microservice/services/MovieService/MovieService.GraphQL/Queries/Query.cs +++ /dev/null @@ -1,26 +0,0 @@ -using HotChocolate; -using HotChocolate.Types; -using MovieService.GraphQL.Types; -using MovieService.Service.Interfaces.Dtos; -using MovieService.Service.Interfaces.Services; - -namespace MovieService.GraphQL.Queries; - -public class Query -{ - public IAsyncEnumerable FindMovie([Service]IMovieService movieService, string searchTerm) - { - return movieService.Search(searchTerm); - } -} - -public class QueryType : ObjectType -{ - protected override void Configure(IObjectTypeDescriptor descriptor) - { - descriptor.Field(x => x.FindMovie(default!, default!)) - .Type>() - .Argument("searchTerm", x=> x.Type()) - .Description("Find Movie by partial name"); - } -} diff --git a/server/nt.microservice/services/MovieService/MovieService.GraphQL/Types/MovieType.cs b/server/nt.microservice/services/MovieService/MovieService.GraphQL/Types/MovieType.cs index 90cf68d8..ef15843a 100644 --- a/server/nt.microservice/services/MovieService/MovieService.GraphQL/Types/MovieType.cs +++ b/server/nt.microservice/services/MovieService/MovieService.GraphQL/Types/MovieType.cs @@ -1,41 +1,39 @@ -using HotChocolate.Types; -using MovieService.Service.Interfaces.Dtos; +using HotChocolate; namespace MovieService.GraphQL.Types; -public class MovieType : ObjectType +public class MovieType { - protected override void Configure(IObjectTypeDescriptor descriptor) - { - descriptor.Description("Defines a movie"); - - descriptor.Field(x=>x.Title) - .Type() - .Description("Title of Movie"); - descriptor.Field(x=>x.MovieLanguage) - .Type() - .Description("Language of movie"); - descriptor.Field(x=>x.ReleaseDate) - .Type() - .Description("Release date of movie"); - descriptor.Field(x => x.Cast) - .Type>() - .UsePaging() - .Description("Cast of the movie"); - //descriptor.Field(x => x.Crew) - // .Type() - // .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 Cast { get; set; } = []; + + [GraphQLName("crew")] + [GraphQLDescription("Crew of the movie")] + public Dictionary>? Crew { get; set; } = []; } -public class PersonType : ObjectType +public class PersonType { - protected override void Configure(IObjectTypeDescriptor descriptor) - { - descriptor.Description("Defines a Person"); - - descriptor.Field(x => x.Name) - .Type>() - .Description("Name of the person"); - } + [GraphQLName("name")] + [GraphQLDescription("Name")] + public string Name { get; set; } = null!; } diff --git a/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Class1.cs b/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Class1.cs deleted file mode 100644 index 62d2af81..00000000 --- a/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MovieService.Service.Interfaces -{ - public class Class1 - { - - } -} diff --git a/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Dtos/MovieDto.cs b/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Dtos/MovieDto.cs index 90c71021..0e15f7d5 100644 --- a/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Dtos/MovieDto.cs +++ b/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Dtos/MovieDto.cs @@ -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; } diff --git a/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Services/IMovieService.cs b/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Services/IMovieService.cs index f0a450a2..f7d4f2ba 100644 --- a/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Services/IMovieService.cs +++ b/server/nt.microservice/services/MovieService/MovieService.Service.Interfaces/Services/IMovieService.cs @@ -6,4 +6,5 @@ public interface IMovieService { Task CreateMovie(MovieDto movie); IAsyncEnumerable Search(string searchTerm); + IAsyncEnumerable GetRecentMovies(int count = 10); } diff --git a/server/nt.microservice/services/MovieService/MovieService.Service/Services/MovieService.cs b/server/nt.microservice/services/MovieService/MovieService.Service/Services/MovieService.cs index d8586e28..7cbf48b7 100644 --- a/server/nt.microservice/services/MovieService/MovieService.Service/Services/MovieService.cs +++ b/server/nt.microservice/services/MovieService/MovieService.Service/Services/MovieService.cs @@ -5,6 +5,7 @@ using MovieService.Service.Interfaces.Services; using Omu.ValueInjecter; using System.Linq; +using System.Threading.Tasks; namespace MovieService.Service.Services; @@ -41,6 +42,18 @@ public async Task CreateMovie(MovieDto movie) } + public async IAsyncEnumerable GetRecentMovies(int count = 10) + { + if (count <= 0) + yield break; + + await foreach(var movie in _movieCrudService.GetRecentMovies(count)) + { + yield return Mapper.Map(movie); + } + + } + public async IAsyncEnumerable Search(string searchTerm) { if(string.IsNullOrEmpty(searchTerm)) diff --git a/server/nt.microservice/services/ReviewService/ReviewService.Application.DTO/Reviews/Review.cs b/server/nt.microservice/services/ReviewService/ReviewService.Application.DTO/Reviews/Review.cs index b3cf4b5f..0aff9e2d 100644 --- a/server/nt.microservice/services/ReviewService/ReviewService.Application.DTO/Reviews/Review.cs +++ b/server/nt.microservice/services/ReviewService/ReviewService.Application.DTO/Reviews/Review.cs @@ -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!; }