Skip to content

Commit

Permalink
Feat: 마이페이지 일정 목록 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
nohy6630 committed May 16, 2024
1 parent 7ae6131 commit e8ae83c
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface DirectChatRoomRepositoryCustom {
List<DirectChatRoom> findForUser(User user);

List<DirectChatRoom> findUpdatableRooms();

List<DirectChatRoom> findAppointmentForUserInMonth(User who, int year, int month);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@ public List<DirectChatRoom> findUpdatableRooms() {
.where(directChatRoom.nextAppointment.appointmentDate.before(LocalDate.now()))
.fetch();
}

@Override
public List<DirectChatRoom> findAppointmentForUserInMonth(User who, int year, int month) {
return jpaQueryFactory
.selectFrom(directChatRoom)
.join(directChatRoom.userChatRooms, userChatRoom)
.join(userChatRoom.user, user)
.where(user.eq(who)
.and(directChatRoom.nextAppointment.appointmentDate.year().eq(year))
.and(directChatRoom.nextAppointment.appointmentDate.month().eq(month)))
.orderBy(directChatRoom.updatedAt.desc())
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public interface GroupChatRoomRepositoryCustom {
List<GroupChatRoom> findForUser(User user);

List<GroupChatRoom> findUpdatableRooms();

List<GroupChatRoom> findAppointmentForUserInMonth(User who, int year, int month);

List<GroupChatRoom> findActivityForUserInMonth(User who, int year, int month);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,30 @@ public List<GroupChatRoom> findUpdatableRooms() {
.where(groupChatRoom.nextAppointment.appointmentDate.before(LocalDate.now()))
.fetch();
}

@Override
public List<GroupChatRoom> findAppointmentForUserInMonth(User who, int year, int month) {
return jpaQueryFactory
.selectFrom(groupChatRoom)
.join(groupChatRoom.userChatRooms, userChatRoom)
.join(userChatRoom.user, user)
.where(user.eq(who)
.and(groupChatRoom.nextAppointment.appointmentDate.year().eq(year))
.and(groupChatRoom.nextAppointment.appointmentDate.month().eq(month)))
.orderBy(groupChatRoom.updatedAt.desc())
.fetch();
}

@Override
public List<GroupChatRoom> findActivityForUserInMonth(User who, int year, int month) {
return jpaQueryFactory
.selectFrom(groupChatRoom)
.join(groupChatRoom.userChatRooms, userChatRoom)
.join(userChatRoom.user, user)
.where(user.eq(who)
.and(groupChatRoom.activity.time.year().eq(year))
.and(groupChatRoom.activity.time.month().eq(month)))
.orderBy(groupChatRoom.updatedAt.desc())
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.meetup.teame.backend.domain.user.controller;

import com.meetup.teame.backend.domain.user.dto.request.OnboardingReq;
import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq;
import com.meetup.teame.backend.domain.user.dto.response.ReadCalenderRes;
import com.meetup.teame.backend.domain.user.dto.response.ReadMainRes;
import com.meetup.teame.backend.domain.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -20,9 +22,9 @@ public class UserController {
@Operation(summary = "메인 페이지 조회", description = """
현재 로그인한 유저의 메인 페이지를 조회합니다.
아직 로그인이 없어서 임시로 고정된 더미 유저의 데이터를 전달하는 식으로 구현되어 있습니다.
임시로 고정된 더미 유저의 데이터를 전달하는 식으로 구현되어 있습니다.
추후 로그인 적용 시에는 jwt토큰도 같이 전달해서 요청해주셔야 합니다.
jwt토큰도 같이 전달해서 요청해주셔야 합니다.
""")
@GetMapping("/main")
public ResponseEntity<ReadMainRes> readMainPage() {
Expand All @@ -33,18 +35,38 @@ public ResponseEntity<ReadMainRes> readMainPage() {
@Operation(summary = "온보딩 정보 등록", description = """
유저의 온보딩 정보를 등록합니다.
아직 로그인이 없어서 임시로 고정된 더미 유저의 온보딩 정보를 등록하는 식으로 구현되어 있습니다.
임시로 고정된 더미 유저의 온보딩 정보를 등록하는 식으로 구현되어 있습니다.
jwt토큰도 같이 전달해서 요청해주셔야 합니다.
추후 로그인 적용 시에는 jwt토큰도 같이 전달해서 요청해주셔야 합니다.
현재 온보딩 정보로 입력 가능한 성격 유형
("잔잔한", "활발한", "평화로운", "자연친화적인", "창의적인", "학문적인", "예술적인", "배울 수 있는")
위 유형들 중 최소 1개 이상을 선택해서 Request Body에 담아 전송해주세요.
""")
@PatchMapping("/onboarding")
public ResponseEntity<Void> setUserPersonality(@RequestBody @Valid OnboardingReq onboardingReq){
public ResponseEntity<Void> setUserPersonality(@RequestBody @Valid OnboardingReq onboardingReq) {
userService.setUserPersonality(onboardingReq);
return ResponseEntity
.ok().build();
}


@Operation(summary = "마이페이지 캘린더 조회", description = """
유저의 캘린더 정보를 조회합니다.
임시로 고정된 더미 유저의 캘린더 정보를 조회하는 식으로 구현되어 있습니다.
jwt토큰도 같이 전달해서 요청해주셔야 합니다.
url 쿼리 파라미터로 다음과 같은 값을 전달해 주셔야 합니다.
year : 년도
month : 월
""")
@GetMapping("/mypage/calender")
public ResponseEntity<ReadCalenderRes> readCalender(@ModelAttribute @Valid ReadCalenderReq readCalenderReq) {
return ResponseEntity
.ok(userService.readCalender(readCalenderReq));
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.meetup.teame.backend.domain.user.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Getter
public class ReadCalenderReq {
@NotBlank(message="year is required.")
@Schema(example = "2024")
private Integer year;

@NotBlank(message="month is required.")
@Schema(example = "5")
private Integer month;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static AppointmentRes ofGroupChatRoom(GroupChatRoom groupChatRoom) {
return AppointmentRes.builder()
.date(groupChatRoom.getNextAppointment().getAppointmentDate())
.tag(groupChatRoom.getActivity().getTitle())
.description(groupChatRoom.getNextAppointment().getAppointmentDate() + " 약속")
.description(groupChatRoom.getActivity().getTitle() + " 약속")
.about(groupChatRoom.getNextAppointment().getAppointmentLocation())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
public class ReadCalenderRes {
List<AppointmentRes> appointments;

public static ReadCalenderRes of(List<GroupChatRoom> groupChatRooms, List<DirectChatRoom> directChatRooms) {
public static ReadCalenderRes of(List<GroupChatRoom> groupChatRoomsByActivity, List<DirectChatRoom> directChatRooms, List<GroupChatRoom> groupChatRooms) {
List<AppointmentRes> appointments = new ArrayList<>();
appointments.addAll(groupChatRooms.stream()
appointments.addAll(groupChatRoomsByActivity.stream()
.map(AppointmentRes::ofActivity)
.toList());
appointments.addAll(directChatRooms.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.meetup.teame.backend.domain.activity.repository.ActivityRepository;
import com.meetup.teame.backend.domain.auth.oauth.dto.CreateUserRequest;
import com.meetup.teame.backend.domain.chatroom.repository.DirectChatRoomRepository;
import com.meetup.teame.backend.domain.chatroom.repository.GroupChatRoomRepository;
import com.meetup.teame.backend.domain.experience.repository.ExperienceRepository;
import com.meetup.teame.backend.domain.personality.Personality;
import com.meetup.teame.backend.domain.user.dto.request.OnboardingReq;
import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq;
import com.meetup.teame.backend.domain.user.dto.response.ReadCalenderRes;
import com.meetup.teame.backend.domain.user.dto.response.ReadMainRes;
import com.meetup.teame.backend.domain.user.entity.Gender;
import com.meetup.teame.backend.domain.user.entity.User;
Expand All @@ -28,6 +32,8 @@ public class UserService {
private final UserRepository userRepository;
private final ActivityRepository activityRepository;
private final ExperienceRepository experienceRepository;
private final DirectChatRoomRepository directChatRoomRepository;
private final GroupChatRoomRepository groupChatRoomRepository;

public ReadMainRes readMainPage() {
//todo 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함
Expand All @@ -48,7 +54,7 @@ public User createUser(CreateUserRequest request) {
return User.builder()
.name(request.getName())
.email(request.getEmail())
.gender(Objects.equals(request.getGender(), "male") ? Gender.MALE:Gender.FEMALE)
.gender(Objects.equals(request.getGender(), "male") ? Gender.MALE : Gender.FEMALE)
.age(age)
.location(request.getLocation())
.point(0L)
Expand Down Expand Up @@ -76,4 +82,15 @@ public void setUserPersonality(OnboardingReq onboardingReq) {
.toList();
user.setPersonalities(personalities);
}

public ReadCalenderRes readCalender(ReadCalenderReq readCalenderReq) {
//todo 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함
User user = userRepository.findById(5L)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
return ReadCalenderRes.of(
groupChatRoomRepository.findActivityForUserInMonth(user, readCalenderReq.getYear(), readCalenderReq.getMonth()),
directChatRoomRepository.findAppointmentForUserInMonth(user, readCalenderReq.getYear(), readCalenderReq.getMonth()),
groupChatRoomRepository.findAppointmentForUserInMonth(user, readCalenderReq.getYear(), readCalenderReq.getMonth())
);
}
}

0 comments on commit e8ae83c

Please sign in to comment.