Skip to content

Commit 3425638

Browse files
committed
Merge branch 'dev' into feat/#56
2 parents fb54109 + fea1590 commit 3425638

File tree

63 files changed

+2198
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2198
-204
lines changed
+40-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
name: 🧪 Backend Tests on Pull Request
2-
3-
on:
4-
pull_request:
5-
branches:
6-
- main
7-
- dev
8-
9-
jobs:
10-
project-test:
11-
runs-on: ubuntu-latest
12-
13-
steps:
14-
- name: 📦 Checkout repository
15-
uses: actions/checkout@v4
16-
17-
- name: 🖼️ Install ImageMagick
18-
run: sudo apt-get install -y imagemagick
19-
20-
- name: 🏗️ Set up JDK 17
21-
uses: actions/setup-java@v4
22-
with:
23-
distribution: 'temurin'
24-
java-version: '17'
25-
26-
- name: 🎟️ Grant execute permission for gradlew
27-
run: chmod +x gradlew
28-
29-
- name: 🧪 Spring Boot Test
30-
run: ./gradlew clean test -i
31-
32-
- name: Add coverage to PR
33-
id: jacoco
34-
uses: madrapps/[email protected]
35-
with:
36-
title: 📄 Jacoco Coverage Report
37-
paths: ${{ github.workspace }}/**/reports/jacoco/test/jacocoTestReport.xml
38-
token: ${{ secrets.GITHUB_TOKEN }}
39-
min-coverage-overall: 80
40-
min-coverage-changed-files: 80
1+
#name: 🧪 Backend Tests on Pull Request
2+
#
3+
#on:
4+
# pull_request:
5+
# branches:
6+
# - main
7+
# - dev
8+
#
9+
#jobs:
10+
# project-test:
11+
# runs-on: ubuntu-latest
12+
#
13+
# steps:
14+
# - name: 📦 Checkout repository
15+
# uses: actions/checkout@v4
16+
#
17+
# - name: 🖼️ Install ImageMagick
18+
# run: sudo apt-get install -y imagemagick
19+
#
20+
# - name: 🏗️ Set up JDK 17
21+
# uses: actions/setup-java@v4
22+
# with:
23+
# distribution: 'temurin'
24+
# java-version: '17'
25+
#
26+
# - name: 🎟️ Grant execute permission for gradlew
27+
# run: chmod +x gradlew
28+
#
29+
# - name: 🧪 Spring Boot Test
30+
# run: ./gradlew clean test -i
31+
#
32+
# - name: Add coverage to PR
33+
# id: jacoco
34+
# uses: madrapps/[email protected]
35+
# with:
36+
# title: 📄 Jacoco Coverage Report
37+
# paths: ${{ github.workspace }}/**/reports/jacoco/test/jacocoTestReport.xml
38+
# token: ${{ secrets.GITHUB_TOKEN }}
39+
# min-coverage-overall: 80
40+
# min-coverage-changed-files: 80

application/wypl-core/src/main/java/com/wypl/wyplcore/auth/service/AuthServiceImpl.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import com.wypl.jpamemberdomain.member.OauthProvider;
1616
import com.wypl.jpamemberdomain.member.data.MemberSaveDto;
1717
import com.wypl.jpamemberdomain.member.data.SocialMemberSaveDto;
18-
import com.wypl.jpamemberdomain.member.repository.MemberRepository;
1918
import com.wypl.jpamemberdomain.member.repository.SocialMemberRepository;
2019
import com.wypl.jpamemberdomain.member.utils.SocialMemberRepositoryUtils;
2120
import com.wypl.wyplcore.auth.data.response.AuthTokensResponse;
21+
import com.wypl.wyplcore.member.service.MemberServiceImpl;
2222

2323
import lombok.RequiredArgsConstructor;
2424

