Skip to content

Commit

Permalink
remove useless stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlermitage committed Nov 25, 2023
1 parent 53ab93e commit 3271d31
Show file tree
Hide file tree
Showing 21 changed files with 15 additions and 126 deletions.
8 changes: 0 additions & 8 deletions src/main/java/manon/api/user/UserWS.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ public UserWithSnapshotsDto readAndIncludeUserSnapshots(@AuthenticationPrincipal
return userService.readOneAndFetchUserSnapshotDtos(user.getUserId());
}

/** Get user's version. */
@Operation(summary = "Get my user version number.")
@GetMapping("/version")
public long readVersion(@AuthenticationPrincipal UserSimpleDetails user) {
log.debug("user {} reads his version", user.getIdentity());
return userService.readVersionById(user.getUserId()).getVersion();
}

/** Update one user's user field. */
@Operation(summary = "Update my user data.")
@PutMapping(value = "/field", consumes = JSON)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/manon/document/user/FriendshipEventEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import lombok.ToString;
import manon.model.user.FriendshipEventCode;
import manon.util.Tools;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.io.Serializable;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -53,6 +55,7 @@ public class FriendshipEventEntity implements Serializable {

@Column(nullable = false)
@Enumerated(EnumType.STRING)
@JdbcTypeCode(SqlTypes.VARCHAR)
private FriendshipEventCode code;

@JsonSerialize(using = LocalDateTimeSerializer.class)
Expand Down
19 changes: 5 additions & 14 deletions src/main/java/manon/document/user/UserEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import lombok.ToString;
import manon.model.user.RegistrationState;
import manon.util.Tools;
import org.springframework.data.annotation.Version;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.io.Serializable;
import java.time.LocalDateTime;
Expand All @@ -55,7 +56,7 @@
@QueryEntity
@Getter
@ToString(exclude = "userSnapshots")
@EqualsAndHashCode(exclude = {"id", "userSnapshots", "version", "creationDate", "updateDate"})
@EqualsAndHashCode(exclude = {"id", "userSnapshots", "creationDate"})
@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
Expand Down Expand Up @@ -86,6 +87,7 @@ public class UserEntity implements Serializable {

@Column(nullable = false)
@Enumerated(EnumType.STRING)
@JdbcTypeCode(SqlTypes.VARCHAR)
private RegistrationState registrationState;

/** A non-unique name that can change, NOT mandatory. */
Expand All @@ -102,27 +104,16 @@ public class UserEntity implements Serializable {
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
private List<UserSnapshotEntity> userSnapshots;

@Version
@Column(nullable = false)
private long version;

@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@Column(nullable = false)
private LocalDateTime creationDate;

@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@Column(nullable = false)
private LocalDateTime updateDate;

@PrePersist
public void prePersist() {
LocalDateTime now = Tools.now();
if (creationDate == null) {
creationDate = now;
creationDate = Tools.now();
}
updateDate = now;
}

/** {@link UserEntity} fields validation rules. */
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/manon/document/user/UserSnapshotEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public class UserSnapshotEntity implements Serializable {
@Column(updatable = false)
private String userEmail;

@Column(updatable = false)
private long userVersion;

@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@Column(nullable = false)
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/manon/document/user/UserVersionProjection.java

This file was deleted.

5 changes: 1 addition & 4 deletions src/main/java/manon/dto/user/AbstractUserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* declare any field because everything comes from the ancestor: this is not perfect, but it works.
*/
@Data
@EqualsAndHashCode(exclude = {"id", "creationDate", "updateDate"})
@EqualsAndHashCode(exclude = {"id", "creationDate"})
public abstract class AbstractUserDto {

private long id;
Expand All @@ -41,7 +41,4 @@ public abstract class AbstractUserDto {

@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime creationDate;

@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime updateDate;
}
1 change: 0 additions & 1 deletion src/main/java/manon/mapper/user/UserMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public abstract class UserMapper {
@Mapping(source = "registrationState", target = "userRegistrationState")
@Mapping(source = "nickname", target = "userNickname")
@Mapping(source = "email", target = "userEmail")
@Mapping(source = "version", target = "userVersion")
@Mapping(source = "from", target = "user")
public abstract UserSnapshotEntity toUserSnapshotEntity(UserEntity from);

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/manon/repository/user/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import manon.document.user.UserEntity;
import manon.document.user.UserIdProjection;
import manon.document.user.UserVersionProjection;
import manon.model.user.RegistrationState;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
Expand All @@ -18,9 +17,6 @@ public interface UserRepository extends JpaRepository<UserEntity, Long>, Queryds

Optional<UserEntity> findByUsername(String username);

@Query("select u from User u where u.id = :id")
Optional<UserVersionProjection> findVersionById(@Param("id") long id);

@Query("select u from User u where u.username = :username")
Optional<UserIdProjection> findVersionByUsername(@Param("username") String username);

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/manon/service/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.querydsl.core.types.Predicate;
import manon.document.user.UserEntity;
import manon.document.user.UserIdProjection;
import manon.document.user.UserVersionProjection;
import manon.dto.user.UserWithSnapshotsDto;
import manon.err.user.PasswordNotMatchException;
import manon.model.user.RegistrationState;
Expand All @@ -24,8 +23,6 @@ public interface UserService {

Optional<UserEntity> findByUsername(String username);

UserVersionProjection readVersionById(long id);

/**
* Update a user's data.
* @param userId user id.
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/manon/service/user/impl/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import manon.document.user.QUserEntity;
import manon.document.user.UserEntity;
import manon.document.user.UserIdProjection;
import manon.document.user.UserVersionProjection;
import manon.dto.user.UserWithSnapshotsDto;
import manon.err.user.PasswordNotMatchException;
import manon.err.user.UserExistsException;
Expand Down Expand Up @@ -65,11 +64,6 @@ public UserEntity readByUsername(String username) {
return userRepository.findByUsername(username).orElseThrow(UserNotFoundException::new);
}

@Override
public UserVersionProjection readVersionById(long id) {
return userRepository.findVersionById(id).orElseThrow(UserNotFoundException::new);
}

@Override
public UserEntity create(UserEntity user) {
if (userRepository.existsByUsername(user.getUsername())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ create table user_
nickname varchar(24),
password varchar(256) not null,
registration_state varchar(255) not null,
update_date timestamp not null,
username varchar(24) not null,
version bigint not null,
primary key (id)
);
create table user_snapshot
Expand All @@ -64,7 +62,6 @@ create table user_snapshot
user_password varchar(255),
user_registration_state integer,
user_username varchar(255),
user_version bigint,
user_id bigint,
primary key (id)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ create table user_
nickname varchar(24) null,
password varchar(256) not null,
registration_state varchar(255) not null,
update_date datetime(6) not null,
username varchar(24) not null,
version bigint not null,
constraint uk__user__username
unique (username)
);
Expand Down Expand Up @@ -72,7 +70,6 @@ create table user_snapshot
user_password varchar(255) null,
user_registration_state int null,
user_username varchar(255) null,
user_version bigint null,
user_id bigint null,
constraint fk__user_snapshot__user_id
foreign key (user_id) references user_ (id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ create table user_
nickname varchar(24),
password varchar(256) not null,
registration_state varchar(255) not null,
update_date timestamp not null,
username varchar(24) not null
constraint uk_wqsqlvajcne4rlyosglqglhk
unique,
version bigint not null
unique
);

create table friendship
Expand Down
10 changes: 0 additions & 10 deletions src/test/java/manon/api/user/UserWSCtrlIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ void shouldVerifyReadAndIncludeUserSnapshots(Rs rs, Integer status) {
verify(userWs, status).readAndIncludeUserSnapshots(any());
}

@ParameterizedTest
@MethodSource(DP_ALLOW_AUTHENTICATED)
void shouldVerifyReadVersion(Rs rs, Integer status) {
rs.getSpec()
.get(API_USER + "/version")
.then()
.statusCode(status);
verify(userWs, status).readVersion(any());
}

@ParameterizedTest
@MethodSource(DP_ALLOW_AUTHENTICATED)
void shouldVerifyUpdateField(Rs rs, Integer status) {
Expand Down
13 changes: 0 additions & 13 deletions src/test/java/manon/api/user/UserWSIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void shouldRegister(String name, String pwd) {
UserEntity user = userService.readByUsername(name);
assertThat(user.getUsername()).isEqualTo(name);
assertThat(user.getAuthorities()).isEqualTo(PLAYER.getAuthority());
assertThat(user.getVersion()).isGreaterThanOrEqualTo(0L);
assertThat(user.getRegistrationState()).isEqualTo(ACTIVE);
assertThat(pwd).as("don't store raw passwords!")
.isNotEqualTo(user.getPassword())
Expand Down Expand Up @@ -145,17 +144,6 @@ void shouldReadAndIncludeUserSnapshotsWhenUserHasSnapshots() {
assertThat(webUser.getUserSnapshots()).hasSize(2).isEqualTo(dbUser.getUserSnapshots());
}

@Test
void shouldReadVersion() {
Response res = whenP1().getSpec()
.get(API_USER + "/version");
res.then()
.statusCode(SC_OK);
Long webUserVersion = readValue(res, Long.class);
Long dbUserVersion = userService.readOne(userId(1)).getVersion();
assertThat(webUserVersion).isEqualTo(dbUserVersion);
}

Object[][] dataProviderShouldUpdate() {
return new Object[][]{
{"", ""},
Expand All @@ -177,7 +165,6 @@ void shouldUpdate(String nickname, String email) {
UserEntity userExpected = userBefore.toBuilder()
.email(email)
.nickname(nickname)
.version(userBefore.getVersion() + 1)
.build();
assertThat(userAfter).isEqualTo(userExpected);
}
Expand Down
24 changes: 2 additions & 22 deletions src/test/java/manon/document/user/UserEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,13 @@ void shouldVerifyToString() {
Assertions.assertThat(UserEntity.builder().build().toString()).contains(
"id", "username",
"authorities", "password", "registrationState",
"nickname", "email",
"version", "creationDate", "updateDate");
}

@Test
void shouldVerifyPrePersistOnNew() {
UserEntity o = UserEntity.builder().build();
o.prePersist();
Assertions.assertThat(o.getCreationDate()).isNotNull();
Assertions.assertThat(o.getUpdateDate()).isEqualTo(o.getCreationDate());
}

@Test
void shouldVerifyPrePersistOnExisting() {
UserEntity o = UserEntity.builder().build();
o.prePersist();
LocalDateTime creationDate = o.getCreationDate();

o.prePersist();
Assertions.assertThat(o.getCreationDate()).isEqualTo(creationDate);
Assertions.assertThat(o.getUpdateDate()).isAfterOrEqualTo(creationDate);
"nickname", "email", "creationDate");
}

@Test
void shouldVerifyEqualsContract() {
EqualsVerifier.forClass(UserEntity.class)
.withIgnoredFields("id", "userSnapshots", "version", "creationDate", "updateDate")
.withIgnoredFields("id", "userSnapshots", "creationDate")
.withPrefabValues(UserEntity.class,
UserEntity.builder().nickname("n1").build(),
UserEntity.builder().nickname("n2").build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ void shouldVerifyToString() {
Assertions.assertThat(UserSnapshotEntity.builder().build().toString()).contains(
"id", "userUsername",
"userAuthorities", "userPassword", "userRegistrationState",
"userNickname", "userEmail",
"userVersion", "creationDate");
"userNickname", "userEmail", "creationDate");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/manon/dto/user/UserDtoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UserDtoTest {
@Test
void shouldVerifyEqualsContract() {
EqualsVerifier.simple().forClass(UserDto.class)
.withIgnoredFields("id", "creationDate", "updateDate")
.withIgnoredFields("id", "creationDate")
.verify();
}
}
2 changes: 1 addition & 1 deletion src/test/java/manon/dto/user/UserWithSnapshotsDtoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UserWithSnapshotsDtoTest {
@Test
void shouldVerifyEqualsContract() {
EqualsVerifier.simple().forClass(UserWithSnapshotsDto.class)
.withIgnoredFields("id", "creationDate", "updateDate")
.withIgnoredFields("id", "creationDate")
.verify();
}
}
13 changes: 0 additions & 13 deletions src/test/java/manon/service/user/impl/UserServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ void shouldFailReadByUsernameUnknown() {
.isInstanceOf(UserNotFoundException.class);
}

@Test
void shouldReadVersionById() {
Assertions.assertThat(userService.readVersionById(userId(2)).getVersion()).isGreaterThanOrEqualTo(0L);
}

@Test
void shouldFailReadVersionByIdUnknown() {
Assertions.assertThatThrownBy(() -> userService.readVersionById(UNKNOWN_ID))
.isInstanceOf(UserNotFoundException.class);
}

@Test
void shouldReadIdByUsername() {
Assertions.assertThat(userService.readIdByUsername(name(1)).getId()).isEqualTo(userId(1));
Expand Down Expand Up @@ -262,7 +251,5 @@ void shouldSave(String validUsername) {

UserEntity user = userService.readByUsername(validUsername);
Assertions.assertThat(user.getCreationDate()).isBetween(before, after);
Assertions.assertThat(user.getUpdateDate()).isBetween(before, after);
Assertions.assertThat(user.getVersion()).isNotNegative();
}
}
Loading

0 comments on commit 3271d31

Please sign in to comment.