-
Notifications
You must be signed in to change notification settings - Fork 26
Feat: adds lesson 26 , amiyah jones' MediaItemsController #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 79 commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
8cc92d0
Create README.md
AmiyahJo 50b1861
Delete lesson_00/amiyahjones/README.md
AmiyahJo 27d57c0
Merge branch 'code-differently:main' into main
AmiyahJo fa3c700
Merge branch 'code-differently:main' into main
AmiyahJo 7c2d053
Merge branch 'code-differently:main' into main
AmiyahJo faedd1b
Merge branch 'code-differently:main' into main
AmiyahJo 19a4187
Merge branch 'code-differently:main' into main
AmiyahJo 7711266
Merge branch 'code-differently:main' into main
AmiyahJo 9a10c4c
Merge branch 'code-differently:main' into main
AmiyahJo 3ea50c4
Merge branch 'code-differently:main' into main
AmiyahJo d7b772d
Merge branch 'code-differently:main' into main
AmiyahJo de46b67
Merge branch 'code-differently:main' into main
AmiyahJo b891561
Merge branch 'code-differently:main' into main
AmiyahJo 7c9f2db
Merge branch 'code-differently:main' into main
AmiyahJo ff3ba35
Merge branch 'code-differently:main' into main
AmiyahJo 457feea
Merge branch 'code-differently:main' into main
AmiyahJo 5868f9d
Merge branch 'code-differently:main' into main
AmiyahJo 28eacd4
Merge branch 'code-differently:main' into main
AmiyahJo bca4933
Merge branch 'code-differently:main' into main
AmiyahJo 9ff0f9e
Merge branch 'code-differently:main' into main
AmiyahJo 8d02849
Merge branch 'code-differently:main' into main
AmiyahJo 6dd3a43
Merge branch 'code-differently:main' into main
AmiyahJo 95f56a5
Merge branch 'code-differently:main' into main
AmiyahJo 0f4dbac
Merge branch 'code-differently:main' into main
AmiyahJo a3b9984
Merge branch 'code-differently:main' into main
AmiyahJo 54cd199
Merge branch 'code-differently:main' into main
AmiyahJo edbe7c0
Merge branch 'code-differently:main' into main
AmiyahJo 7f0a084
Merge branch 'code-differently:main' into main
AmiyahJo a905b74
Merge branch 'code-differently:main' into main
AmiyahJo 2d69531
Merge branch 'code-differently:main' into main
AmiyahJo df48fbd
Merge branch 'code-differently:main' into main
AmiyahJo c972d14
Merge branch 'code-differently:main' into main
AmiyahJo bc3907c
Merge branch 'code-differently:main' into main
AmiyahJo c3eabbb
Merge branch 'code-differently:main' into main
AmiyahJo 9fff7d0
Merge branch 'code-differently:main' into main
AmiyahJo 4c57926
Merge branch 'code-differently:main' into main
AmiyahJo 8dd5d42
Merge branch 'code-differently:main' into main
AmiyahJo 18f65ee
Merge branch 'code-differently:main' into main
AmiyahJo 2dd1645
Merge branch 'code-differently:main' into main
AmiyahJo 0de8601
Merge branch 'code-differently:main' into main
AmiyahJo 85dd364
Merge branch 'code-differently:main' into main
AmiyahJo 0afda26
Merge branch 'code-differently:main' into main
AmiyahJo f31e8d9
Merge branch 'code-differently:main' into main
AmiyahJo 3e24069
Merge branch 'code-differently:main' into main
AmiyahJo 8600f6c
Merge branch 'code-differently:main' into main
AmiyahJo 563b076
Merge branch 'code-differently:main' into main
AmiyahJo b01a324
Merge branch 'code-differently:main' into main
AmiyahJo 697a72d
Merge branch 'code-differently:main' into main
AmiyahJo 92891f6
Merge branch 'code-differently:main' into main
AmiyahJo 17fdee5
Merge branch 'code-differently:main' into main
AmiyahJo cf7e6f2
Merge branch 'code-differently:main' into main
AmiyahJo a131bdc
Merge branch 'code-differently:main' into main
AmiyahJo c46d32f
Merge branch 'code-differently:main' into main
AmiyahJo 651fa01
Merge branch 'code-differently:main' into main
AmiyahJo e075fb7
Merge branch 'code-differently:main' into main
AmiyahJo ec7c3d1
Merge branch 'code-differently:main' into main
AmiyahJo 186c10e
Merge branch 'code-differently:main' into main
AmiyahJo e13bae6
Merge remote-tracking branch 'refs/remotes/origin/main'
8f999c6
Merge remote-tracking branch 'refs/remotes/origin/main'
af811ee
Merge branch 'code-differently:main' into main
AmiyahJo 8676657
Merge branch 'code-differently:main' into main
AmiyahJo 25f01e6
Merge branch 'code-differently:main' into main
AmiyahJo e132f49
Merge branch 'code-differently:main' into main
AmiyahJo aecfedd
Merge branch 'code-differently:main' into main
AmiyahJo 9730f82
Merge branch 'code-differently:main' into main
AmiyahJo 4f181fd
Merge branch 'code-differently:main' into main
AmiyahJo d6c62f9
Merge branch 'code-differently:main' into main
AmiyahJo 52373df
Merge branch 'code-differently:main' into main
AmiyahJo af515aa
Merge branch 'code-differently:main' into main
AmiyahJo 8cb5bfb
Merge branch 'code-differently:main' into main
AmiyahJo 2ef0eb8
Merge branch 'code-differently:main' into main
AmiyahJo f63b274
Merge branch 'code-differently:main' into main
AmiyahJo 226cc27
Merge branch 'code-differently:main' into main
AmiyahJo 6158bf8
Merge branch 'code-differently:main' into main
AmiyahJo 21119ab
Merge branch 'code-differently:main' into main
AmiyahJo d11b3b9
Merge branch 'code-differently:main' into main
AmiyahJo f8b8f39
Merge branch 'code-differently:main' into main
AmiyahJo 7e05f49
feat: adds media item controller methods
46c3e11
fix: ./gradlew :api_app:spotlessApply
301638e
Merge branch 'code-differently:main' into feature/lesson_26
AmiyahJo c0de66f
Merge branch 'code-differently:main' into feature/lesson_26
AmiyahJo 27aa27d
Merge branch 'code-differently:main' into feature/lesson_26
AmiyahJo bb55835
Merge branch 'code-differently:main' into feature/lesson_26
AmiyahJo 1928540
Merge branch 'code-differently:main' into feature/lesson_26
AmiyahJo 13038e5
Merge branch 'code-differently:main' into feature/lesson_26
AmiyahJo 33d0931
Merge branch 'code-differently:main' into feature/lesson_26
AmiyahJo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,21 @@ | |
import com.codedifferently.lesson26.library.Librarian; | ||
import com.codedifferently.lesson26.library.Library; | ||
import com.codedifferently.lesson26.library.MediaItem; | ||
import com.codedifferently.lesson26.library.exceptions.MediaItemCheckedOutException; | ||
import com.codedifferently.lesson26.library.search.SearchCriteria; | ||
import io.swagger.v3.oas.annotations.parameters.RequestBody; | ||
import jakarta.validation.Valid; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.springframework.http.HttpStatus; | ||
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.RestController; | ||
|
||
@RestController | ||
|
@@ -29,4 +38,53 @@ public GetMediaItemsResponse getItems() { | |
var response = GetMediaItemsResponse.builder().items(responseItems).build(); | ||
return response; | ||
} | ||
|
||
@GetMapping("/items/{id}") | ||
public ResponseEntity<MediaItemResponse> getItemById(@PathVariable("id") String id) { | ||
Set<MediaItem> items = library.search(SearchCriteria.builder().id(id).build()); | ||
if (items.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); | ||
} | ||
MediaItem item = items.iterator().next(); | ||
MediaItemResponse response = MediaItemResponse.from(item); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@PostMapping("/items") | ||
public ResponseEntity<?> addItem(@Valid @RequestBody MediaItemRequest request) { | ||
if (request == null) { | ||
return ResponseEntity.badRequest().body(Map.of("errors", List.of("Missing required fields"))); | ||
} | ||
|
||
MediaItem newItem; | ||
try { | ||
newItem = MediaItemRequest.asMediaItem(request); | ||
} catch (IllegalArgumentException e) { | ||
return ResponseEntity.badRequest() | ||
.body(Map.of("errors", List.of("Unknown media item type: " + request.getType()))); | ||
} | ||
|
||
library.addMediaItem(newItem, new Librarian("Jane Doe", "[email protected]")); | ||
|
||
return ResponseEntity.ok(Map.of("item", Map.of("id", newItem.getId().toString()))); | ||
} | ||
|
||
@DeleteMapping("/items/{id}") | ||
public ResponseEntity<Map<String, List<String>>> deleteItem(@PathVariable("id") String id) { | ||
Set<MediaItem> items = library.search(SearchCriteria.builder().id(id).build()); | ||
if (items.isEmpty()) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); | ||
} | ||
|
||
MediaItem item = items.iterator().next(); | ||
|
||
try { | ||
library.removeMediaItem(item, librarian); | ||
} catch (MediaItemCheckedOutException e) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST) | ||
.body(Map.of("errors", List.of(e.getMessage()))); | ||
} | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only error is that it expects the status 200 , but gets 400. Fixing this has been an issue
chatgpt expects me to manually include a book if statement , or a bindingResult <- both still gives the same 400 error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you had two problems. For one, you were using the wrong
@RequestBody
annotation so the request message was not being read correctly. Secondly, you should have preferred to accept theCreateMediaItemRequest
type which is the type of request the test anticipates sending.