Skip to content

Commit

Permalink
Merge pull request #59 from AlongTheBlue/alongBlue
Browse files Browse the repository at this point in the history
feat: 여행따라 조회 및 작성 수정
  • Loading branch information
yeilkk authored Oct 14, 2024
2 parents 1267cfe + c720ae5 commit d02fccb
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.alongtheblue.alongtheblue_server.domain.userInfo.application.UserInfoService;
import org.alongtheblue.alongtheblue_server.domain.userInfo.domain.UserInfo;
import org.alongtheblue.alongtheblue_server.domain.userInfo.dto.CreateUserInfoDto;
import org.alongtheblue.alongtheblue_server.domain.userInfo.dto.UserInfoDto;
import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse;
import org.springframework.web.bind.annotation.*;

Expand All @@ -33,8 +34,9 @@ public ApiResponse<List<UserInfo>> retrieveAllUserInfo() {

@Operation(summary = "ID로 UserInfo 조회 API")
@GetMapping("/user")
public ApiResponse<UserInfo> retrieveUserInfo(@RequestHeader("Authorization") String uid) {
return userInfoService.retrieveUserInfo(uid);
public ApiResponse<UserInfoDto> retrieveUserInfo(@RequestHeader("Authorization") String uid) {
return userInfoService.retrieveUserInfoDto(uid);
// return userInfoService.retrieveUserInfo(uid);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.alongtheblue.alongtheblue_server.domain.userInfo.dao.UserInfoRepository;
import org.alongtheblue.alongtheblue_server.domain.userInfo.domain.UserInfo;
import org.alongtheblue.alongtheblue_server.domain.userInfo.dto.CreateUserInfoServiceDto;
import org.alongtheblue.alongtheblue_server.domain.userInfo.dto.UserInfoDto;
import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse;
import org.alongtheblue.alongtheblue_server.global.error.ErrorCode;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -74,4 +75,13 @@ public ApiResponse<UserInfo> retrieveUserInfo(String uid) {
return ApiResponse.ok("사용자 정보를 성공적으로 조회했습니다.", userInfo);
}

public ApiResponse<UserInfoDto> retrieveUserInfoDto(String uid) {
UserInfo userInfo = retrieveUserInfo(uid).getData();
UserInfoDto userInfoDto = new UserInfoDto(
userInfo.getUid(),
userInfo.getUserName(),
userInfo.getProfileImageUrl()
);
return ApiResponse.ok("사용자 정보를 성공적으로 조회했습니다.", userInfoDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.alongtheblue.alongtheblue_server.domain.userInfo.dto;

public record UserInfoDto(
String uid,
String userName,
// String userComment,
String profileImg
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public UserTourCourse createTourCourse(

@Operation(summary = "여행따라 전체 게시물 조회 API")
@GetMapping("/list")
public List<UserTourCourseDTO> getAllUserTourCourses(){
public ApiResponse<List<UserTourCourseDTO>> getAllUserTourCourses(){
return tourCommunityService.getAllUserTourCourses();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.alongtheblue.alongtheblue_server.domain.userInfo.application.UserInfoService;
import org.alongtheblue.alongtheblue_server.domain.userInfo.domain.UserInfo;
import org.alongtheblue.alongtheblue_server.domain.userInfo.dto.UserInfoDto;
import org.alongtheblue.alongtheblue_server.global.adapter.S3Adapter;
import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse;
import org.alongtheblue.alongtheblue_server.global.data.tourcommunity.dto.request.CreateUserTourCourseServiceRequestDto;
Expand Down Expand Up @@ -120,22 +121,31 @@ private String saveImageToS3(MultipartFile image) {
}

// 여행따라 전체 조회 - 페이지네이션 필요
public List<UserTourCourseDTO> getAllUserTourCourses() {
public ApiResponse<List<UserTourCourseDTO>> getAllUserTourCourses() {
List<UserTourCourse> userCourses = userTourCourseRepository.findAll();
List<UserTourCourseDTO> userCourseDtoList = new ArrayList<>();
for (UserTourCourse userCourse : userCourses) {
UserInfo userInfo = userCourse.getUserInfo();
UserInfoDto userInfoDto = new UserInfoDto(
userInfo.getUid(),
userInfo.getUserName(),
userInfo.getProfileImageUrl()
);
UserTourCourseDTO userCourseDto = new UserTourCourseDTO();
userCourseDto.setUser(userInfoDto);
userCourseDto.setTitle(userCourse.getTitle());
userCourseDto.setWriting(userCourse.getWriting());
userCourseDto.setContent(userCourse.getWriting());
userCourseDto.setId(userCourse.getId());
// dto.setTags(tourPostHashTagRepository.findBytourCourseForHashTag(tour));

List<TourPostItem> items = tourPostItemRepository.findByuserTourCourse(userCourse);
List<TourPostItem> items = tourPostItemRepository.findByUserTourCourse(userCourse);
List<TourImage> images = tourImageRepository.findBytourPostItem(items.get(0));
if (!images.isEmpty()) userCourseDto.setImgUrl(images.get(0).getUrl());
if (!images.isEmpty())
userCourseDto.setImgUrl(images.get(0).getUrl());
// userCourseDto.setImgUrl(tourImageRepository.findBytourPostItem(items.get(0)).get(0).getUrl());
userCourseDtoList.add(userCourseDto);
}
return userCourseDtoList;
return ApiResponse.ok(userCourseDtoList);
}

public UserTourCourse findById(Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import java.util.List;

public interface TourPostItemRepository extends JpaRepository<TourPostItem, Long> {
List<TourPostItem> findByuserTourCourse (UserTourCourse userTourCourse);
List<TourPostItem> findByUserTourCourse(UserTourCourse userCourse);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import lombok.Getter;
import lombok.Setter;
import org.alongtheblue.alongtheblue_server.domain.userInfo.dto.UserInfoDto;
import org.alongtheblue.alongtheblue_server.global.data.course.Course;

import java.util.List;
@Getter
@Setter
public class UserTourCourseDTO {
private UserInfoDto user;
private Long id;
private String title;
private String writing;
private String content;
// private List<TourPostHashTag> tags;
private String imgUrl;
private List<TourPostItemDTO> postItems;
// private List<TourPostItemDTO> postItems;
}

0 comments on commit d02fccb

Please sign in to comment.