Skip to content

Commit

Permalink
Merge pull request #84 from TeamPINGLE/fix/82
Browse files Browse the repository at this point in the history
[fix] 기타 수정
  • Loading branch information
tkdwns414 authored Jan 15, 2024
2 parents 5f54654 + f133fd6 commit 2420382
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
import java.util.List;

public record PinResponse(Long id, Double x, Double y, MCategory category, int meetingCount) {
public static PinResponse ofWithoutCategory(Pin pin) {
return new PinResponse(pin.getId(),pin.getPoint().getX(), pin.getPoint().getY(),
getMostRecentMeetingCategoryOfPin(pin), getMeetingCount(pin));
}

public static PinResponse ofWithCategory(Pin pin, MCategory category, int count) {
public static PinResponse of(Pin pin, MCategory category, int count) {
return new PinResponse(pin.getId(),pin.getPoint().getX(), pin.getPoint().getY(),
category, count);
}

public static PinResponse ofWithNoFilter(Pin pin) {
return new PinResponse(pin.getId(),pin.getPoint().getX(), pin.getPoint().getY(),
getMostRecentMeetingCategoryOfPin(pin), getMeetingCount(pin));

}
public static PinResponse ofWithFilter(Pin pin, MCategory mCategory) {
return new PinResponse(pin.getId(),pin.getPoint().getX(), pin.getPoint().getY(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public enum ErrorMessage {
INVALID_TOKEN_TYPE(HttpStatus.UNAUTHORIZED, "유효하지 않은 토큰 타입입니다."),
// Invalid Argument Error 400
BAD_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."),
ALREADY_REGISTERED_USER(HttpStatus.BAD_REQUEST, "이미 가입된 사용자입니다."),
INVALID_GROUP_CODE(HttpStatus.BAD_REQUEST, "유효하지 않은 그룹 코드입니다."),
INVALID_HEADER_ERROR(HttpStatus.BAD_REQUEST, "유효하지 않은 헤더입니다."),
INVALID_PROVIDER_ERROR(HttpStatus.BAD_REQUEST, "유효하지 않은 소셜 플랫폼입니다."),
Expand All @@ -40,6 +39,7 @@ public enum ErrorMessage {
METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, "지원하지 않는 메소드입니다."),
// Conflict Error 409
RESOURCE_CONFLICT(HttpStatus.CONFLICT, "리소스 충돌이 일어났습니다."),
ALREADY_REGISTERED_USER(HttpStatus.CONFLICT, "이미 가입된 사용자입니다."),
// Internal Server Error 500
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류입니다.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface MeetingRepository extends JpaRepository<Meeting, Long> {
@Query("SELECT COUNT(m) FROM Meeting m WHERE m.pin.id = :pinId AND m.startAt > CURRENT_TIMESTAMP")
int countMeetingsForPinWithoutCategory(Long pinId);

@Query("SELECT COUNT(m) FROM Meeting m WHERE m.pin.id = :pinId AND m.startAt > CURRENT_TIMESTAMP AND m.category = :category")
int countMeetingsForPin(Long pinId, MCategory category);
int countMeetingsForPinWithCategory(Long pinId, MCategory category);

Optional<Meeting> findFirstByPinIdAndStartAtAfterOrderByStartAtAsc(Long pinId, LocalDateTime currentTime);

List<Meeting> findByPinIdAndCategoryAndStartAtAfterOrderByStartAt(Long pinId, MCategory category, LocalDateTime currentTime);

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/pingle/pingleserver/service/PinService.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,18 @@ public List<PinResponse> getPins(Long teamId, MCategory category) {

if (category == null) {
pins = pinRepository.findPinsAndTimeBefore(teamId);
return pins.stream().map(PinResponse::ofWithoutCategory).toList();
return pins.stream().map(pin -> {
return PinResponse.of(
pin,
meetingRepository.findFirstByPinIdAndStartAtAfterOrderByStartAtAsc(pin.getId(), LocalDateTime.now())
.map(Meeting::getCategory).orElse(MCategory.OTHERS),
meetingRepository.countMeetingsForPinWithoutCategory(pin.getId()));
}).toList();
}

pins = pinRepository.findPinsWithCategoryAndTimeBefore(teamId, category);
return pins.stream()
.map(pin -> PinResponse.ofWithCategory(pin, category, meetingRepository.countMeetingsForPin(pin.getId(), category))).toList();
.map(pin -> PinResponse.of(pin, category, meetingRepository.countMeetingsForPinWithCategory(pin.getId(), category))).toList();
}

public List<MeetingResponse> getMeetings(Long pinId, Long userId, MCategory category){
Expand Down

0 comments on commit 2420382

Please sign in to comment.