-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e8a3d0
commit 71773a6
Showing
17 changed files
with
30 additions
and
544 deletions.
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
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
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
3 changes: 0 additions & 3 deletions
3
aws-lambda-project/src/main/java/com/learning/awslambda/model/query/FindActorsQuery.java
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
aws-lambda-project/src/main/java/com/learning/awslambda/model/response/ActorResponse.java
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package com.learning.awslambda.model.response; | ||
|
||
public record ActorResponse(Long id, String text) {} | ||
public record ActorResponse(Long id, String name) {} |
27 changes: 0 additions & 27 deletions
27
aws-lambda-project/src/main/java/com/learning/awslambda/model/response/PagedResult.java
This file was deleted.
Oops, something went wrong.
5 changes: 4 additions & 1 deletion
5
aws-lambda-project/src/main/java/com/learning/awslambda/repositories/ActorRepository.java
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package com.learning.awslambda.repositories; | ||
|
||
import com.learning.awslambda.entities.Actor; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ActorRepository extends JpaRepository<Actor, Long> {} | ||
public interface ActorRepository extends JpaRepository<Actor, Long> { | ||
Optional<Actor> findByNameLike(String name); | ||
} |
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
63 changes: 5 additions & 58 deletions
63
aws-lambda-project/src/main/java/com/learning/awslambda/web/controllers/ActorController.java
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 |
---|---|---|
@@ -1,80 +1,27 @@ | ||
package com.learning.awslambda.web.controllers; | ||
|
||
import com.learning.awslambda.exception.ActorNotFoundException; | ||
import com.learning.awslambda.model.query.FindActorsQuery; | ||
import com.learning.awslambda.model.request.ActorRequest; | ||
import com.learning.awslambda.model.response.ActorResponse; | ||
import com.learning.awslambda.model.response.PagedResult; | ||
import com.learning.awslambda.services.ActorService; | ||
import com.learning.awslambda.utils.AppConstants; | ||
import jakarta.validation.Valid; | ||
import java.net.URI; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
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.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
||
@RestController | ||
@RequestMapping("/api/actors") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class ActorController { | ||
|
||
private final ActorService actorService; | ||
|
||
@GetMapping | ||
public PagedResult<ActorResponse> getAllActors( | ||
@RequestParam(value = "pageNo", defaultValue = AppConstants.DEFAULT_PAGE_NUMBER, required = false) | ||
int pageNo, | ||
@RequestParam(value = "pageSize", defaultValue = AppConstants.DEFAULT_PAGE_SIZE, required = false) | ||
int pageSize, | ||
@RequestParam(value = "sortBy", defaultValue = AppConstants.DEFAULT_SORT_BY, required = false) | ||
String sortBy, | ||
@RequestParam(value = "sortDir", defaultValue = AppConstants.DEFAULT_SORT_DIRECTION, required = false) | ||
String sortDir) { | ||
FindActorsQuery findActorsQuery = new FindActorsQuery(pageNo, pageSize, sortBy, sortDir); | ||
return actorService.findAllActors(findActorsQuery); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<ActorResponse> getActorById(@PathVariable Long id) { | ||
return actorService.findActorById(id).map(ResponseEntity::ok).orElseThrow(() -> new ActorNotFoundException(id)); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<ActorResponse> createActor(@RequestBody @Validated ActorRequest actorRequest) { | ||
ActorResponse response = actorService.saveActor(actorRequest); | ||
URI location = ServletUriComponentsBuilder.fromCurrentRequest() | ||
.path("/api/actors/{id}") | ||
.buildAndExpand(response.id()) | ||
.toUri(); | ||
return ResponseEntity.created(location).body(response); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<ActorResponse> updateActor( | ||
@PathVariable Long id, @RequestBody @Valid ActorRequest actorRequest) { | ||
return ResponseEntity.ok(actorService.updateActor(id, actorRequest)); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<ActorResponse> deleteActor(@PathVariable Long id) { | ||
@GetMapping("/{name}") | ||
public ResponseEntity<ActorResponse> getActorByName(@PathVariable String name) { | ||
return actorService | ||
.findActorById(id) | ||
.map(actor -> { | ||
actorService.deleteActorById(id); | ||
return ResponseEntity.ok(actor); | ||
}) | ||
.orElseThrow(() -> new ActorNotFoundException(id)); | ||
.findActorByName(name) | ||
.map(ResponseEntity::ok) | ||
.orElseThrow(() -> new ActorNotFoundException(name)); | ||
} | ||
} |
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
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
60 changes: 0 additions & 60 deletions
60
aws-lambda-project/src/test/java/com/learning/awslambda/SqsListenerIntegrationTest.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.