@@ -28,8 +28,8 @@
2828
public class AuthServiceImpl {
2929
private final GoogleOAuthClient googleOAuthClient;
3030
private final SocialMemberRepository socialMemberRepository;
31-
private final MemberRepository memberRepository;
3231
private final AuthDomainServiceImpl authDomainService;
32+
private final MemberServiceImpl memberService;
3333

3434
@Transactional
3535
public AuthTokensResponse generateToken(final String provider, final String code) {
@@ -68,21 +68,18 @@ public void logout(AuthMember authMember) {
6868
public void quitMember(AuthMember authMember) {
6969
// Todo : 회원 탈퇴 로직 논의
7070
deleteToken(authMember);
71-
deleteMember(authMember);
71+
memberService.deleteMember(authMember);
7272
}
7373

7474
private void deleteToken(AuthMember authMember) {
7575
authDomainService.deleteToken(authMember.accessToken());
7676
}
7777

78-
private void deleteMember(AuthMember authMember) {
79-
memberRepository.deleteById(authMember.id());
80-
}
81-
8278
private boolean isInvalidRefreshToken(String accessToken, String refreshToken) {
8379
return refreshToken.isEmpty() || !refreshToken.equals(authDomainService.getRefreshToken(accessToken));
8480
}
8581

82+
// todo:
8683
private long findMemberIdAfterSaveMember(String accessToken, GoogleUserInfoResponse googleUserInfoResponse) {
8784
if (isNewMember(googleUserInfoResponse)) {
8885
LocalDate birthday = googleOAuthClient.fetchBirthday(accessToken);
@@ -105,6 +102,7 @@ private long findMemberIdAfterSaveMember(String accessToken, GoogleUserInfoRespo
105102
return SocialMemberRepositoryUtils.getSocialMember(socialMemberRepository, googleUserInfoResponse.id()).getId();
106103
}
107104

105+
// todo:
108106
private boolean isNewMember(GoogleUserInfoResponse googleUserInfoResponse) {
109107
return !socialMemberRepository.existsByOauthProviderAndOauthId(OauthProvider.GOOGLE,
110108
googleUserInfoResponse.id());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.wypl.wyplcore.calendar.data;
2+
3+
import java.time.LocalDate;
4+
5+
public record DateSearchCondition(LocalDate startDate, LocalDate endDate) {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.wypl.wyplcore.calendar.data.request;
2+
3+
import java.time.LocalDate;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.wypl.wyplcore.schedule.data.CalendarType;
7+
8+
public record CalendarFindRequest(
9+
10+
@JsonProperty("calendar_type")
11+
CalendarType calendarType,
12+
13+
@JsonProperty("start_date")
14+
LocalDate today
15+
) {
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.wypl.wyplcore.calendar.data.response;
2+
3+
import java.util.List;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.wypl.wyplcore.schedule.data.response.ScheduleFindResponse;
7+
8+
public record CalendarSchedulesResponse(
9+
10+
@JsonProperty("schedule_count")
11+
int scheduleCount,
12+
13+
@JsonProperty("schedules")
14+
List<ScheduleFindResponse> schedules
15+
) {
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.wypl.wyplcore.calendar.service;
2+
3+
import java.time.LocalDate;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import org.springframework.stereotype.Service;
8+
import org.springframework.transaction.annotation.Transactional;
9+
10+
import com.wypl.googleoauthclient.domain.AuthMember;
11+
import com.wypl.jpacalendardomain.calendar.domain.Calendar;
12+
import com.wypl.jpacalendardomain.calendar.domain.MemberCalendar;
13+
import com.wypl.jpacalendardomain.calendar.domain.Schedule;
14+
import com.wypl.jpacalendardomain.calendar.repository.ScheduleRepository;
15+
import com.wypl.jpamemberdomain.member.domain.Member;
16+
import com.wypl.wyplcore.calendar.data.DateSearchCondition;
17+
import com.wypl.wyplcore.calendar.data.request.CalendarFindRequest;
18+
import com.wypl.wyplcore.calendar.data.response.CalendarSchedulesResponse;
19+
import com.wypl.wyplcore.calendar.service.strategy.CalendarStrategy;
20+
import com.wypl.wyplcore.schedule.data.CalendarType;
21+
import com.wypl.wyplcore.schedule.data.response.ScheduleFindResponse;
22+
import com.wypl.wyplcore.schedule.service.repetition.RepetitionService;
23+
24+
import lombok.RequiredArgsConstructor;
25+
26+
@Service
27+
@RequiredArgsConstructor
28+
public class CalendarService {
29+
30+
private final ScheduleRepository scheduleRepository;
31+
32+
private final Map<CalendarType, CalendarStrategy> calendarStrategyMap;
33+
34+
/**
35+
* 캘린더의 일정을 조회한다.
36+
* @param authMember : 인증된 사용자 정보
37+
* @param calendarId : 조회할 캘린더 ID
38+
* @param calendarFindRequest : 캘린더 조회 조건
39+
* @return FindCalendarResponse
40+
*/
41+
@Transactional(readOnly = true)
42+
public CalendarSchedulesResponse findCalendar(AuthMember authMember, long calendarId,
43+
CalendarFindRequest calendarFindRequest) {
44+
45+
Calendar foundCalendar = null; // FIXME: calendarId로 foundCalendar 엔티티 검증 필요.
46+
MemberCalendar foundMemberCalendar = null; // FIXME: memberCalendar 엔티티 검증 필요.
47+
Member foundMember = null; // FIXME: member 엔티티 검증 필요.
48+
49+
DateSearchCondition dateSearchCondition = getDateSearchCondition(calendarFindRequest.today(),
50+
calendarFindRequest.calendarType());
51+
52+
List<Schedule> schedules = scheduleRepository.findByCalendarIdAndBetweenStartDateAndEndDate(calendarId,
53+
dateSearchCondition.startDate(), dateSearchCondition.endDate());
54+
55+
List<ScheduleFindResponse> responses = schedules.stream()
56+
.flatMap(schedule -> getScheduleResponsesWithRepetition(schedule, dateSearchCondition.startDate(),
57+
dateSearchCondition.endDate()).stream())
58+
.toList();
59+
60+
return new CalendarSchedulesResponse(responses.size(), responses);
61+
}
62+
63+
/**
64+
* RepetitionService를 통해 반복 일정을 가공하여 조회한다.
65+
* @param schedule : 일정 정보
66+
* @param startDate : 조회 시작일
67+
* @param endDate : 조회 종료일
68+
* @return List<ScheduleFindResponse> : 일정 반복 정보를 통해 리스트 형태로 가공하여 반환된다.
69+
*/
70+
private List<ScheduleFindResponse> getScheduleResponsesWithRepetition(Schedule schedule, LocalDate startDate,
71+
LocalDate endDate) {
72+
return RepetitionService.getScheduleResponses(schedule, startDate, endDate);
73+
}
74+
75+
/**
76+
* CalendarType에 따라 DateSearchCondition을 반환한다.
77+
* @param today : 조회 기준일
78+
* @param calendarType : 조회할 캘린더 타입
79+
* @return DateSearchCondition : DateSearchCondition 객체를 반환한다.
80+
*/
81+
private DateSearchCondition getDateSearchCondition(LocalDate today, CalendarType calendarType) {
82+
return calendarStrategyMap.get(calendarType).getDateSearchCondition(today);
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.wypl.wyplcore.calendar.service;
2+
3+
import java.time.LocalDate;
4+
5+
public class CalendarServiceUtil {
6+
7+
public static LocalDate getMaxDate(LocalDate date1, LocalDate date2) {
8+
return date1.isBefore(date2) ? date2 : date1;
9+
}
10+
11+
public static LocalDate getMinDate(LocalDate date1, LocalDate date2) {
12+
return date1.isBefore(date2) ? date1 : date2;
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.wypl.wyplcore.calendar.service.strategy;
2+
3+
import java.time.LocalDate;
4+
5+
import com.wypl.wyplcore.calendar.data.DateSearchCondition;
6+
import com.wypl.wyplcore.schedule.data.CalendarType;
7+
8+
public interface CalendarStrategy {
9+
10+
CalendarType getCalendarType();
11+
12+
DateSearchCondition getDateSearchCondition(LocalDate today);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.wypl.wyplcore.calendar.service.strategy;
2+
3+
import java.util.HashMap;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
import com.wypl.wyplcore.schedule.data.CalendarType;
12+
13+
@Configuration
14+
public class CalendarStrategyConfig {
15+
16+
private final Map<CalendarType, CalendarStrategy> calendarStrategyMap = new HashMap<>();
17+
18+
@Autowired
19+
public CalendarStrategyConfig(List<CalendarStrategy> calendarStrategies) {
20+
calendarStrategies.forEach(calendarStrategy -> {
21+
calendarStrategyMap.put(calendarStrategy.getCalendarType(), calendarStrategy);
22+
});
23+
}
24+
25+
@Bean
26+
public Map<CalendarType, CalendarStrategy> calendarStrategyMap() {
27+
return calendarStrategyMap;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.wypl.wyplcore.calendar.service.strategy;
2+
3+
import java.time.LocalDate;
4+
5+
import org.springframework.stereotype.Component;
6+
7+
import com.wypl.wyplcore.calendar.data.DateSearchCondition;
8+
import com.wypl.wyplcore.schedule.data.CalendarType;
9+
10+
import lombok.RequiredArgsConstructor;
11+
12+
@Component
13+
@RequiredArgsConstructor
14+
public class DayCalendarStrategy implements CalendarStrategy {
15+
16+
@Override
17+
public CalendarType getCalendarType() {
18+
return CalendarType.DAY;
19+
}
20+
21+
@Override
22+
public DateSearchCondition getDateSearchCondition(LocalDate today) {
23+
return new DateSearchCondition(today, today);
24+
}
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.wypl.wyplcore.calendar.service.strategy;
2+
3+
import java.time.LocalDate;
4+
import java.time.temporal.TemporalAdjusters;
5+
6+
import org.springframework.stereotype.Component;
7+
8+
import com.wypl.wyplcore.calendar.data.DateSearchCondition;
9+
import com.wypl.wyplcore.schedule.data.CalendarType;
10+
11+
import lombok.RequiredArgsConstructor;
12+
13+
@Component
14+
@RequiredArgsConstructor
15+
public class MonthCalendarStrategy implements CalendarStrategy {
16+
17+
@Override
18+
public CalendarType getCalendarType() {
19+
return CalendarType.MONTH;
20+
}
21+
22+
@Override
23+
public DateSearchCondition getDateSearchCondition(LocalDate today) {
24+
LocalDate searchStartDate = today.withDayOfMonth(1);
25+
LocalDate searchEndDate = today.with(TemporalAdjusters.lastDayOfMonth());
26+
return new DateSearchCondition(searchStartDate, searchEndDate);
27+
}
28+
}

0 commit comments

Comments
 (0)