88import everTale .everTale_be .domain .easterEgg .entity .EasterEggVoice ;
99import everTale .everTale_be .domain .profile .entity .Enum .ProfileType ;
1010import everTale .everTale_be .domain .profile .entity .Profile ;
11- import everTale .everTale_be .domain .profile .repository . ProfileRepository ;
11+ import everTale .everTale_be .domain .profile .service . ProfileService ;
1212import everTale .everTale_be .domain .profile .util .ProfileHelper ;
1313import everTale .everTale_be .domain .story .dto .SceneResponseDTO ;
1414import everTale .everTale_be .domain .story .dto .StoryCollectionResponseDto ;
2121import everTale .everTale_be .global .apiPayload .code .status .ErrorStatus ;
2222import everTale .everTale_be .global .apiPayload .exception .handler .NotFoundHandler ;
2323import everTale .everTale_be .domain .story .external .StoryApiClient ;
24- import everTale .everTale_be .global .apiPayload .exception .handler .UnAuthorizedHandler ;
2524import everTale .everTale_be .global .s3 .S3Manager ;
2625import org .springframework .data .domain .Page ;
2726import org .springframework .data .domain .Pageable ;
@@ -44,7 +43,7 @@ public class StoryService {
4443 private final StoryRepository storyRepository ;
4544 private final StoryCharacterRepository storyCharacterRepository ;
4645 private final PersonalityRepository personalityRepository ;
47- private final ProfileRepository profileRepository ;
46+ private final ProfileService profileService ;
4847 private final StoryApiClient storyApiClient ;
4948 private final ProfileHelper profileHelper ;
5049 private final S3Manager s3Manager ;
@@ -342,14 +341,9 @@ public StoryCollectionResponseDto getStories(Long profileId, Pageable pageable)
342341 Profile profile = profileHelper .getAuthenticatedProfile ();
343342
344343 if (profile .getProfileType ()== ProfileType .CHILD ) {
345- if (!profile .getId ().equals (profileId )) {
346- throw new UnAuthorizedHandler (ErrorStatus .UNAUTHORIZED_PROFILE_ACCESS );
347- }
344+ profileService .validateChildProfileAccess (profile , profileId );
348345 } else {
349- boolean isMyChild = profileRepository .existsByUserIdAndId (profile .getId (), profileId );
350- if (!isMyChild ) {
351- throw new UnAuthorizedHandler (ErrorStatus .UNAUTHORIZED_PROFILE_ACCESS );
352- }
346+ profileService .validateParentProfileAccess (profile , profileId );
353347 }
354348
355349 Page <Story > stories = storyRepository .findByProfileId (profileId , pageable );
0 commit comments