Skip to content

Commit

Permalink
submit java-spring-ru/service-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
hexlet-cli committed Feb 20, 2024
1 parent ab36432 commit 39fee82
Show file tree
Hide file tree
Showing 11 changed files with 662 additions and 662 deletions.
2 changes: 1 addition & 1 deletion .current.json
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 modified java-spring-ru/service-layer/gradlew
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions java-spring-ru/service-layer/settings.gradle.kts
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
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
}
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
}
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);
}
Loading

0 comments on commit 39fee82

Please sign in to comment.