-
Notifications
You must be signed in to change notification settings - Fork 0
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
ab36432
commit 39fee82
Showing
11 changed files
with
662 additions
and
662 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"assignment":"java-spring-ru/search"} | ||
{"assignment":"java-spring-ru/service-layer"} |
Empty file.
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 @@ | ||
rootProject.name = "service-layer" | ||
// spring.jpa.generate-ddl = true | ||
// spring.jpa.hibernate.ddl-auto | ||
rootProject.name = "service-layer" | ||
// spring.jpa.generate-ddl = true | ||
// spring.jpa.hibernate.ddl-auto |
134 changes: 67 additions & 67 deletions
134
java-spring-ru/service-layer/src/main/java/exercise/controller/AuthorsController.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,67 +1,67 @@ | ||
package exercise.controller; | ||
|
||
import exercise.dto.AuthorDTO; | ||
import exercise.dto.AuthorCreateDTO; | ||
import exercise.dto.AuthorUpdateDTO; | ||
import exercise.service.AuthorService; | ||
import jakarta.validation.Valid; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
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.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/authors") | ||
public class AuthorsController { | ||
|
||
@Autowired | ||
private AuthorService authorService; | ||
|
||
// BEGIN | ||
@GetMapping("") | ||
public ResponseEntity<List<AuthorDTO>> index() { | ||
var authors = authorService.getAll(); | ||
return ResponseEntity.ok() | ||
.body(authors); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<AuthorDTO> show(@PathVariable Long id) { | ||
var author = authorService.findById(id); | ||
return ResponseEntity.ok() | ||
.body(author); | ||
} | ||
|
||
@PostMapping("") | ||
public ResponseEntity<AuthorDTO> create(@RequestBody AuthorCreateDTO newAuthor) { | ||
var author = authorService.create(newAuthor); | ||
return ResponseEntity.created(URI.create("/authors")) | ||
.body(author); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<AuthorDTO> update(@PathVariable Long id, | ||
@RequestBody AuthorUpdateDTO editedAuthor) { | ||
var author = authorService.update(id, editedAuthor); | ||
return ResponseEntity.ok() | ||
.body(author); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<?> delete(@PathVariable Long id) { | ||
authorService.delete(id); | ||
return ResponseEntity.ok().build(); | ||
} | ||
// END | ||
} | ||
package exercise.controller; | ||
|
||
import exercise.dto.AuthorDTO; | ||
import exercise.dto.AuthorCreateDTO; | ||
import exercise.dto.AuthorUpdateDTO; | ||
import exercise.service.AuthorService; | ||
import jakarta.validation.Valid; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
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.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/authors") | ||
public class AuthorsController { | ||
|
||
@Autowired | ||
private AuthorService authorService; | ||
|
||
// BEGIN | ||
@GetMapping("") | ||
public ResponseEntity<List<AuthorDTO>> index() { | ||
var authors = authorService.getAll(); | ||
return ResponseEntity.ok() | ||
.body(authors); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<AuthorDTO> show(@PathVariable Long id) { | ||
var author = authorService.findById(id); | ||
return ResponseEntity.ok() | ||
.body(author); | ||
} | ||
|
||
@PostMapping("") | ||
public ResponseEntity<AuthorDTO> create(@RequestBody AuthorCreateDTO newAuthor) { | ||
var author = authorService.create(newAuthor); | ||
return ResponseEntity.created(URI.create("/authors")) | ||
.body(author); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<AuthorDTO> update(@PathVariable Long id, | ||
@RequestBody AuthorUpdateDTO editedAuthor) { | ||
var author = authorService.update(id, editedAuthor); | ||
return ResponseEntity.ok() | ||
.body(author); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<?> delete(@PathVariable Long id) { | ||
authorService.delete(id); | ||
return ResponseEntity.ok().build(); | ||
} | ||
// END | ||
} |
132 changes: 66 additions & 66 deletions
132
java-spring-ru/service-layer/src/main/java/exercise/controller/BooksController.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,66 +1,66 @@ | ||
package exercise.controller; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import exercise.dto.BookCreateDTO; | ||
import exercise.dto.BookDTO; | ||
import exercise.dto.BookUpdateDTO; | ||
import exercise.service.BookService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
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.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import jakarta.validation.Valid; | ||
|
||
@RestController | ||
@RequestMapping("/books") | ||
public class BooksController { | ||
@Autowired | ||
private BookService bookService; | ||
|
||
// BEGIN | ||
@GetMapping("") | ||
public ResponseEntity<List<BookDTO>> index() { | ||
var books = bookService.getAll(); | ||
return ResponseEntity.ok() | ||
.body(books); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<BookDTO> show(@PathVariable Long id) { | ||
var book = bookService.findById(id); | ||
return ResponseEntity.ok() | ||
.body(book); | ||
} | ||
|
||
@PostMapping("") | ||
public ResponseEntity<BookDTO> create(@RequestBody BookCreateDTO newBook) { | ||
var book = bookService.create(newBook); | ||
return ResponseEntity.created(URI.create("/books")) | ||
.body(book); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<BookDTO> update(@PathVariable Long id, | ||
@RequestBody BookUpdateDTO editedBook) { | ||
var book = bookService.update(id, editedBook); | ||
return ResponseEntity.ok() | ||
.body(book); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<?> delete(@PathVariable Long id) { | ||
bookService.delete(id); | ||
return ResponseEntity.ok().build(); | ||
} | ||
// END | ||
} | ||
package exercise.controller; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import exercise.dto.BookCreateDTO; | ||
import exercise.dto.BookDTO; | ||
import exercise.dto.BookUpdateDTO; | ||
import exercise.service.BookService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
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.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import jakarta.validation.Valid; | ||
|
||
@RestController | ||
@RequestMapping("/books") | ||
public class BooksController { | ||
@Autowired | ||
private BookService bookService; | ||
|
||
// BEGIN | ||
@GetMapping("") | ||
public ResponseEntity<List<BookDTO>> index() { | ||
var books = bookService.getAll(); | ||
return ResponseEntity.ok() | ||
.body(books); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<BookDTO> show(@PathVariable Long id) { | ||
var book = bookService.findById(id); | ||
return ResponseEntity.ok() | ||
.body(book); | ||
} | ||
|
||
@PostMapping("") | ||
public ResponseEntity<BookDTO> create(@RequestBody BookCreateDTO newBook) { | ||
var book = bookService.create(newBook); | ||
return ResponseEntity.created(URI.create("/books")) | ||
.body(book); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<BookDTO> update(@PathVariable Long id, | ||
@RequestBody BookUpdateDTO editedBook) { | ||
var book = bookService.update(id, editedBook); | ||
return ResponseEntity.ok() | ||
.body(book); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<?> delete(@PathVariable Long id) { | ||
bookService.delete(id); | ||
return ResponseEntity.ok().build(); | ||
} | ||
// END | ||
} |
56 changes: 28 additions & 28 deletions
56
java-spring-ru/service-layer/src/main/java/exercise/mapper/AuthorMapper.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,28 +1,28 @@ | ||
package exercise.mapper; | ||
|
||
import exercise.dto.AuthorCreateDTO; | ||
import exercise.dto.AuthorDTO; | ||
import exercise.dto.AuthorUpdateDTO; | ||
import exercise.model.Author; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.NullValuePropertyMappingStrategy; | ||
import org.mapstruct.MappingConstants; | ||
import org.mapstruct.ReportingPolicy; | ||
import org.mapstruct.MappingTarget; | ||
|
||
@Mapper( | ||
uses = {JsonNullableMapper.class, ReferenceMapper.class}, | ||
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, | ||
componentModel = MappingConstants.ComponentModel.SPRING, | ||
unmappedTargetPolicy = ReportingPolicy.IGNORE | ||
) | ||
public abstract class AuthorMapper { | ||
|
||
// BEGIN | ||
public abstract Author map(AuthorCreateDTO dto); | ||
|
||
public abstract AuthorDTO map(Author model); | ||
// END | ||
|
||
public abstract void update(AuthorUpdateDTO dto, @MappingTarget Author model); | ||
} | ||
package exercise.mapper; | ||
|
||
import exercise.dto.AuthorCreateDTO; | ||
import exercise.dto.AuthorDTO; | ||
import exercise.dto.AuthorUpdateDTO; | ||
import exercise.model.Author; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.NullValuePropertyMappingStrategy; | ||
import org.mapstruct.MappingConstants; | ||
import org.mapstruct.ReportingPolicy; | ||
import org.mapstruct.MappingTarget; | ||
|
||
@Mapper( | ||
uses = {JsonNullableMapper.class, ReferenceMapper.class}, | ||
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, | ||
componentModel = MappingConstants.ComponentModel.SPRING, | ||
unmappedTargetPolicy = ReportingPolicy.IGNORE | ||
) | ||
public abstract class AuthorMapper { | ||
|
||
// BEGIN | ||
public abstract Author map(AuthorCreateDTO dto); | ||
|
||
public abstract AuthorDTO map(Author model); | ||
// END | ||
|
||
public abstract void update(AuthorUpdateDTO dto, @MappingTarget Author model); | ||
} |
Oops, something went wrong.