Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix [#169] 타임테이블 조회 쿼리에 @Param 어노테이션 추가 #170

Merged
merged 6 commits into from
Jan 23, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.sopt.confeti.global.common.BaseResponse;
import org.sopt.confeti.global.message.SuccessMessage;
import org.sopt.confeti.global.util.ApiResponseUtil;
import org.sopt.confeti.global.util.S3FileHandler;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -19,11 +20,11 @@
public class UserInfoController {

private final UserInfoFacade userInfoFacade;
private final S3FileHandler s3FileHandler;

@GetMapping
public ResponseEntity<BaseResponse<?>> getUserInfo(@RequestHeader("Authorization") Long userId) {
public ResponseEntity<BaseResponse<?>> getUserInfo(@RequestHeader("Authorization") long userId) {
UserInfoDTO userInfo = userInfoFacade.getUserInfo(userId);
UserInfoResponse user = UserInfoResponse.from(userInfo);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, user);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, UserInfoResponse.of(userInfo, s3FileHandler));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ResponseEntity<BaseResponse<?>> removeTimetableFestival(
@GetMapping("/{festivalDateId}")
public ResponseEntity<BaseResponse<?>> getTimetableFestival(
@RequestHeader("Authorization") long userId,
@PathVariable(name = "festivalDateId") @Min(value=0, message="요청 형식이 올바르지 않습니다.") long festivalDateId
@PathVariable(name = "festivalDateId") @Min(value = 0, message = "요청 형식이 올바르지 않습니다.") long festivalDateId
){
UserTimetableFestivalBasicDTO response = userTimetableFacade.getTimetableInfo(userId, festivalDateId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, UserTimetableFestivalResponse.from(response));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.sopt.confeti.api.user.dto.response;

import org.sopt.confeti.api.user.facade.dto.response.UserInfoDTO;
import org.sopt.confeti.global.util.S3FileHandler;

public record UserInfoResponse (
Long userId,
String profileUrl,
String username
) {
public static UserInfoResponse from (UserInfoDTO userInfoDTO) {
return new UserInfoResponse(userInfoDTO.userId(), userInfoDTO.profileUrl(), userInfoDTO.username());
public static UserInfoResponse of(final UserInfoDTO userInfoDTO, final S3FileHandler s3FileHandler) {
return new UserInfoResponse(
userInfoDTO.userId(),
s3FileHandler.getFileUrl(userInfoDTO.profilePath()),
userInfoDTO.username()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class UserInfoFacade {

@Transactional
public UserInfoDTO getUserInfo(Long userId) {
User user = userService.findById(userId);
return UserInfoDTO.from(user);
return UserInfoDTO.from(
userService.findById(userId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public UserTimetableFestivalBasicDTO getTimetableInfo(final long userId, final l
List<UserTimetable> userTimetables = userTimetableService.getUserTimetables(userId, festivalTimeIds);

Map<Long, UserTimetable> userTimetableMapper = userTimetables.stream()
.collect(Collectors.toMap(UserTimetable::getId, Function.identity()));
.collect(Collectors.toMap(userTimetable ->
userTimetable.getFestivalTime().getId(), Function.identity())
);

return UserTimetableFestivalBasicDTO.of(festivalDate, userTimetableMapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

import org.sopt.confeti.domain.user.User;

public record UserInfoDTO (Long userId, String profileUrl, String username){
public static UserInfoDTO from (User user) {
return new UserInfoDTO(user.getId(), user.getProfilePath(), user.getUsername());
public record UserInfoDTO (
long userId,
String profilePath,
String username
){
public static UserInfoDTO from (final User user) {
return new UserInfoDTO(
user.getId(),
user.getProfilePath(),
user.getUsername()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ public interface UserTimetableRepository extends JpaRepository<UserTimetable, Lo
" WHERE tf.user.id = :userId" +
" AND ut.festivalTime.id IN :festivalTimeIds"
)
List<UserTimetable> findByUserIdAndFestivalTimeIds(final long userId, final List<Long> festivalTimeIds);
List<UserTimetable> findByUserIdAndFestivalTimeIds(
final @Param("userId") long userId,
final @Param("festivalTimeIds") List<Long> festivalTimeIds
);
}