Skip to content

Commit baef88a

Browse files
Enriched the services with more data, and modified the schemas.
1 parent 17157b4 commit baef88a

File tree

7 files changed

+88
-25
lines changed

7 files changed

+88
-25
lines changed

src/AuthorManagement/AuthorManagement.Api/Models/Author.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ namespace AuthorManagement.Api.Models
55
{
66
public class Author
77
{
8-
public Author(Guid id, string firstName, string lastName, List<Book> books)
8+
public Author(Guid id, string firstName, string middleName, string lastName, bool isPenName, List<Author> aliases, List<Book> books)
99
{
1010
Id = id;
1111
FirstName = firstName;
12+
MiddleName = middleName;
1213
LastName = lastName;
13-
Books = books;
14-
}
15-
16-
public Author(string firstName, string lastName, List<Book> books)
17-
{
18-
FirstName = firstName;
19-
LastName = lastName;
14+
IsPenName = isPenName;
15+
Aliases = aliases;
2016
Books = books;
2117
}
2218

@@ -26,7 +22,11 @@ public Author()
2622

2723
public Guid Id { get; set; }
2824
public string FirstName { get; set; }
25+
public string MiddleName { get; set; }
2926
public string LastName { get; set; }
27+
public string FullName => string.IsNullOrWhiteSpace(MiddleName) ? $"{FirstName} {LastName}" : $"{FirstName} {MiddleName} {LastName}";
28+
public bool IsPenName { get; set; }
29+
public List<Author> Aliases { get; set; }
3030
public List<Book> Books { get; set; }
3131
}
3232
}

src/AuthorManagement/AuthorManagement.Api/Schemas/AuthorMutation.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ public AuthorMutation(IAuthorService service)
1919
[GraphQLMetadata("createAuthor")]
2020
public Task<Author> AddAuthorAsync(AuthorInput input)
2121
{
22-
var author = new Author(input.FirstName, input.LastName, new List<Book>()
23-
{
24-
new Book { Id = Guid.NewGuid() }
25-
});
22+
var author = new Author();
2623
return _service.AddAuthorAsync(author);
2724
}
2825
}

src/AuthorManagement/AuthorManagement.Api/Services/AuthorService.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,37 @@ public class AuthorService : IAuthorService
1212

1313
public AuthorService()
1414
{
15-
_authors = new List<Author>
15+
var everyonePoops = new Book
16+
{
17+
Id = new Guid("48de5cca-0266-40fc-a34b-22aaaff258f0")
18+
};
19+
20+
var expanseBooks = new List<Book>()
1621
{
17-
new Author(new Guid("d08a13f9-756c-4f25-8e5f-6cb7475e5246"), "Taro", "Gomi", new List<Book>()
22+
new Book
1823
{
19-
new Book { Id = new Guid("48de5cca-0266-40fc-a34b-22aaaff258f0")}
20-
})
24+
Id = new Guid("af5370ae-33f8-48b9-b5a0-eeb81190181b")
25+
},
26+
new Book
27+
{
28+
Id = new Guid("85ce8816-5fbf-443a-b512-b37ede78911a")
29+
},
30+
new Book
31+
{
32+
Id = new Guid("b4d706b1-5c58-478e-8158-44ab50759af7")
33+
}
34+
};
35+
36+
var jamesSACoreyAliases = new List<Author>()
37+
{
38+
new Author(new Guid("21c34f3d-089b-4e06-bc0d-cde8ffa16d3d"), "Daniel", null, "Abraham", false, new List<Author>(), new List<Book>()),
39+
new Author(new Guid("3c52ce95-5569-4836-8b0b-2e79cffaafb4"), "Ty", null, "Franck", false, new List<Author>(), new List<Book>())
40+
};
41+
42+
_authors = new List<Author>
43+
{
44+
new Author(new Guid("d08a13f9-756c-4f25-8e5f-6cb7475e5246"), "Taro", null, "Gomi", false, new List<Author>(), new List<Book>() { everyonePoops }),
45+
new Author(new Guid("2f775d9a-835e-4674-9b68-8ad29ccba6d6"), "James", "S.A.", "Corey", true, jamesSACoreyAliases, expanseBooks)
2146
};
2247
}
2348

