Skip to content

Commit 1741f18

Browse files
committed
chore: fix formatting and minor naming changes
1 parent fd15a1a commit 1741f18

36 files changed

+862
-772
lines changed

lesson_26/api/java/api_app/src/main/java/com/codedifferently/lesson26/web/MediaItemRequest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.codedifferently.lesson26.library.Dvd;
55
import com.codedifferently.lesson26.library.Magazine;
66
import com.codedifferently.lesson26.library.MediaItem;
7-
import com.codedifferently.lesson26.library.MediaType;
87
import com.codedifferently.lesson26.library.Newspaper;
98
import jakarta.validation.constraints.NotBlank;
109
import java.util.List;
@@ -19,8 +18,9 @@
1918
@NoArgsConstructor
2019
@Builder
2120
public class MediaItemRequest {
21+
2222
private UUID id;
23-
private MediaType type;
23+
private String type;
2424
private String isbn;
2525

2626
@NotBlank(message = "Title is required")
@@ -33,17 +33,17 @@ public class MediaItemRequest {
3333

3434
public static MediaItem asMediaItem(MediaItemRequest request) {
3535
var id = request.id != null ? request.id : UUID.randomUUID();
36-
switch (request.type) {
37-
case BOOK -> {
36+
switch (request.type.toUpperCase()) {
37+
case "book" -> {
3838
return new Book(id, request.title, request.isbn, List.of(request.authors), request.pages);
3939
}
40-
case DVD -> {
40+
case "dvd" -> {
4141
return new Dvd(id, request.title);
4242
}
43-
case MAGAZINE -> {
43+
case "magazine" -> {
4444
return new Magazine(id, request.title);
4545
}
46-
case NEWSPAPER -> {
46+
case "newspaper" -> {
4747
return new Newspaper(id, request.title);
4848
}
4949
default -> throw new IllegalArgumentException("Unknown media item type: " + request.type);

lesson_26/api/java/api_app/src/main/java/com/codedifferently/lesson26/web/MediaItemResponse.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.codedifferently.lesson26.library.Book;
44
import com.codedifferently.lesson26.library.MediaItem;
5-
import com.codedifferently.lesson26.library.MediaType;
65
import java.util.List;
76
import java.util.UUID;
87
import lombok.Builder;
@@ -11,7 +10,8 @@
1110
@Data
1211
@Builder
1312
public class MediaItemResponse {
14-
private MediaType type;
13+
14+
private String type;
1515
private UUID id;
1616
private String isbn;
1717
private String title;
@@ -22,7 +22,10 @@ public class MediaItemResponse {
2222

2323
public static MediaItemResponse from(MediaItem item) {
2424
var result =
25-
MediaItemResponse.builder().id(item.getId()).title(item.getTitle()).type(item.getType());
25+
MediaItemResponse.builder()
26+
.id(item.getId())
27+
.title(item.getTitle())
28+
.type(item.getType().name().toLowerCase());
2629

2730
switch (item.getType()) {
2831
case BOOK -> {

lesson_26/api/javascript/api_app/src/data/data.module.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { LIBRARY_DATA_LOADER_PROVIDER } from './library_data_loader';
33
import { LibraryJsonDataLoader } from './library_json_data_loader';
44

55
@Module({
6-
providers: [{
7-
provide: LIBRARY_DATA_LOADER_PROVIDER,
8-
useClass: LibraryJsonDataLoader
9-
}],
10-
exports: [LIBRARY_DATA_LOADER_PROVIDER]
6+
providers: [
7+
{
8+
provide: LIBRARY_DATA_LOADER_PROVIDER,
9+
useClass: LibraryJsonDataLoader,
10+
},
11+
],
12+
exports: [LIBRARY_DATA_LOADER_PROVIDER],
1113
})
12-
export class DataModule {}
14+
export class DataModule {}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export { DataModule } from './data.module';
2-
export { LIBRARY_DATA_LOADER_PROVIDER, LibraryDataLoader } from './library_data_loader';
3-
2+
export {
3+
LIBRARY_DATA_LOADER_PROVIDER,
4+
LibraryDataLoader,
5+
} from './library_data_loader';

lesson_26/api/javascript/api_app/src/data/library_data_loader.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ export const LIBRARY_DATA_LOADER_PROVIDER = Symbol('LibraryDataLoader');
44

55
/** An object that loads data from a source and returns a LibraryDataModel object. */
66
export interface LibraryDataLoader {
7-
/**
8-
* Load data from a source and return a LibraryDataModel object.
9-
*
10-
* @return A LibraryDataModel object.
11-
* @throws Error if an I/O error occurs.
12-
*/
13-
loadData(): Promise<LibraryDataModel>;
7+
/**
8+
* Load data from a source and return a LibraryDataModel object.
9+
*
10+
* @return A LibraryDataModel object.
11+
* @throws Error if an I/O error occurs.
12+
*/
13+
loadData(): Promise<LibraryDataModel>;
1414
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Injectable } from "@nestjs/common";
1+
import { Injectable } from '@nestjs/common';
22
import * as LibraryJsonData from '../../resources/data.json';
3-
import { LibraryDataModel } from "../models/library_data_model";
4-
import { LibraryDataLoader } from "./library_data_loader";
3+
import { LibraryDataModel } from '../models/library_data_model';
4+
import { LibraryDataLoader } from './library_data_loader';
55

66
@Injectable()
77
export class LibraryJsonDataLoader implements LibraryDataLoader {
8-
async loadData() {
9-
const { mediaItems, guests } = LibraryJsonData;
10-
return new LibraryDataModel(mediaItems, guests);
11-
}
12-
}
8+
async loadData() {
9+
const { mediaItems, guests } = LibraryJsonData;
10+
return new LibraryDataModel(mediaItems, guests);
11+
}
12+
}
Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,53 @@
1-
import { MediaItemBase } from "./media_item_base";
2-
import { MediaType } from "./media_type";
1+
import { MediaItemBase } from './media_item_base';
2+
import { MediaType } from './media_type';
33

44
export class Book extends MediaItemBase {
5-
private readonly isbn: string;
6-
private readonly authors: string[];
7-
private readonly numberOfPages: number;
8-
9-
constructor(id: string, title: string, isbn: string, authors: string[], numberOfPages: number) {
10-
super(id, title);
11-
this.isbn = isbn;
12-
this.authors = authors;
13-
this.numberOfPages = numberOfPages;
5+
private readonly isbn: string;
6+
private readonly authors: string[];
7+
private readonly numberOfPages: number;
8+
9+
constructor(
10+
id: string,
11+
title: string,
12+
isbn: string,
13+
authors: string[],
14+
numberOfPages: number,
15+
) {
16+
super(id, title);
17+
this.isbn = isbn;
18+
this.authors = authors;
19+
this.numberOfPages = numberOfPages;
20+
}
21+
22+
getType(): MediaType {
23+
return MediaType.BOOK;
24+
}
25+
26+
getIsbn(): string {
27+
return this.isbn;
28+
}
29+
30+
getAuthors(): string[] {
31+
return this.authors;
32+
}
33+
34+
getNumberOfPages(): number {
35+
return this.numberOfPages;
36+
}
37+
38+
protected matchesAuthor(authorQuery: string): boolean {
39+
if (!authorQuery) {
40+
return true;
1441
}
15-
16-
getType(): MediaType {
17-
return MediaType.BOOK;
18-
}
19-
20-
getIsbn(): string {
21-
return this.isbn;
22-
}
23-
24-
getAuthors(): string[] {
25-
return this.authors;
42+
for (const author of this.getAuthors()) {
43+
if (author.toLowerCase().includes(authorQuery.toLowerCase())) {
44+
return true;
45+
}
2646
}
47+
return false;
48+
}
2749

28-
getNumberOfPages(): number {
29-
return this.numberOfPages;
30-
}
31-
32-
protected matchesAuthor(authorQuery: string): boolean {
33-
if (!authorQuery) {
34-
return true;
35-
}
36-
for (const author of this.getAuthors()) {
37-
if (author.toLowerCase().includes(authorQuery.toLowerCase())) {
38-
return true;
39-
}
40-
}
41-
return false;
42-
}
43-
44-
toString(): string {
45-
return `Book{id='${this.getId()}', title='${this.getTitle()}'}`;
46-
}
47-
}
50+
toString(): string {
51+
return `Book{id='${this.getId()}', title='${this.getTitle()}'}`;
52+
}
53+
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { MediaItemBase } from "./media_item_base";
2-
import { MediaType } from "./media_type";
1+
import { MediaItemBase } from './media_item_base';
2+
import { MediaType } from './media_type';
33

44
export class Dvd extends MediaItemBase {
5-
constructor(id: string, title: string) {
6-
super(id, title);
7-
}
5+
constructor(id: string, title: string) {
6+
super(id, title);
7+
}
88

9-
getType(): MediaType {
10-
return MediaType.DVD;
11-
}
9+
getType(): MediaType {
10+
return MediaType.DVD;
11+
}
1212

13-
toString(): string {
14-
return `Dvd{id='${this.getId()}', title='${this.getTitle()}'}`;
15-
}
16-
}
13+
toString(): string {
14+
return `Dvd{id='${this.getId()}', title='${this.getTitle()}'}`;
15+
}
16+
}

lesson_26/api/javascript/api_app/src/library/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ export { MediaItem } from './media_item';
99
export { MediaType } from './media_type';
1010
export { Newspaper } from './newspaper';
1111
export { Patron } from './patron';
12-
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { LibraryGuestBase } from "./library_guest_base";
1+
import { LibraryGuestBase } from './library_guest_base';
22

33
/** Represents a librarian of a library. */
44
export class Librarian extends LibraryGuestBase {
5-
constructor(name: string, email: string) {
6-
super(name, email);
7-
}
5+
constructor(name: string, email: string) {
6+
super(name, email);
7+
}
88

9-
toString(): string {
10-
return `Librarian{id='${this.getEmail()}', name='${this.getName()}'}`;
11-
}
9+
toString(): string {
10+
return `Librarian{id='${this.getEmail()}', name='${this.getName()}'}`;
11+
}
1212
}

0 commit comments

Comments
 (0)