Skip to content

Commit fff2a31

Browse files
committed
format using spotless
Signed-off-by: Kirill Mokevnin <[email protected]>
1 parent 9d2240a commit fff2a31

File tree

15 files changed

+151
-161
lines changed

15 files changed

+151
-161
lines changed

build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ dependencies {
4545
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1")
4646
}
4747

48+
spotless {
49+
java {
50+
importOrder()
51+
removeUnusedImports()
52+
eclipse()
53+
.sortMembersEnabled(true)
54+
formatAnnotations()
55+
indentWithSpaces(4)
56+
}
57+
}
58+
4859
tasks.test {
4960
useJUnitPlatform()
5061
testLogging {

src/main/java/io/hexlet/blog/Application.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package io.hexlet.blog;
22

3+
import net.datafaker.Faker;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.context.annotation.Bean;
67

7-
import net.datafaker.Faker;
8-
98
@SpringBootApplication
109
public class Application {
1110
public static void main(String[] args) {

src/main/java/io/hexlet/blog/component/DataInitializer.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package io.hexlet.blog.component;
22

3+
import io.hexlet.blog.model.User;
4+
import io.hexlet.blog.repository.UserRepository;
5+
import io.hexlet.blog.util.ModelGenerator;
6+
import lombok.AllArgsConstructor;
37
import org.instancio.Instancio;
48
import org.springframework.beans.factory.annotation.Autowired;
59
import org.springframework.boot.ApplicationArguments;
610
import org.springframework.boot.ApplicationRunner;
711
import org.springframework.stereotype.Component;
812

9-
import io.hexlet.blog.model.User;
10-
import io.hexlet.blog.repository.UserRepository;
11-
import io.hexlet.blog.util.ModelGenerator;
12-
import lombok.AllArgsConstructor;
13-
1413
@Component
1514
@AllArgsConstructor
1615
public class DataInitializer implements ApplicationRunner {

src/main/java/io/hexlet/blog/config/EncodersConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package io.hexlet.blog.config;
22

3+
import lombok.AllArgsConstructor;
34
import org.springframework.context.annotation.Bean;
45
import org.springframework.context.annotation.Configuration;
56
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
67
import org.springframework.security.crypto.password.PasswordEncoder;
78

8-
import lombok.AllArgsConstructor;
9-
109
@Configuration
1110
@AllArgsConstructor
1211
public class EncodersConfig {
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.hexlet.blog.config;
22

3+
import io.hexlet.blog.service.CustomUserDetailsService;
4+
import lombok.AllArgsConstructor;
35
import org.springframework.beans.factory.annotation.Autowired;
46
import org.springframework.context.annotation.Bean;
57
import org.springframework.context.annotation.Configuration;
@@ -13,9 +15,6 @@
1315
import org.springframework.security.web.SecurityFilterChain;
1416
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
1517

16-
import io.hexlet.blog.service.CustomUserDetailsService;
17-
import lombok.AllArgsConstructor;
18-
1918
@Configuration
2019
@EnableWebSecurity
2120
@AllArgsConstructor
@@ -26,16 +25,9 @@ public class SecurityConfig {
2625
@Autowired
2726
private CustomUserDetailsService userService;
2827

29-
@Bean
30-
public SecurityFilterChain securityFilterChain(HttpSecurity http, HandlerMappingIntrospector introspector)
31-
throws Exception {
32-
return http.build();
33-
}
34-
3528
@Bean
3629
public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception {
37-
return http.getSharedObject(AuthenticationManagerBuilder.class)
38-
.build();
30+
return http.getSharedObject(AuthenticationManagerBuilder.class).build();
3931
}
4032

4133
@Bean
@@ -45,4 +37,10 @@ public AuthenticationProvider daoAuthProvider(AuthenticationManagerBuilder auth)
4537
provider.setPasswordEncoder(passwordEncoder);
4638
return provider;
4739
}
40+
41+
@Bean
42+
public SecurityFilterChain securityFilterChain(HttpSecurity http, HandlerMappingIntrospector introspector)
43+
throws Exception {
44+
return http.build();
45+
}
4846
}

src/main/java/io/hexlet/blog/exception/ResourceNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.springframework.web.bind.annotation.ResponseStatus;
55

66
@ResponseStatus(HttpStatus.NOT_FOUND)
7-
public class ResourceNotFoundException extends RuntimeException{
7+
public class ResourceNotFoundException extends RuntimeException {
88
public ResourceNotFoundException(String message) {
99
super(message);
1010
}

src/main/java/io/hexlet/blog/mapper/JsonNullableMapper.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
99
public abstract class JsonNullableMapper {
1010

11-
public <T> JsonNullable<T> wrap(T entity) {
12-
return JsonNullable.of(entity);
13-
}
11+
/**
12+
* Checks whether nullable parameter was passed explicitly.
13+
*
14+
* @return true if value was set explicitly, false otherwise
15+
*/
16+
@Condition
17+
public <T> boolean isPresent(JsonNullable<T> nullable) {
18+
return nullable != null && nullable.isPresent();
19+
}
1420

15-
public <T> T unwrap(JsonNullable<T> jsonNullable) {
16-
return jsonNullable == null ? null : jsonNullable.orElse(null);
17-
}
21+
public <T> T unwrap(JsonNullable<T> jsonNullable) {
22+
return jsonNullable == null ? null : jsonNullable.orElse(null);
23+
}
1824

19-
/**
20-
* Checks whether nullable parameter was passed explicitly.
21-
*
22-
* @return true if value was set explicitly, false otherwise
23-
*/
24-
@Condition
25-
public <T> boolean isPresent(JsonNullable<T> nullable) {
26-
return nullable != null && nullable.isPresent();
27-
}
25+
public <T> JsonNullable<T> wrap(T entity) {
26+
return JsonNullable.of(entity);
27+
}
2828
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package io.hexlet.blog.mapper;
22

3+
import io.hexlet.blog.model.BaseEntity;
4+
import jakarta.persistence.EntityManager;
35
import org.mapstruct.Mapper;
46
import org.mapstruct.MappingConstants;
57
import org.mapstruct.TargetType;
68
import org.springframework.beans.factory.annotation.Autowired;
79

8-
import io.hexlet.blog.model.BaseEntity;
9-
import jakarta.persistence.EntityManager;
10-
1110
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
1211
public abstract class ReferenceMapper {
13-
@Autowired
14-
private EntityManager entityManager;
12+
@Autowired
13+
private EntityManager entityManager;
1514

16-
public <T extends BaseEntity> T toEntity(Long id, @TargetType Class<T> entityClass) {
17-
return id != null ? entityManager.find(entityClass, id) : null;
18-
}
15+
public <T extends BaseEntity> T toEntity(Long id, @TargetType Class<T> entityClass) {
16+
return id != null ? entityManager.find(entityClass, id) : null;
17+
}
1918
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package io.hexlet.blog.mapper;
22

3+
import io.hexlet.blog.dto.UserDTO;
4+
import io.hexlet.blog.model.User;
35
import org.mapstruct.Mapper;
46
import org.mapstruct.MappingConstants;
57
import org.mapstruct.MappingTarget;
68
import org.mapstruct.NullValuePropertyMappingStrategy;
79
import org.mapstruct.ReportingPolicy;
810

9-
import io.hexlet.blog.dto.UserDTO;
10-
import io.hexlet.blog.model.User;
11-
12-
@Mapper(uses = { JsonNullableMapper.class,
13-
ReferenceMapper.class }, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING, unmappedTargetPolicy = ReportingPolicy.IGNORE)
11+
@Mapper(uses = {JsonNullableMapper.class,
12+
ReferenceMapper.class}, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING, unmappedTargetPolicy = ReportingPolicy.IGNORE)
1413
public abstract class UserMapper {
15-
public abstract User map(UserDTO model);
14+
public abstract UserDTO map(User model);
1615

17-
public abstract UserDTO map(User model);
16+
public abstract User map(UserDTO model);
1817

19-
public abstract void update(UserDTO update, @MappingTarget User destination);
18+
public abstract void update(UserDTO update, @MappingTarget User destination);
2019
}

src/main/java/io/hexlet/blog/model/User.java

Lines changed: 73 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
import static jakarta.persistence.GenerationType.IDENTITY;
44

5-
import java.util.ArrayList;
6-
import java.util.Collection;
7-
import java.util.Date;
8-
9-
import org.springframework.data.annotation.CreatedDate;
10-
import org.springframework.data.annotation.LastModifiedDate;
11-
import org.springframework.security.core.GrantedAuthority;
12-
import org.springframework.security.core.userdetails.UserDetails;
13-
145
import jakarta.persistence.Column;
156
import jakarta.persistence.Entity;
167
import jakarta.persistence.GeneratedValue;
178
import jakarta.persistence.Id;
189
import jakarta.persistence.Table;
1910
import jakarta.validation.constraints.NotBlank;
11+
import java.util.ArrayList;
12+
import java.util.Collection;
13+
import java.util.Date;
2014
import lombok.EqualsAndHashCode;
2115
import lombok.Getter;
2216
import lombok.Setter;
2317
import lombok.ToString;
18+
import org.springframework.data.annotation.CreatedDate;
19+
import org.springframework.data.annotation.LastModifiedDate;
20+
import org.springframework.security.core.GrantedAuthority;
21+
import org.springframework.security.core.userdetails.UserDetails;
2422

2523
@Entity
2624
@Getter
@@ -30,71 +28,70 @@
3028
@Table(name = "users")
3129
public class User implements UserDetails, BaseEntity {
3230

33-
@Id
34-
@GeneratedValue(strategy = IDENTITY)
35-
@ToString.Include
36-
@EqualsAndHashCode.Include
37-
private Long id;
38-
39-
// EMAIL
40-
@Column(unique = true)
41-
@ToString.Include
42-
private String email;
43-
44-
// @NotBlank
45-
@ToString.Include
46-
private String firstName;
47-
48-
// @NotBlank
49-
@ToString.Include
50-
private String lastName;
51-
52-
@NotBlank
53-
private String passwordDigest;
54-
55-
@LastModifiedDate
56-
private Date updatedAt;
57-
58-
@CreatedDate
59-
private Date createdAt;
60-
61-
// @Override
62-
// public String getPassword() {
63-
// return password;
64-
// }
65-
66-
@Override
67-
public String getUsername() {
68-
return email;
69-
}
70-
71-
@Override
72-
public String getPassword() {
73-
return passwordDigest;
74-
}
75-
76-
@Override
77-
public boolean isEnabled() {
78-
return true;
79-
}
80-
81-
@Override
82-
public Collection<? extends GrantedAuthority> getAuthorities() {
83-
return new ArrayList<GrantedAuthority>();
84-
}
85-
86-
@Override
87-
public boolean isAccountNonExpired() {
88-
return true;
89-
}
90-
91-
@Override
92-
public boolean isAccountNonLocked() {
93-
return true;
94-
}
95-
96-
@Override
97-
public boolean isCredentialsNonExpired() {
98-
return true;
99-
}
31+
@Id
32+
@GeneratedValue(strategy = IDENTITY)
33+
@ToString.Include
34+
@EqualsAndHashCode.Include
35+
private Long id;
36+
37+
// EMAIL
38+
@Column(unique = true)
39+
@ToString.Include
40+
private String email;
41+
42+
// @NotBlank
43+
@ToString.Include
44+
private String firstName;
45+
46+
// @NotBlank
47+
@ToString.Include
48+
private String lastName;
49+
50+
@NotBlank private String passwordDigest;
51+
52+
@LastModifiedDate
53+
private Date updatedAt;
54+
55+
@CreatedDate
56+
private Date createdAt;
57+
58+
// @Override
59+
// public String getPassword() {
60+
// return password;
61+
// }
62+
63+
@Override
64+
public Collection<? extends GrantedAuthority> getAuthorities() {
65+
return new ArrayList<GrantedAuthority>();
66+
}
67+
68+
@Override
69+
public String getPassword() {
70+
return passwordDigest;
71+
}
72+
73+
@Override
74+
public String getUsername() {
75+
return email;
76+
}
77+
78+
@Override
79+
public boolean isAccountNonExpired() {
80+
return true;
81+
}
82+
83+
@Override
84+
public boolean isAccountNonLocked() {
85+
return true;
86+
}
87+
88+
@Override
89+
public boolean isCredentialsNonExpired() {
90+
return true;
91+
}
92+
93+
@Override
94+
public boolean isEnabled() {
95+
return true;
96+
}
10097
}

0 commit comments

Comments
 (0)