src/AuthorManagement/AuthorManagement.Api/Startup.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ extend type Mutation {
6161
type Author @key(fields: ""id"") {
6262
id: ID!
6363
firstName: String
64+
middleName: String
6465
lastName: String
66+
fullName: String
67+
isPenName: Boolean
68+
aliases: [Author]
6569
books: [Book]
6670
}
6771

src/BookManagement/BookManagement.Api/Models/Book.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@ namespace BookManagement.Api.Models
44
{
55
public class Book
66
{
7-
public Book(Guid id, string title, string description, Author author)
7+
public Book(Guid id, string title, string overview, Author author, long isbn, string publisher,
8+
DateTime publicationDate, int pages)
89
{
910
Id = id;
1011
Title = title;
11-
Description = description;
12+
Overview = overview;
1213
Author = author;
14+
Isbn = isbn;
15+
Publisher = publisher;
16+
PublicationDate = publicationDate;
17+
Pages = pages;
1318
}
1419

1520
public Guid Id { get; set; }
1621
public string Title { get; set; }
17-
public string Description { get; set; }
22+
public string Overview { get; set; }
1823
public Author Author { get; set; }
24+
public long Isbn { get; set; }
25+
public string Publisher { get; set; }
26+
public DateTime PublicationDate { get; set; }
27+
public int Pages { get; set; }
1928
}
2029
}

src/BookManagement/BookManagement.Api/Services/BookService.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,36 @@ public class BookService : IBookService
1212

1313
public BookService()
1414
{
15+
var taroGomi = new Author
16+
{
17+
Id = new Guid("d08a13f9-756c-4f25-8e5f-6cb7475e5246")
18+
};
19+
20+
var jamesSACorey = new Author
21+
{
22+
Id = new Guid("2f775d9a-835e-4674-9b68-8ad29ccba6d6")
23+
};
24+
25+
var noAuthor = new Author
26+
{
27+
Id = Guid.Empty
28+
};
29+
1530
_books = new List<Book>()
1631
{
17-
new Book(new Guid("48de5cca-0266-40fc-a34b-22aaaff258f0"), "Everybody Poops", "A book about pooping", new Author
18-
{
19-
Id = new Guid("d08a13f9-756c-4f25-8e5f-6cb7475e5246")
20-
})
32+
new Book(new Guid("48de5cca-0266-40fc-a34b-22aaaff258f0"), "Everyone Poops",
33+
"Both a matter-of-fact, educational guide and a hilarious romp through poop territory.",
34+
taroGomi, 9781929132140, "Kane/Miller Book Publishers", DateTime.Parse("01/28/1993"), 28),
35+
new Book(new Guid("af5370ae-33f8-48b9-b5a0-eeb81190181b"), "Leviathan Wakes (Expanse Series #1)",
36+
"Humanity has colonized the solar system — Mars, the Moon, the Asteroid Belt and beyond — but the stars are still out of our reach./n/nJim Holden is XO of an ice miner making runs from the rings of Saturn to the mining stations of the Belt. When he and his crew stumble upon a derelict ship, the Scopuli, they find themselves in possession of a secret they never wanted. A secret that someone is willing to kill for — and kill on a scale unfathomable to Jim and his crew. War is brewing in the system unless he can find out who left the ship and why./n/nDetective Miller is looking for a girl. One girl in a system of billions, but her parents have money and money talks. When the trail leads him to the Scopuli and rebel sympathizer Holden, he realizes that this girl may be the key to everything./n/nHolden and Miller must thread the needle between the Earth government, the Outer Planet revolutionaries, and secretive corporations — and the odds are against them. But out in the Belt, the rules are different, and one small ship can change the fate of the universe.",
37+
jamesSACorey, 9780316129084, "Orbit", DateTime.Parse("06/15/2011"), 592),
38+
new Book(new Guid("85ce8816-5fbf-443a-b512-b37ede78911a"), "Caliban's War (Expanse Series #2)",
39+
"We are not alone./n/nOn Ganymede, breadbasket of the outer planets, a Martian marine watches as her platoon is slaughtered by a monstrous supersoldier. On Earth, a high-level politician struggles to prevent interplanetary war from reigniting. And on Venus, an alien protomolecule has overrun the planet, wreaking massive, mysterious changes and threatening to spread out into the solar system./n/nIn the vast wilderness of space, James Holden and the crew of the Rocinante have been keeping the peace for the Outer Planets Alliance.When they agree to help a scientist search war - torn Ganymede for a missing child, the future of humanity rests on whether a single ship can prevent an alien invasion that may have already begun. . .",
40+
jamesSACorey, 9780316129060, "Orbit", DateTime.Parse("06/26/2012"), 624),
41+
new Book(new Guid("b4d706b1-5c58-478e-8158-44ab50759af7"), "Abaddon's Gate (Expanse Series #3)",
42+
"For generations, the solar system — Mars, the Moon, the Asteroid Belt — was humanity's great frontier. Until now. The alien artifact working through its program under the clouds of Venus has appeared in Uranus's orbit, where it has built a massive gate that leads to a starless dark./n/nJim Holden and the crew of the Rocinante are part of a vast flotilla of scientific and military ships going out to examine the artifact. But behind the scenes, a complex plot is unfolding, with the destruction of Holden at its core. As the emissaries of the human race try to find whether the gate is an opportunity or a threat, the greatest danger is the one they brought with them./n/nAbaddon's Gate is a breakneck science fiction adventure following the critically acclaimed Caliban's War.",
43+
jamesSACorey, 9780316129077, "Orbit", DateTime.Parse("06/04/2013"), 566),
44+
2145
};
2246
}
2347

src/BookManagement/BookManagement.Api/Startup.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ public void ConfigureServices(IServiceCollection services)
3939
return FederatedSchema.For(@"
4040
type Book @key(fields: ""id"") {
4141
id: ID!
42-
title: String!
43-
description: String!
42+
title: String
43+
overview: String
4444
author: Author
45+
isbn: Long
46+
publisher: String
47+
publicationDate: Date
48+
pages: Int
4549
}
4650
4751
extend type Query {

0 commit comments

Comments
 (0)