Skip to content

Commit

Permalink
Merge pull request #295 from 42organization/fix-user-image-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
wken5577 authored Sep 28, 2023
2 parents c3fa5ae + 3d09d66 commit ca44144
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

Expand Down Expand Up @@ -33,4 +34,8 @@ public interface UserRepository extends JpaRepository<User, Long> {
List<User> findEnemyByGameAndUser(@Param("gameId") Long gameId, @Param("userId") Long userId);

List<User> findUsersByIdIn(List<Long> userIds);

@Modifying(clearAutomatically = true)
@Query("update User u set u.imageUri = :imageUri where u.id = :id")
void updateUserImage(Long id, String imageUri);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public AsyncNewUserImageUploader(UserImageHandler userImageHandler, UserReposito
}

@Async("asyncExecutor")
@Transactional
public void upload(String intraId, String imageUrl) {
String s3ImageUrl = userImageHandler.uploadAndGetS3ImageUri(intraId, imageUrl);
if (defaultImageUrl.equals(s3ImageUrl)) {
Expand All @@ -46,7 +47,7 @@ public void upload(String intraId, String imageUrl) {
UserImage userImage = new UserImage(user, (s3ImageUrl != null) ? s3ImageUrl : defaultImageUrl,
LocalDateTime.now(), null, true);
userImageRepository.save(userImage);
user.updateImageUri(userImage.getImageUri());
userRepository.updateUserImage(user.getId(), userImage.getImageUri());
});
}

Expand Down

0 comments on commit ca44144

Please sign in to comment.