Skip to content

Commit 3511cae

Browse files
committed
Fix problems with BL
1 parent 6e45e70 commit 3511cae

12 files changed

Lines changed: 76 additions & 44 deletions

File tree

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@
125125
<version>3.3.0</version>
126126
<executions>
127127
<!-- Turned off for Front -->
128-
<!-- <execution>-->
129-
<!-- <phase>compile</phase>-->
130-
<!-- <goals>-->
131-
<!-- <goal>check</goal>-->
132-
<!-- </goals>-->
133-
<!-- </execution>-->
128+
<!-- <execution>-->
129+
<!-- <phase>compile</phase>-->
130+
<!-- <goals>-->
131+
<!-- <goal>check</goal>-->
132+
<!-- </goals>-->
133+
<!-- </execution>-->
134134
</executions>
135135
<configuration>
136136
<configLocation>${maven.checkstyle.plugin.configLocation}</configLocation>

src/main/java/back/activitymanager/dto/activity/ActivityDto.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package back.activitymanager.dto.activity;
22

3-
import back.activitymanager.dto.user.UserWithoutRolesDto;
3+
import back.activitymanager.dto.user.UserResponseDto;
44
import java.time.LocalDateTime;
5+
import java.util.ArrayList;
56
import java.util.List;
67
import lombok.Data;
78

@@ -29,7 +30,7 @@ public class ActivityDto {
2930

3031
private LocalDateTime localDateTime;
3132

32-
private UserWithoutRolesDto author;
33+
private UserResponseDto author;
3334

34-
private List<UserWithoutRolesDto> participants;
35+
private List<UserResponseDto> participants = new ArrayList<>();
3536
}

src/main/java/back/activitymanager/dto/user/UserWithoutRolesDto.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/back/activitymanager/mapper/ActivityMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.mapstruct.Mapping;
1010
import org.mapstruct.MappingTarget;
1111

