Skip to content

Commit

Permalink
Merge pull request #28 from commonground-project/feat/add-getting-use…
Browse files Browse the repository at this point in the history
…r-profile-image

Add getting user profile image
  • Loading branch information
YukinaMochizuki authored Dec 2, 2024
2 parents 82ec7e1 + e57a669 commit 93c2e15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ public ResponseEntity<UserResponse> userSetup(@Valid @RequestBody UserSetupReque
UserResponse response = UserMapper.toResponse(userEntity);
return ResponseEntity.ok(response);
}

@GetMapping(value = "/user/profile-image/{username}", produces = "image/png")
public ResponseEntity<byte[]> getProfileImage(@Valid @NotBlank @PathVariable String username) {
return ResponseEntity.ok(userService.getProfileImage(username));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ public FullUserEntity getMe(String email) {
Optional<FullUserEntity> userEntityOptional = userRepository.findUserEntityByEmail(email);
return userEntityOptional.orElseThrow(() -> new EntityNotFoundException("User", "email", email));
}

public byte[] getProfileImage(String username) {
return userRepository.getUserEntityByUsername(username).orElseThrow(
() -> new EntityNotFoundException("User", "email", username)
).getProfileImage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface UserRepository extends CrudRepository<UserEntity, Long> {

Optional<FullUserEntity> findUserEntityByUsername(String username);

Optional<UserEntity> getUserEntityByUsername(String username);

SimpleUserEntity findByEmail(String email);

@Query("SELECT u.id FROM UserEntity u WHERE u.uuid = ?1")
Expand Down

0 comments on commit 93c2e15

Please sign in to comment.