Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class User extends JPAEntity {
@Column(name = "password")
private String password;

@Column(name = "enabled")
private Boolean enabled;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "employee_id")
private Employee employee ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public ResponseEntity<?> update (@PathVariable Integer id , @RequestBody UserDto
{
return userHandler.update(id, dto);
}
@PatchMapping("/{id}")
@Operation(summary = "update status withen true or false ")
public ResponseEntity<?> updateStatus(@PathVariable Integer id,
@RequestParam(value = "status",defaultValue = "true") Boolean status)
{
return userHandler.updateStatus(id,status);
}

@DeleteMapping("/{id}")
@Operation(summary = "delete user By Id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

Expand All @@ -25,7 +26,8 @@ public class UserDto extends GenericDto {
message ="Password must contain only letters , numbers and special characters" )
private String password;


@NotNull(message = "enabled is mandatory", groups = {InsertValidation.class, UpdateValidation.class})
private Boolean enabled;
private EmployeeDto employee ;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public ResponseEntity<?> update (Integer id , UserDto userDto)
return ResponseEntity.ok(dto);

}
public ResponseEntity<?>updateStatus(int userId, boolean status)
{
User user = userService.getById(userId)
.orElseThrow(()->new ResourceNotFoundException(User.class.getSimpleName(),userId));
user.setEnabled(status);
userService.save(user);
UserDto dto = mapper.toDto(user);
return ResponseEntity.ok(dto);
}

public ResponseEntity<?> delete (Integer id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public User save (User user)
return userRepository.save(user);
}

public User update(User user)
{
return userRepository.save(user);
}

public Optional<User> findUserName(String userName) {
return userRepository.findByUserName(userName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<changeSet id="1677488783448-1" author="HP (generated)">
<addColumn tableName="users">
<column name="enabled" type="BOOLEAN"/>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<include file="db/changelog/2023/02/07-01-changelog.xml" />
<include file="db/changelog/2023/02/20-02-changelog.xml" />
<include file="db/changelog/2023/02/20-01-changelog.xml"/>
<include file="db/changelog/2023/02/27-01-changelog.xml"/>

</databaseChangeLog>