Skip to content
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
01cd71a
updating main
bscott519 Aug 20, 2025
c4f01ed
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Aug 20, 2025
07cd146
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Aug 20, 2025
0f069d0
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Aug 24, 2025
679067f
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Aug 25, 2025
064560c
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Aug 27, 2025
acb9d5a
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Aug 27, 2025
0a5c684
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Aug 28, 2025
a856d55
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 1, 2025
4427712
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 4, 2025
add9ed5
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 4, 2025
a758076
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 5, 2025
603074a
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 8, 2025
56c45b2
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 9, 2025
6a1d48d
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 11, 2025
61d6181
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 14, 2025
b93d894
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 23, 2025
a8bf019
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 25, 2025
a5951ee
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 26, 2025
8554585
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Sep 30, 2025
78c872b
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Oct 1, 2025
5e81c04
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Oct 2, 2025
a58c860
Merge branch 'main' of https://github.com/bscott519/code-society-25-2
bscott519 Oct 3, 2025
ec47846
created functions for API and working on making them functional
bscott519 Oct 5, 2025
9031277
implemented the required functions, trying to make all tests pass
bscott519 Oct 6, 2025
33bd84c
Delete package.json
bscott519 Oct 6, 2025
d0638a7
Delete package-lock.json
bscott519 Oct 6, 2025
7429b28
Delete lesson_04/benjaminscott/bscottREADME.md
bscott519 Oct 6, 2025
3d7c4c2
all tests pass
bscott519 Oct 6, 2025
e81a25c
Merge branch 'feat/lesson23' of https://github.com/bscott519/code-soc…
bscott519 Oct 6, 2025
290065a
Delete lesson_06/benjaminscott/jest.config.js
bscott519 Oct 6, 2025
139f885
Delete lesson_06/benjaminscott/jest.config.json
bscott519 Oct 6, 2025
e4d5c24
Delete lesson_06/benjaminscott/stretchfunc.test.ts
bscott519 Oct 6, 2025
30134f3
Delete lesson_06/benjaminscott/stretchfunc.ts
bscott519 Oct 6, 2025
daae54e
Delete lesson_06/benjaminscott/tsconfig.json
bscott519 Oct 6, 2025
5cab2a2
ran spotlessApply and all tests pass
bscott519 Oct 9, 2025
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 @@ -4,12 +4,18 @@
import com.codedifferently.lesson23.library.Library;
import com.codedifferently.lesson23.library.MediaItem;
import com.codedifferently.lesson23.library.search.SearchCriteria;
import jakarta.validation.Valid;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -31,4 +37,60 @@ public ResponseEntity<GetMediaItemsResponse> getItems() {
var response = GetMediaItemsResponse.builder().items(responseItems).build();
return ResponseEntity.ok(response);
}

@PostMapping("/items")
public ResponseEntity<CreateMediaItemResponse> addItem(
@Valid @RequestBody CreateMediaItemRequest request) {
try {
MediaItem mediaItem = MediaItemRequest.asMediaItem(request.getItem());
library.addMediaItem(mediaItem, librarian);
CreateMediaItemResponse response =
CreateMediaItemResponse.builder().item(MediaItemResponse.from(mediaItem)).build();
return ResponseEntity.ok(response);
} catch (Exception e) {
return ResponseEntity.badRequest().build();
}
}

@GetMapping("/items/{id}")
public ResponseEntity<MediaItemResponse> getItem(@PathVariable String id) {
UUID uuid;
try {
uuid = UUID.fromString(id);
} catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().build();
}
SearchCriteria criteria = new SearchCriteria();
criteria.id = uuid.toString();
Set<MediaItem> items = library.search(criteria);
MediaItem item = items.stream().findFirst().orElse(null);
if (item == null) {
return ResponseEntity.notFound().build();
}
MediaItemResponse response = MediaItemResponse.from(item);
return ResponseEntity.ok(response);
}

@DeleteMapping("/items/{id}")
public ResponseEntity<Void> deleteItem(@PathVariable String id) {
UUID uuid;
try {
uuid = UUID.fromString(id);
} catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().build();
}
SearchCriteria criteria = new SearchCriteria();
criteria.id = uuid.toString();
Set<MediaItem> items = library.search(criteria);
MediaItem item = items.stream().findFirst().orElse(null);
if (item == null) {
return ResponseEntity.notFound().build();
}
try {
library.removeMediaItem(uuid, librarian);
} catch (Exception e) {
return ResponseEntity.status(409).build();
}
return ResponseEntity.noContent().build();
}
}