Skip to content

Commit

Permalink
Resolved problem with @requiredargsconstructor annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Slawek84PL committed Oct 14, 2024
1 parent fde0181 commit 30a891a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/main/java/pl/ateam/disasteralerts/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
36 changes: 19 additions & 17 deletions src/main/java/pl/ateam/disasteralerts/user/UserService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pl.ateam.disasteralerts.user;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
Expand All @@ -9,65 +8,68 @@
import java.util.UUID;

@Service
@RequiredArgsConstructor
public class UserService {

private final UserRepository repository;
private final UserRepository userRepository;

public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}

boolean existsById(UUID userId) {
return repository.existsById(userId);
return userRepository.existsById(userId);
}

boolean existsByUsername(String username) {
return repository.existsByUsername(username);
return userRepository.existsByUsername(username);
}

boolean existsByEmail(String email) {
return repository.existsByEmail(email);
return userRepository.existsByEmail(email);
}

Optional<User> findById(UUID id) {
return repository.findById(id);
return userRepository.findById(id);
}

Optional<User> findByUsername(String username) {
return repository.findByUsername(username);
return userRepository.findByUsername(username);
}

Optional<User> findByEmail(String email) {
return repository.findByEmail(email);
return userRepository.findByEmail(email);
}

List<User> getAllUsers() {
return repository.findAll();
return userRepository.findAll();
}

public void save(User user) {
repository.save(user);
userRepository.save(user);
}

public void saveAll(Collection<User> users) {
repository.saveAll(users);
userRepository.saveAll(users);
}

public void delete(User user) {
repository.delete(user);
userRepository.delete(user);
}

public void deleteById(UUID id) {
repository.deleteById(id);
userRepository.deleteById(id);
}

public void deleteAll() {
repository.deleteAll();
userRepository.deleteAll();
}

public void deleteAll(Collection<User> users) {
repository.deleteAll(users);
userRepository.deleteAll(users);
}

public long userCount() {
return repository.count();
return userRepository.count();
}

}

0 comments on commit 30a891a

Please sign in to comment.