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

refactor: COGO 조회 response dto 수정 #160

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import java.net.URI;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -52,16 +52,16 @@ public ResponseEntity<ApiResponseGenerator<List<PossibleDateCreateGetResponseDto
);
}

@GetMapping
@GetMapping("{mentorId}")
@Operation(summary = "멘토ID로 커피챗 가능시간 불러오기")
@ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환")
public ResponseEntity<ApiResponseGenerator<List<PossibleDateCreateGetResponseDto>>> getPossibleDates(
Authentication authentication
) throws Exception {
Authentication authentication,
@PathVariable("mentorId") Long mentorId
) {
return ResponseEntity.ok().body(
ApiResponseGenerator.onSuccessOK(
possibleDateService.findPossibleDateListByMentor(getUserNameByAuthentication(authentication))
)
possibleDateService.findPossibleDateListByMentor(mentorId))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public class ApplicationCreateResponseDto {
private String applicationMemo;

@JsonProperty("application_date")
@Schema(type = "string", pattern = "yyyy-MM-dd")
@Schema(type = "string", pattern = "yyyy-mm-dd")
private LocalDate applicationDate;

@JsonProperty("application_start_time")
@Schema(type = "string", pattern = "HH-mm")
@Schema(type = "string", pattern = "hh:mm:ss")
private LocalTime applicationStartTime;

@JsonProperty("application_end_time")
@Schema(type = "string", pattern = "HH-mm")
@Schema(type = "string", pattern = "hh:mm:ss")
private LocalTime applicationEndTime;

public static ApplicationCreateResponseDto from(Application application) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class ApplicationGetResponseDto {
@JsonProperty("mentee_name")
private String menteeName;

@JsonProperty("mentor_name")
private String mentorName;

@JsonProperty("application_memo")
private String memo;

Expand All @@ -31,16 +34,17 @@ public class ApplicationGetResponseDto {
private LocalDate date;

@JsonProperty("application_start_time")
@Schema(type = "string", pattern = "HH-mm", example = "14:30")
@Schema(type = "string", pattern = "hh:mm:ss")
private LocalTime startTime;

@JsonProperty("application_end_time")
@Schema(type = "string", pattern = "HH-mm", example = "15:30")
@Schema(type = "string", pattern = "hh:mm:ss")
private LocalTime endTime;

public static ApplicationGetResponseDto toDto(Application application, String menteeName) {
public static ApplicationGetResponseDto toDto(Application application, String mentorName, String menteeName) {
return ApplicationGetResponseDto.builder()
.applicationId(application.getId())
.mentorName(mentorName)
.menteeName(menteeName)
.memo(application.getMemo())
.date(application.getPossibleDate().getDate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public class PossibleDateCreateGetResponseDto {
private LocalDate date;

@JsonProperty("start_time")
@Schema(type = "string", pattern = "HH-mm")
@Schema(type = "string", pattern = "hh:mm:ss")
private LocalTime startTime;

@JsonProperty("end_time")
@Schema(type = "string", pattern = "HH-mm")
@Schema(type = "string", pattern = "hh:mm:ss")
private LocalTime endTime;

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class PossibleDateCreateRequestDto {
private LocalDate date;

@JsonProperty("start_time")
@Schema(type = "string", pattern = "HH-mm")
@Schema(type = "string", pattern = "hh:mm:ss")
private LocalTime startTime;

@JsonProperty("end_time")
@Schema(type = "string", pattern = "HH-mm")
@Schema(type = "string", pattern = "hh:mm:ss")
private LocalTime endTime;

@QueryProjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,12 @@ public ApplicationGetResponseDto getApplication(Long applicationId) {
APPLICATION_NOT_FOUND.getErrorMessage()
));
User findMenteeUser = userRepository.findByMenteeId(findApplication.getMentee().getId());
User findMentorUser = userRepository.findByMentor(findApplication.getMentor());
//TODO: toDTO 빌더 만들어두고, join으로 묶자
return ApplicationGetResponseDto.builder()
.applicationId(applicationId)
.menteeName(findMenteeUser.getName())
.mentorName(findMentorUser.getName())
.memo(findApplication.getMemo())
.date(findApplication.getPossibleDate().getDate())
.startTime(findApplication.getPossibleDate().getStartTime())
Expand Down Expand Up @@ -260,6 +262,7 @@ public List<ApplicationGetResponseDto> getApplications(String username, String a
// MATCHED든 UNMATCHED든 둘 중 하나 필터링 된 것들 다 반환
dtos.add(ApplicationGetResponseDto.toDto(
app,
user.getName(),
findMenteeUser.getName()
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.soongsil.CoffeeChat.service;

import static com.soongsil.CoffeeChat.controller.exception.enums.UserErrorCode.*;

import java.util.List;
import java.util.stream.Collectors;

import com.soongsil.CoffeeChat.controller.exception.CustomException;
import com.soongsil.CoffeeChat.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.soongsil.CoffeeChat.controller.exception.CustomException;
import com.soongsil.CoffeeChat.dto.PossibleDateCreateGetResponseDto;
import com.soongsil.CoffeeChat.dto.PossibleDateCreateRequestDto;
import com.soongsil.CoffeeChat.entity.Mentor;
import com.soongsil.CoffeeChat.entity.PossibleDate;
import com.soongsil.CoffeeChat.entity.User;
import com.soongsil.CoffeeChat.repository.PossibleDate.PossibleDateRepository;
import com.soongsil.CoffeeChat.repository.User.UserRepository;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import static com.soongsil.CoffeeChat.controller.exception.enums.UserErrorCode.USER_NOT_FOUND;

@Service
@RequiredArgsConstructor
@Slf4j
Expand All @@ -28,7 +28,7 @@ public class PossibleDateService {
private final PossibleDateRepository possibleDateRepository;
private final UserRepository userRepository;

private User findUserByUsername(String username){
private User findUserByUsername(String username) {
return userRepository.findByUsername(username)
.orElseThrow(() -> new CustomException(
USER_NOT_FOUND.getHttpStatusCode(),
Expand Down Expand Up @@ -63,10 +63,7 @@ public List<PossibleDateCreateGetResponseDto> updatePossibleDate(List<PossibleDa
.collect(Collectors.toList());
}


public List<PossibleDateCreateGetResponseDto> findPossibleDateListByMentor(String username) {
User user = findUserByUsername(username);
Long mentorId = user.getMentor().getId();
public List<PossibleDateCreateGetResponseDto> findPossibleDateListByMentor(Long mentorId) {
return possibleDateRepository.getPossibleDatesByMentorId(mentorId)
.stream()
.map(possibleDate -> PossibleDateCreateGetResponseDto.builder()
Expand Down
Loading