user nules

This commit is contained in:
Filip Izydorczyk 2020-12-18 15:24:01 +01:00
parent ca440a3fd5
commit 5ef7c19ade
5 changed files with 30 additions and 22 deletions

View File

@ -35,11 +35,11 @@ spring.profiles.active=prod
Jeżeli chcemy zmienić jakieś opcję dla pordukcji to robimy to w tym sammym katalogi w pliku `application-prod.properties` i dla dev analogicznie w `application-dev.properties`.
W paczce dla proda w protpertiesach poufne dane odczytywane są ze zmiennych środowiskowych systemu na którym odpalana jest aplikacja. Ustawić trzeba następujące zmienne:
- PLANNAPLAN_MYSQL_DB_HOST - host bazy danych np `localhost`
- PLANNAPLAN_MYSQL_DB_PORT - port na którym działa baza
- PLANNAPLAN_MYSQL_DB - nazwa bazy dancyh. W profilu **dev** jest to np test
- PLANNAPLAN_MYSQL_DB_USERNAME - nazwa użytkownika bazy
- PLANNAPLAN_MYSQL_DB_PASSWORD - hasło użytkownika bazy
- `PLANNAPLAN_MYSQL_DB_HOST` - host bazy danych np `localhost`
- `PLANNAPLAN_MYSQL_DB_PORT` - port na którym działa baza
- `PLANNAPLAN_MYSQL_DB` - nazwa bazy dancyh. W profilu **dev** jest to np test
- `PLANNAPLAN_MYSQL_DB_USERNAME` - nazwa użytkownika bazy
- `PLANNAPLAN_MYSQL_DB_PASSWORD` - hasło użytkownika bazy
## Packaging

View File

@ -12,29 +12,25 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* UserRepository.getByAuthority:
* Return list of:
* SELECT * FROM User WHERE email = i.
* UserRepository.getByAuthority: Return list of: SELECT * FROM User WHERE email
* = i.
*
* Where i, ?1 are equale to variables.
* Where i, ?1 are equale to variables.
*
* UserRepository.getByToken:
* Return list of:
* SELECT * FROM User WHERE token = i.
* UserRepository.getByToken: Return list of: SELECT * FROM User WHERE token =
* i.
*
* Where i, ?1 are equale to variables.
* Where i, ?1 are equale to variables.
*
* UserRepository.searchForUsers:
* Return list of:
* SELECT * FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%).
* UserRepository.searchForUsers: Return list of: SELECT * FROM User WHERE (name
* LIKE %?1% OR surname LIKE %?1%).
*
* Where i, ?1 are equale to variables.
* Where i, ?1 are equale to variables.
*
* UserRepository.searchForUsers with role:
* Return list of:
* SELECT * FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2").
* UserRepository.searchForUsers with role: Return list of: SELECT * FROM User
* WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2").
*
* Where i, ?1 are equale to variables.
* Where i, ?1 are equale to variables.
*/
@Repository
@ -51,6 +47,9 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2")
List<User> searchForUsers(@Param("query") String query, @Param("role") UserRoles role);
@Query("FROM User WHERE role=?1")
List<User> getAllByRole(@Param("role") UserRoles role);
@Query("FROM User WHERE usosId = ?1")
Optional<User> getByUsosId(@Param("usosId") String usosId);
}

View File

@ -77,4 +77,8 @@ public class UserService {
return this.repo.findById(userId);
}
public List<User> getAllStudents() {
return this.repo.getAllByRole(UserRoles.STUDENT);
}
}

View File

@ -120,6 +120,11 @@ public class App {
newuser.setSurname("Sad");
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("iamnull@st.amu.edu.pl");
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
}
System.out.println(Logo.getStartedInfo(isDev));

View File

@ -47,7 +47,7 @@ public class UsersController {
@PreAuthorize("hasRole('ROLE_DEANERY')")
@ApiOperation(value = "Gets all students. You need token with DEANERY role to call this")
public ResponseEntity<List<UserResponse>> getAllStudents() {
final List<User> searches = this.userService.searchForStudents("");
final List<User> searches = this.userService.getAllStudents();
final List<UserResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
return new ResponseEntity<>(response, HttpStatus.OK);
}