Skip to content

Commit

Permalink
Merge branch 'main' into add-log
Browse files Browse the repository at this point in the history
  • Loading branch information
picksitquick authored Feb 26, 2024
2 parents ba4f153 + d239fcc commit 7c0148c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public List<RoleDTO> getAllRolesBySkillName(String name) {

public List<RoleDTO> getRolesByUserEmail(String email){

return rolesRepository.findByUsers_Email(email).stream().map(
return rolesRepository.findByUsers_EmailId(email).stream().map(
roles -> getRolesMapper().roleToRoleDto(roles)
).collect(Collectors.toList()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public List<SkillsDTO> getAllSkillsByRolesName(String name) {
}

public List<SkillsDTO> getSkillsByEmail(String email) {
return skillsRepository.findByUsers_Email(email).stream()
return skillsRepository.findByUsers_EmailId(email).stream()
.map(skills -> getSkillsMapper().skillsToSkillsDTO(skills))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public UserDTO createUsers(UserDTO userDto) {

public UserDTO updateUsers(String emailId, UserDTO userDto) {

Users usersRes = usersRepository.findByEmail(emailId);
Users usersRes = usersRepository.findByEmailId(emailId);
if (usersRes.getEmail() == null) {
return null;
}
Expand All @@ -93,7 +93,7 @@ public UserDTO updateUsers(String emailId, UserDTO userDto) {

public void deleteUsers(String emailId) {
userOperationsHelper.deleteUser(emailId);
getUsersRepository().deleteByEmailId(emailId);
getUsersRepository().deleteById(emailId);
}

public void deleteAllUsers() {
Expand All @@ -106,14 +106,14 @@ public List<UserDTO> getAllUsers(String email) {

List<UserDTO> usersDto = new ArrayList<>();
if (email == null) usersRepository.findAll().forEach(user -> usersDto.add(getUserMapper().usersToUserDTO(user)));
else usersRepository.findByEmailContaining(email).forEach(user -> usersDto.add(getUserMapper().usersToUserDTO(user)));
else usersRepository.findListByEmailId(email).forEach(user -> usersDto.add(getUserMapper().usersToUserDTO(user)));
if (usersDto.isEmpty()) {
return null;
}
return usersDto;
}
public UserDTO getUserByEmail(String email){
return getUserMapper().usersToUserDTO(getUsersRepository().findByEmail(email));
return getUserMapper().usersToUserDTO(getUsersRepository().findByEmailId(email));
}

public List<UserDTO> getUsersByLastName(String lastName){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public interface RolesRepository extends JpaRepository<Roles, Long> {

List<Roles> findBySkills_Name(String name);

List<Roles> findByUsers_Email(String email);
List<Roles> findByUsers_EmailId(String emailId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public interface SkillsRepository extends JpaRepository<Skills, Long> {

List<Skills> findByUsers_FirstName(String name);

List<Skills> findByUsers_Email(String email);
List<Skills> findByUsers_EmailId(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@
import com.gamedoora.model.dao.Users;

@Repository
public interface UsersRepository extends JpaRepository<Users, Long> {
public interface UsersRepository extends JpaRepository<Users, String> {
Users findByEmailId(String emailId);

List<Users> findByEmailContaining(String emailId);
List<Users> findByRole_Id(long id);

Users findByEmail(String email);
List<Users> findBySkills_Id(long id);

List<Users> findBySkills_Id(String emailId);
List<Users> findByFirstName(String firstName);

List<Users> findByRole_Id(String emailId);
List<Users> findByLastName(String lastName);

List <Users> findByFirstName(String firstName);
List <Users> findByLastName(String lastName);
List<Users> findBySkills_Name(String name);

List<Users> findByRole_Name(String name);
List<Users> findByRole_Name(String name);

List<Users> findByStudiosSet_EmailId(String emailId);

void deleteByEmailId(String emailId);
List<Users> findListByEmailId(String emailId);
}
Original file line number Diff line number Diff line change
@@ -1,73 +1,90 @@
//package com.gamedoora.backend.userservices.repository;
//
//import com.gamedoora.model.dao.Users;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
//
//import java.util.List;
//import java.util.Optional;
//
//import static org.junit.jupiter.api.Assertions.assertEquals;
//import static org.junit.jupiter.api.Assertions.assertNotNull;
//
//@DataJpaTest(properties = {"spring.cloud.config.enabled=false"})
//class UsersRepositoryTest {
//
// @Autowired
// private UsersRepository usersRepository;
//
// private Users users = new Users();
//
// @BeforeEach
// void setup(){
//
// users = Users.builder()
// .id(1L)
// .firstName("Test")
// .lastName("doe")
// .email("test@gmail.com")
// .providerToken("")//required fields while building objects
// .build();
// }
//
//
// @Test
// public void sampleTest(){
//
// usersRepository.save(users);
//
// Optional<Users> dummy = usersRepository.findById(1L);
// List<Users> test = usersRepository.findByFirstName("ok");
//
// List<Users> sample = usersRepository.findBySkills_Name("sample");
//
// assertNotNull(sample);
// assertNotNull(dummy);
// assertNotNull(test);
// }
//
// @Test
// void findByName() {
// usersRepository.save(users);
// List<Users> userValue = usersRepository.findByFirstName(users.getFirstName());
// assertNotNull(userValue);
// assertEquals(userValue.get(0).getFirstName() , "Test");
// }
// @Test
// void findByEmail() {
// usersRepository.save(users);
// Users userValue = usersRepository.findByEmail(users.getEmail());
// assertNotNull(userValue);
// assertEquals(userValue.getEmail() , "test@gmail.com");
// }
//
// @Test
// void findByLastName() {
// usersRepository.save(users);
// List<Users> userValue = usersRepository.findByLastName(users.getLastName());
// assertNotNull(userValue);
// assertEquals(userValue.get(0).getLastName() , "doe");
// }
//}
package com.gamedoora.backend.userservices.repository;

import com.gamedoora.model.dao.Users;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@DataJpaTest(properties = {"spring.cloud.config.enabled=false"})
class UsersRepositoryTest {

@Autowired
private UsersRepository usersRepository;

private Users users = new Users();

private Users testUsers = new Users();

@BeforeEach
void setup(){

users = Users.builder()
.emailId("test@gamedoora.com")
.firstName("Test")
.lastName("doe")
.providerToken("")//required fields while building objects
.build();

testUsers = Users.builder()
.emailId("test1@gamedoora.com")
.firstName("Test2")
.lastName("joe")
.providerToken("")//required fields while building objects
.build();
}


@Test
public void sampleTest(){

usersRepository.save(users);

Optional<Users> dummy = usersRepository.findById("test@gamedoora.com");
List<Users> test = usersRepository.findByFirstName("ok");

List<Users> sample = usersRepository.findBySkills_Name("sample");

assertNotNull(sample);
assertNotNull(dummy);
assertNotNull(test);
}

@Test
void findByName() {
usersRepository.save(users);
List<Users> userValue = usersRepository.findByFirstName(users.getFirstName());
assertNotNull(userValue);
assertEquals(userValue.get(0).getFirstName() , "Test");
}
@Test
void findByEmail() {
usersRepository.save(users);
Users userValue = usersRepository.findByEmailId(users.getEmail());
assertNotNull(userValue);
assertEquals(userValue.getEmail() , "test@gamedoora.com");
}

@Test
void findByLastName() {
usersRepository.save(users);
List<Users> userValue = usersRepository.findByLastName(users.getLastName());
assertNotNull(userValue);
assertEquals(userValue.get(0).getLastName() , "doe");
}

@Test
void findListOfUsers(){
usersRepository.save(users);
usersRepository.save(testUsers);
List<Users> userList = usersRepository.findListByEmailId("test1@gamedoora.com");
assertNotNull(userList);
assertEquals(userList.size() , 1);
}
}

0 comments on commit 7c0148c

Please sign in to comment.