Skip to content

Commit

Permalink
Merge pull request #138 from teamterning/refactor/#137
Browse files Browse the repository at this point in the history
[♻️ refactor] 홈 > 곧 마감되는 관심공고 : 분기 처리를 위한 데이터 형식 추가
  • Loading branch information
junggyo1020 authored Sep 20, 2024
2 parents 0eddd35 + d672e45 commit 3026059
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

import java.util.List;

import static org.terning.terningserver.exception.enums.SuccessMessage.SUCCESS_GET_ANNOUNCEMENTS;
import static org.terning.terningserver.exception.enums.SuccessMessage.SUCCESS_GET_UPCOMING_ANNOUNCEMENTS;
import static org.terning.terningserver.exception.enums.SuccessMessage.*;

@RestController
@RequiredArgsConstructor
Expand All @@ -41,8 +40,17 @@ public ResponseEntity<SuccessResponse<List<UpcomingScrapResponseDto>>> getUpcomi
@AuthenticationPrincipal Long userId
){

List<UpcomingScrapResponseDto> scrapList = scrapService.getUpcomingScrap(userId);
boolean hasScrapped = scrapService.hasUserScrapped(userId);
List<UpcomingScrapResponseDto.ScrapDetail> scrapList = scrapService.getUpcomingScrap(userId);

return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS, scrapList));
UpcomingScrapResponseDto responseDto = new UpcomingScrapResponseDto(hasScrapped, scrapList);

if(!hasScrapped){
return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS_NO_SCRAP, responseDto));
} else if (scrapList.isEmpty()) {
return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS_EMPTY_LIST, responseDto));
} else {
return ResponseEntity.ok(SuccessResponse.of(SUCCESS_GET_UPCOMING_ANNOUNCEMENTS, responseDto));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,41 @@
import org.terning.terningserver.domain.Scrap;
import org.terning.terningserver.util.DateUtil;

import java.util.List;

@Builder
public record UpcomingScrapResponseDto(
Long internshipAnnouncementId,
String companyImage,
String dDay,
String title,
String workingPeriod,
boolean isScrapped,
String color,
String deadline,
String startYearMonth,
String companyInfo
boolean hasScrapped,
List<ScrapDetail> scraps
) {
public static UpcomingScrapResponseDto of(final Scrap scrap){
String startYearMonth = scrap.getInternshipAnnouncement().getStartYear() + "년 " + scrap.getInternshipAnnouncement().getStartMonth() + "월";
@Builder
public record ScrapDetail(
Long internshipAnnouncementId,
String companyImage,
String dDay,
String title,
String workingPeriod,
boolean isScrapped,
String color,
String deadline,
String startYearMonth,
String companyInfo
) {
public static ScrapDetail of(final Scrap scrap) {
String startYearMonth = scrap.getInternshipAnnouncement().getStartYear() + "년 " + scrap.getInternshipAnnouncement().getStartMonth() + "월";

return UpcomingScrapResponseDto.builder()
.internshipAnnouncementId(scrap.getInternshipAnnouncement().getId())
.companyImage(scrap.getInternshipAnnouncement().getCompany().getCompanyImage())
.dDay(DateUtil.convert(scrap.getInternshipAnnouncement().getDeadline()))
.title(scrap.getInternshipAnnouncement().getTitle())
.deadline(DateUtil.convertDeadline(scrap.getInternshipAnnouncement().getDeadline()))
.isScrapped(true) // 스크랩된 항목이므로 항상 true
.color(scrap.getColorToHexValue())
.workingPeriod(scrap.getInternshipAnnouncement().getWorkingPeriod())
.startYearMonth(startYearMonth)
.companyInfo(scrap.getInternshipAnnouncement().getCompany().getCompanyInfo())
.build();
return ScrapDetail.builder()
.internshipAnnouncementId(scrap.getInternshipAnnouncement().getId())
.companyImage(scrap.getInternshipAnnouncement().getCompany().getCompanyImage())
.dDay(DateUtil.convert(scrap.getInternshipAnnouncement().getDeadline()))
.title(scrap.getInternshipAnnouncement().getTitle())
.deadline(DateUtil.convertDeadline(scrap.getInternshipAnnouncement().getDeadline()))
.isScrapped(true) // 스크랩된 항목이므로 항상 true
.color(scrap.getColorToHexValue())
.workingPeriod(scrap.getInternshipAnnouncement().getWorkingPeriod())
.startYearMonth(startYearMonth)
.companyInfo(scrap.getInternshipAnnouncement().getCompany().getCompanyInfo())
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public enum SuccessMessage {
// 홈 화면
SUCCESS_GET_ANNOUNCEMENTS(200, "인턴 공고 불러오기를 성공했습니다"),
SUCCESS_GET_UPCOMING_ANNOUNCEMENTS(200, "곧 마감인 인턴 공고 요청을 성공했습니다"),
SUCCESS_GET_UPCOMING_ANNOUNCEMENTS_NO_SCRAP(200, "아직 스크랩된 인턴 공고가 없어요!"),
SUCCESS_GET_UPCOMING_ANNOUNCEMENTS_EMPTY_LIST(200, "일주일 내에 마감인 공고가 없어요\n캘린더에서 스크랩한 공고 일정을 확인해 보세요"),

// 소셜 로그인
SUCCESS_SIGN_IN(200, "소셜 로그인에 성공하였습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ScrapRepository extends JpaRepository<Scrap, Long>, ScrapReposi

void deleteByInternshipAnnouncementIdAndUserId(Long internshipId, Long userId);

List<Scrap> findByUserIdAndInternshipAnnouncement_DeadlineBetween(Long userId, LocalDate start, LocalDate end);
boolean existsByUserId(Long userId);

}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import java.util.List;

public interface ScrapService {
List<UpcomingScrapResponseDto> getUpcomingScrap(Long userId);

boolean hasUserScrapped(long userId);
List<UpcomingScrapResponseDto.ScrapDetail> getUpcomingScrap(long userId);

void createScrap(Long internshipAnnouncementId, CreateScrapRequestDto request, Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ public class ScrapServiceImpl implements ScrapService {
private final UserRepository userRepository;

@Override
public List<UpcomingScrapResponseDto> getUpcomingScrap(Long userId){
public boolean hasUserScrapped(long userId) {
return scrapRepository.existsByUserId(userId);
}

@Override
public List<UpcomingScrapResponseDto.ScrapDetail> getUpcomingScrap(long userId){
LocalDate today = LocalDate.now();
LocalDate oneWeekFromToday = today.plusDays(7);
return scrapRepository.findScrapsByUserIdAndDeadlineBetweenOrderByDeadline(userId, today, oneWeekFromToday).stream()
.map(UpcomingScrapResponseDto::of)
.map(UpcomingScrapResponseDto.ScrapDetail::of)
.toList();
}

Expand Down

0 comments on commit 3026059

Please sign in to comment.