feat: add func get random image
This commit is contained in:
parent
726376d0d2
commit
3fab358823
@ -1,4 +1,32 @@
|
||||
package com.example.nto.dto.mappers.employee;
|
||||
|
||||
import com.example.nto.domain.entity.Employee;
|
||||
import com.example.nto.domain.entity.Office;
|
||||
import com.example.nto.domain.entity.Position;
|
||||
import com.example.nto.domain.entity.Role;
|
||||
import com.example.nto.dto.entity.employee.EmployeeCreateDTO;
|
||||
import com.example.nto.utils.Utils;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class EmployeeCreateMapper {
|
||||
public static Employee convertFromDTO(
|
||||
EmployeeCreateDTO employeeDTO, String password, Office office,
|
||||
Position position, Role role
|
||||
) {
|
||||
Employee employee = new Employee();
|
||||
|
||||
employee.setName(employeeDTO.getName());
|
||||
employee.setSurname(employeeDTO.getSurname());
|
||||
employee.setPatronymic(employeeDTO.getPatronymic());
|
||||
employee.setTelephone(employeeDTO.getTelephone());
|
||||
employee.setEmail(employeeDTO.getEmail());
|
||||
employee.setPassword(password);
|
||||
employee.setOffice(office);
|
||||
employee.setPosition(position);
|
||||
employee.setRole(role);
|
||||
employee.setProfileImageUrl(Utils.getRandomUrlProfileImage());
|
||||
|
||||
return employee;
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,8 @@ import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
@ -52,6 +51,12 @@ public class Utils {
|
||||
return hours;
|
||||
}
|
||||
|
||||
public static String getRandomUrlProfileImage() {
|
||||
int max = 26, min = 1;
|
||||
String fileName = profileFileName(new Random().nextInt(max - min + 1) + min) + ".jpg";
|
||||
return storageConfig.getS3Endpoint() + "/" + storageConfig.getBucketName() + "/standard/" + fileName;
|
||||
}
|
||||
|
||||
public static String convertDistance(float distance) {
|
||||
if (distance > 1000) return String.format("%.1f", distance / 1000) + " км";
|
||||
else return String.format("%.1f", distance) + " м";
|
||||
|
Loading…
x
Reference in New Issue
Block a user