12-
@Mapper(config = MapperConfig.class)
12+
@Mapper(config = MapperConfig.class, uses = {UserMapper.class})
1313
public interface ActivityMapper {
1414

1515
@Mapping(target = "currentNumberOfPeople", ignore = true)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package back.activitymanager.mapper;
2+
3+
import back.activitymanager.service.DropboxService;
4+
import org.mapstruct.Named;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
public class DropboxHelper {
10+
11+
private final DropboxService dropboxService;
12+
13+
@Autowired
14+
public DropboxHelper(DropboxService dropboxService) {
15+
this.dropboxService = dropboxService;
16+
}
17+
18+
@Named("resolvePhotoLink")
19+
public String resolvePhotoLink(String path) {
20+
if (path == null) {
21+
return "";
22+
}
23+
24+
return dropboxService.getPhotoLink(path);
25+
}
26+
}

src/main/java/back/activitymanager/mapper/UserMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import org.mapstruct.Mapping;
1313
import org.mapstruct.MappingTarget;
1414

15-
@Mapper(config = MapperConfig.class)
15+
@Mapper(config = MapperConfig.class, uses = DropboxHelper.class)
1616
public interface UserMapper {
17+
18+
@Mapping(target = "photoPath", source = "photoPath", qualifiedByName = "resolvePhotoLink")
1719
UserResponseDto toDto(User user);
1820

1921
User toModel(UserRegistrationRequestDto userRegistrationRequestDto);

src/main/java/back/activitymanager/repository/ActivityRepository.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
public interface ActivityRepository extends JpaRepository<Activity, Long> {
1313
boolean existsByAuthor(User principal);
1414

15-
@EntityGraph
16-
@Query("SELECT a FROM Activity a WHERE a.isDeleted = false AND a.localDateTime > current_timestamp")
15+
@EntityGraph(attributePaths = {"participants", "author"})
16+
@Query("SELECT a FROM Activity a WHERE a.isDeleted = false "
17+
+ "AND a.localDateTime > current_timestamp")
1718
Optional<Activity> findById(Long id);
1819

19-
@Query("SELECT a FROM Activity a WHERE a.isDeleted = false AND a.localDateTime > current_timestamp")
20+
@EntityGraph(attributePaths = {"participants", "author"})
21+
@Query("SELECT a FROM Activity a WHERE a.isDeleted = false "
22+
+ "AND a.localDateTime > current_timestamp")
2023
Page<Activity> findByAuthorEmail(Pageable pageable, String email);
2124

22-
@Query("SELECT a FROM Activity a WHERE a.isDeleted = false AND a.localDateTime > current_timestamp")
25+
@EntityGraph(attributePaths = {"participants", "author"})
26+
@Query("SELECT a FROM Activity a WHERE a.isDeleted = false "
27+
+ "AND a.localDateTime > current_timestamp")
2328
Page<Activity> findByParticipantsEmail(Pageable pageable, String name);
2429
}

src/main/java/back/activitymanager/service/UserService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import org.springframework.security.core.Authentication;
1010

1111
public interface UserService {
12+
13+
String DEFAULT_PHOTO_PATH = "default";
14+
1215
UserResponseDto register(UserRegistrationRequestDto userRegistrationRequestDto)
1316
throws RegistrationException;
1417

src/main/java/back/activitymanager/service/impl/DropboxServiceImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import back.activitymanager.exception.DropboxProcessException;
44
import back.activitymanager.service.DropboxService;
5+
import back.activitymanager.service.UserService;
56
import com.dropbox.core.DbxException;
67
import com.dropbox.core.v2.DbxClientV2;
78
import com.dropbox.core.v2.files.GetTemporaryLinkResult;
@@ -27,14 +28,19 @@ public String uploadPhoto(MultipartFile file) {
2728

2829
try (InputStream in = file.getInputStream()) {
2930
client.files().uploadBuilder(path).uploadAndFinish(in);
30-
return path; // зберігаємо шлях (НЕ лінк!)
31+
return path;
3132
} catch (Exception e) {
3233
throw new RuntimeException("Failed to upload photo", e);
3334
}
3435
}
3536

3637
@Override
3738
public String getPhotoLink(String path) {
39+
40+
if (UserService.DEFAULT_PHOTO_PATH.equals(path)) {
41+
return "";
42+
}
43+
3844
try {
3945
GetTemporaryLinkResult result = client.files().getTemporaryLink(path);
4046
return result.getLink();

src/main/java/back/activitymanager/service/impl/UserServiceImpl.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
@Transactional
2929
@RequiredArgsConstructor
3030
public class UserServiceImpl implements UserService {
31-
private static final String DEFAULT_PHOTO_PATH = "default";
3231
private final UserRepository userRepository;
3332
private final UserMapper userMapper;
3433
private final PasswordEncoder passwordEncoder;
@@ -49,7 +48,7 @@ public UserResponseDto register(UserRegistrationRequestDto request) {
4948
@Override
5049
public UserResponseDto getMyUserInfo(Authentication authentication) {
5150
User user = (User) authentication.getPrincipal();
52-
return mapUserToDtoWithPhoto(user);
51+
return userMapper.toDto(user);
5352
}
5453

5554
@Override
@@ -63,7 +62,7 @@ public UserResponseDto updateUser(Authentication authentication,
6362
}
6463

6564
user = userRepository.save(user);
66-
return mapUserToDtoWithPhoto(user);
65+
return userMapper.toDto(user);
6766
}
6867

6968
@Override
@@ -111,17 +110,6 @@ private UserResponseDto buildAndSaveUserWithPhoto(UserRegistrationRequestDto req
111110
"Role is not found: ROLE_USER"));
112111
user.setRoles(Set.of(role));
113112

114-
return mapUserToDtoWithPhoto(userRepository.save(user));
115-
}
116-
117-
private UserResponseDto mapUserToDtoWithPhoto(User user) {
118-
UserResponseDto dto = userMapper.toDto(user);
119-
if (user.getPhotoPath() != null
120-
&& !user.getPhotoPath().equals(DEFAULT_PHOTO_PATH)) {
121-
dto.setPhotoPath(dropboxService.getPhotoLink(user.getPhotoPath()));
122-
} else {
123-
dto.setPhotoPath("");
124-
}
125-
return dto;
113+
return userMapper.toDto(userRepository.save(user));
126114
}
127115
}

0 commit comments

Comments
 (0)