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 24, 2023
1 parent 53ab93e commit 1459ae6
Show file tree
Hide file tree
Showing 20 changed files with 9 additions and 126 deletions.
8 changes: 0 additions & 8 deletions src/main/java/manon/api/user/UserWS.java
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
16 changes: 2 additions & 14 deletions src/main/java/manon/document/user/UserEntity.java
Expand Up @@ -28,7 +28,6 @@
import lombok.ToString;
import manon.model.user.RegistrationState;
import manon.util.Tools;
import org.springframework.data.annotation.Version;

import java.io.Serializable;
import java.time.LocalDateTime;
Expand All @@ -55,7 +54,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 @@ -102,27 +101,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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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();
}
}
5 changes: 0 additions & 5 deletions src/test/java/manon/util/mapper/UserMapperDataset.java
Expand Up @@ -26,9 +26,7 @@ public static UserEntity toUserEntity(int id, UserSnapshotEntity... userSnapshot
.registrationState(RegistrationState.ACTIVE)
.nickname("nickname" + id)
.email("u" + id + "@localhost.net")
.version(1)
.creationDate(now)
.updateDate(now)
.userSnapshots(Arrays.asList(userSnapshotEntityList))
.build();
}
Expand All @@ -42,7 +40,6 @@ public static UserSnapshotEntity toUserSnapshotEntity(UserEntity user) {
.userRegistrationState(user.getRegistrationState())
.userNickname(user.getNickname())
.userEmail(user.getEmail())
.userVersion(1)
.creationDate(now)
.build();
}
Expand All @@ -60,7 +57,6 @@ public static UserDto toUserDto(UserEntity user) {
userDto.setNickname(user.getNickname());
userDto.setEmail(user.getEmail());
userDto.setCreationDate(user.getCreationDate());
userDto.setUpdateDate(user.getUpdateDate());
return userDto;
}

Expand All @@ -86,7 +82,6 @@ public static UserWithSnapshotsDto toUserWithSnapshotsDto(UserDto user, UserSnap
userWithSnapshotsDto.setNickname(user.getNickname());
userWithSnapshotsDto.setEmail(user.getEmail());
userWithSnapshotsDto.setCreationDate(user.getCreationDate());
userWithSnapshotsDto.setUpdateDate(user.getUpdateDate());
userWithSnapshotsDto.setUserSnapshots(Arrays.asList(userSnapshots));
return userWithSnapshotsDto;
}
Expand Down

0 comments on commit 1459ae6

Please sign in to comment.