Skip to content

Commit 089e917

Browse files
committed
reformat code
1 parent ec48234 commit 089e917

14 files changed

+66
-59
lines changed

src/main/java/com/example/controller/BookController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.example.controller;
22

3+
import com.example.model.Book;
34
import com.example.model.dto.BookDTO;
45
import com.example.service.BookService;
5-
import com.example.model.Book;
66
import io.micronaut.http.HttpMessage;
77
import io.micronaut.http.HttpResponse;
88
import io.micronaut.http.HttpStatus;
@@ -34,11 +34,12 @@ public List<BookDTO> books() {
3434
}
3535

3636
@Get("/model")
37-
public List<Book> find(){
37+
public List<Book> find() {
3838
return service.find();
3939
}
40+
4041
@Get("/title")
41-
public Book find(@QueryValue String title){
42+
public Book find(@QueryValue String title) {
4243
return service.findByTitle(title);
4344
}
4445

@@ -55,7 +56,7 @@ public HttpMessage create(Book book) {
5556
}
5657

5758
@Delete("{id}")
58-
public HttpMessage delete(@PathVariable Long id){
59+
public HttpMessage delete(@PathVariable Long id) {
5960

6061
service.delete(id);
6162

src/main/java/com/example/controller/GreetController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.example.controller;
22

33
import com.example.service.GreetingService;
4-
import io.micronaut.http.MediaType;
5-
import io.micronaut.http.annotation.Body;
64
import io.micronaut.http.annotation.Controller;
75
import io.micronaut.http.annotation.Get;
86
import io.micronaut.http.annotation.Post;
@@ -17,11 +15,11 @@ public class GreetController {
1715

1816
@Get("/{name}")
1917
public String greet(String name) {
20-
return greetingService.getGreeting() + " " + name;
18+
return greetingService.getGreeting() + " " + name;
2119
}
2220

2321
@Post("/post")
2422
public String setGreeting(@QueryValue String name) {
25-
return greetingService.getGreeting() + " " + name;
23+
return greetingService.getGreeting() + " " + name;
2624
}
2725
}

src/main/java/com/example/model/Book.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package com.example.model;
22

3-
import javax.persistence.*;
3+
import javax.persistence.Entity;
4+
import javax.persistence.FetchType;
5+
import javax.persistence.GeneratedValue;
6+
import javax.persistence.GenerationType;
7+
import javax.persistence.Id;
8+
import javax.persistence.JoinColumn;
9+
import javax.persistence.ManyToOne;
10+
import javax.persistence.Table;
411

512
@Entity
613
@Table(name = "books")

src/main/java/com/example/repository/AuthorRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
import io.micronaut.data.repository.CrudRepository;
66

77
@Repository
8-
public interface AuthorRepository extends CrudRepository<Author, Long> {
8+
public interface AuthorRepository extends CrudRepository<Author, Long> {
99
}

src/main/java/com/example/repository/BookRepository.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import com.example.model.Book;
44
import com.example.model.dto.BookDTO;
55
import io.micronaut.context.annotation.Executable;
6-
import io.micronaut.data.annotation.*;
6+
import io.micronaut.data.annotation.Join;
7+
import io.micronaut.data.annotation.Repository;
78
import io.micronaut.data.jpa.annotation.EntityGraph;
89
import io.micronaut.data.jpa.repository.JpaSpecificationExecutor;
910
import io.micronaut.data.repository.CrudRepository;
@@ -17,10 +18,12 @@ public interface BookRepository extends CrudRepository<Book, Long>, JpaSpecifica
1718
@Join(value = "author", type = Join.Type.FETCH)
1819
Book findByTitle(String title);
1920

20-
@Join(value = "author", type = Join.Type.FETCH) //
21+
@Join(value = "author", type = Join.Type.FETCH)
22+
//
2123
List<Book> list();
2224

23-
@EntityGraph(attributePaths = {"author", "title"}) //
25+
@EntityGraph(attributePaths = {"author", "title"})
26+
//
2427
List<Book> findAll();
2528

2629
List<BookDTO> find();

src/main/java/com/example/service/AuthorService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class AuthorService {
1313
AuthorRepository repository;
1414

1515

16-
public void getAll(){
16+
public void getAll() {
1717
repository.findAll();
1818
}
1919
}

src/main/java/com/example/service/BookService.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class BookService {
2020
BookRepository repository;
2121

2222
@Transactional
23-
public void initDataBase(){
23+
public void initDataBase() {
2424

2525
Book book = new Book();
2626
book.setTitle("The Stand");
@@ -29,29 +29,30 @@ public void initDataBase(){
2929
}
3030

3131
@Transactional
32-
public List<BookDTO> findAll(){
32+
public List<BookDTO> findAll() {
3333

3434
return repository.find();
3535
}
3636

3737
@Transactional
38-
public List<Book> find(){
38+
public List<Book> find() {
3939
return repository.list();
4040
}
4141

4242

4343
@Transactional
44-
public Book findByTitle(String title){
44+
public Book findByTitle(String title) {
4545
return repository.findByTitle(title);
4646
}
4747

4848

4949
@Transactional
50-
public Long countBooks(){
50+
public Long countBooks() {
5151
return repository.count();
5252
}
53+
5354
@Transactional
54-
public Book fall(){
55+
public Book fall() {
5556

5657
return repository
5758
.findById(null)
@@ -70,12 +71,12 @@ public void delete(Long id) {
7071
repository.deleteById(id);
7172
}
7273

73-
@Transactional
74+
@Transactional
7475
public void updateName(Long id, String title) {
7576

7677
Optional<Book> book = repository.findById(id);
7778

78-
if(book.isPresent()) {
79+
if (book.isPresent()) {
7980
Book bookUpdated = book.get();
8081
bookUpdated.setTitle(title);
8182
repository.update(bookUpdated);

src/main/java/com/example/service/GreetingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@Singleton
88
public class GreetingService {
99

10-
public String getGreeting(){
10+
public String getGreeting() {
1111

1212
return "Hi, nice to see you here";
1313

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ micronaut:
22
application:
33
name: demo
44
server:
5-
port: 8081
5+
port: 8081
66
netty:
77
default:
88
allocator:

src/main/resources/db/liquibase-changelog.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
88

99
<changeSet id="001" author="ivan_tsiupa">
10-
<sql>
11-
CREATE TABLE IF NOT EXISTS books
12-
(
13-
id BIGSERIAL NOT NULL,
14-
title TEXT NOT NULL,
15-
pages BIGINT NOT NULL,
16-
PRIMARY KEY (id)
17-
);
10+
<sql>
11+
CREATE TABLE IF NOT EXISTS books
12+
(
13+
id BIGSERIAL NOT NULL,
14+
title TEXT NOT NULL,
15+
pages BIGINT NOT NULL,
16+
PRIMARY KEY (id)
17+
);
1818

19-
</sql>
19+
</sql>
2020
</changeSet>
2121

2222
<changeSet id="002" author="ivan_tsiupa">
@@ -52,9 +52,9 @@
5252
<changeSet id="005" author="ivan_tsiupa">
5353
<sql>
5454
CREATE TABLE IF NOT EXISTS authors (
55-
id BIGSERIAL NOT NULL,
56-
full_name TEXT NOT NULL,
57-
PRIMARY KEY (id)
55+
id BIGSERIAL NOT NULL,
56+
full_name TEXT NOT NULL,
57+
PRIMARY KEY (id)
5858
);
5959
</sql>
6060
</changeSet>

src/main/resources/logback.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
<!-- encoders are assigned the type
66
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
77
<encoder>
8-
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
8+
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n
9+
</pattern>
910
</encoder>
1011
</appender>
1112

1213
<root level="info">
13-
<appender-ref ref="STDOUT" />
14+
<appender-ref ref="STDOUT"/>
1415
</root>
1516
</configuration>

src/test/java/com/example/DemoTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import io.micronaut.runtime.EmbeddedApplication;
44
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
5-
import org.junit.jupiter.api.Test;
6-
import org.junit.jupiter.api.Assertions;
7-
85
import jakarta.inject.Inject;
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.Test;
98

109
@MicronautTest
1110
class DemoTest {

src/test/java/com/example/controller/BookControllerTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
import com.example.model.Book;
44
import com.google.gson.reflect.TypeToken;
55
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
6-
import io.restassured.internal.mapping.GsonMapper;
76
import io.restassured.response.Response;
87
import io.restassured.specification.RequestSpecification;
9-
import net.bytebuddy.description.method.MethodDescription;
108
import org.junit.jupiter.api.Test;
119

12-
import java.sql.Array;
1310
import java.util.ArrayList;
1411
import java.util.List;
1512

16-
import static org.hamcrest.Matchers.hasSize;
17-
import static org.hamcrest.Matchers.is;
18-
import static org.junit.jupiter.api.Assertions.*;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
1914

2015
@MicronautTest
2116
class BookControllerTest {
@@ -24,8 +19,10 @@ class BookControllerTest {
2419
@Test
2520
void testInitDB(RequestSpecification spec) {
2621
spec
27-
.when().get("/book/init")
28-
.then().statusCode(200);
22+
.when()
23+
.get("/book/init")
24+
.then()
25+
.statusCode(200);
2926
}
3027

3128
@Test
@@ -35,11 +32,11 @@ void testGetBooks(RequestSpecification spec) {
3532
.get("/book")
3633
.andReturn();
3734

38-
res.then().statusCode(200);
35+
res.then().statusCode(200);
3936

40-
List<Book> list = res.body().as( new TypeToken<ArrayList<Book>>() {}.getType());
37+
List<Book> list = res.body().as(new TypeToken<ArrayList<Book>>() {}.getType());
4138

42-
assertTrue(list.size() == 7 || list.size() == 8);
39+
assertTrue(list.size() == 7 || list.size() == 8);
4340
}
4441

4542
}

src/test/java/com/example/controller/GreetControllerTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ void testHelloWorld(RequestSpecification spec) {
2323
}
2424

2525
@Test
26-
void testPostHelloWorld(RequestSpecification spec){
26+
void testPostHelloWorld(RequestSpecification spec) {
2727
HashMap<String, String> params = new HashMap<>();
2828
params.put("name", "Ivan");
2929

3030
spec
3131
.when()
32-
.contentType(ContentType.JSON)
33-
.queryParam("name", "Ivan")
34-
.post("/greet/post")
35-
.then()
36-
.statusCode(200)
37-
.body(is("Hi, nice to see you here Ivan"));
32+
.contentType(ContentType.JSON)
33+
.queryParam("name", "Ivan")
34+
.post("/greet/post")
35+
.then()
36+
.statusCode(200)
37+
.body(is("Hi, nice to see you here Ivan"));
3838

3939
}
4040

0 commit comments

Comments
 (0)