Skip to content

Commit bd117ca

Browse files
authored
Merge pull request #10 from Neighbors-dev/develop
[FEAT] 메인 페이지 조회 API 구현
2 parents c6d7656 + 6ffdd09 commit bd117ca

File tree

31 files changed

+312
-31
lines changed

31 files changed

+312
-31
lines changed

src/main/java/com/neighbors/tohero/application/baseResponse/BaseResponseMessage.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public enum BaseResponseMessage {
2121
JWT_토큰_오류입니다("JWT 토큰 오류입니다"),
2222
지원하지_않는_토큰_입니다("지원하지 않는 토큰 입니다"),
2323
토큰이_올바르지_못한_형식입니다("토큰이 올바르지 못한 형식입니다"),
24-
유효하지_않은_토큰_입니다("유효하지 않은 토큰입니다");
24+
유효하지_않은_토큰_입니다("유효하지 않은 토큰입니다"),
25+
26+
//main page
27+
메인페이지_조회가_정상적으로_실행되었습니다("메인페이지 조회가 정상적으로 실행되었습니다");
2528

2629

2730
private final String message;

src/main/java/com/neighbors/tohero/application/login/service/OAuthService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
import com.neighbors.tohero.application.baseResponse.BaseResponseMessage;
77
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
88
import com.neighbors.tohero.common.enums.Role;
9-
import com.neighbors.tohero.common.exception.user.UserException;
109
import com.neighbors.tohero.common.jwt.AuthTokens;
1110
import com.neighbors.tohero.common.jwt.JwtProvider;
1211
import com.neighbors.tohero.common.jwt.JwtUserDetails;
13-
import com.neighbors.tohero.domain.login.model.User;
14-
import com.neighbors.tohero.domain.login.service.CreateUser;
15-
import com.neighbors.tohero.domain.login.service.oauth.kakao.RequestKakaoInfo;
12+
import com.neighbors.tohero.domain.domain.login.model.User;
13+
import com.neighbors.tohero.domain.domain.login.service.CreateUser;
14+
import com.neighbors.tohero.domain.domain.login.service.oauth.kakao.RequestKakaoInfo;
1615
import lombok.RequiredArgsConstructor;
1716
import lombok.extern.slf4j.Slf4j;
1817
import org.springframework.beans.factory.annotation.Value;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.neighbors.tohero.application.mainPage.dto;
2+
3+
import com.neighbors.tohero.domain.domain.mainPage.model.Letter;
4+
import com.neighbors.tohero.domain.domain.notice.model.Notice;
5+
6+
import java.util.List;
7+
8+
public record GetMainPageInfoResponse(
9+
List<TopNotices> topNotices,
10+
long writtenLetterNumber,
11+
List<OpenedLetter> openedLetters
12+
) {
13+
public record TopNotices(
14+
String title
15+
){
16+
public static TopNotices from(Notice notice){
17+
return new TopNotices(notice.getNoticeTitle());
18+
}
19+
}
20+
21+
public record OpenedLetter(
22+
String to,
23+
String from,
24+
String content
25+
){
26+
public static OpenedLetter from(Letter letter){
27+
return new OpenedLetter(letter.getTargetName(), letter.getFromUserName(), letter.getLetterContent());
28+
}
29+
}
30+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.neighbors.tohero.application.mainPage.service;
2+
3+
import com.neighbors.tohero.application.baseResponse.BaseResponse;
4+
import com.neighbors.tohero.application.baseResponse.BaseResponseMessage;
5+
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
6+
import com.neighbors.tohero.application.mainPage.dto.GetMainPageInfoResponse;
7+
import com.neighbors.tohero.domain.domain.mainPage.model.Letter;
8+
import com.neighbors.tohero.domain.domain.mainPage.service.GetLetter;
9+
import com.neighbors.tohero.domain.domain.notice.model.Notice;
10+
import com.neighbors.tohero.domain.domain.notice.service.GetNotice;
11+
import lombok.RequiredArgsConstructor;
12+
import org.springframework.data.domain.Pageable;
13+
import org.springframework.stereotype.Service;
14+
15+
import java.util.List;
16+
17+
18+
@Service
19+
@RequiredArgsConstructor
20+
public class MainPageService {
21+
22+
private final GetNotice getNotice;
23+
private final GetLetter getLetter;
24+
25+
private static final int EXPOSED_NOTICE_NUMBER = 5;
26+
27+
public BaseResponse<GetMainPageInfoResponse> getMainPageInfo(Pageable pageable){
28+
List<GetMainPageInfoResponse.TopNotices> topNotices = getTopNoticeFromDomain();
29+
long writtenLetterNumber = getLetter.getTotalLetterNumber();
30+
List<GetMainPageInfoResponse.OpenedLetter> openedLetters = getLetterFromDomain(pageable);
31+
32+
return new BaseResponse(
33+
BaseResponseStatus.OK,
34+
BaseResponseMessage.메인페이지_조회가_정상적으로_실행되었습니다.getMessage(),
35+
new GetMainPageInfoResponse(topNotices, writtenLetterNumber, openedLetters)
36+
);
37+
}
38+
39+
private List<GetMainPageInfoResponse.TopNotices> getTopNoticeFromDomain(){
40+
List<Notice> topNotices = getNotice.getTopNotices(EXPOSED_NOTICE_NUMBER);
41+
42+
return topNotices.stream()
43+
.map(GetMainPageInfoResponse.TopNotices::from)
44+
.toList();
45+
}
46+
47+
private List<GetMainPageInfoResponse.OpenedLetter> getLetterFromDomain(Pageable pageable){
48+
List<Letter> openedLetters = getLetter.getPageableLetter(pageable);
49+
50+
return openedLetters.stream()
51+
.map(GetMainPageInfoResponse.OpenedLetter::from)
52+
.toList();
53+
}
54+
}

src/main/java/com/neighbors/tohero/application/notice/dto/GetNoticeResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.neighbors.tohero.application.notice.dto;
22

3-
import com.neighbors.tohero.domain.notice.model.Notice;
3+
import com.neighbors.tohero.domain.domain.notice.model.Notice;
44

55
import java.util.List;
66

src/main/java/com/neighbors/tohero/application/notice/service/NoticeService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.neighbors.tohero.application.baseResponse.BaseResponseMessage;
55
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
66
import com.neighbors.tohero.application.notice.dto.GetNoticeResponse;
7-
import com.neighbors.tohero.domain.notice.model.Notice;
8-
import com.neighbors.tohero.domain.notice.service.GetNotice;
7+
import com.neighbors.tohero.domain.domain.notice.model.Notice;
8+
import com.neighbors.tohero.domain.domain.notice.service.GetNotice;
99
import lombok.RequiredArgsConstructor;
1010
import org.springframework.data.domain.Pageable;
1111
import org.springframework.stereotype.Service;

src/main/java/com/neighbors/tohero/application/user/service/UserService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.neighbors.tohero.application.baseResponse.BaseResponse;
44
import com.neighbors.tohero.application.baseResponse.BaseResponseMessage;
55
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
6-
import com.neighbors.tohero.domain.user.service.UpdateUser;
6+
import com.neighbors.tohero.domain.domain.user.service.UpdateUser;
77
import lombok.RequiredArgsConstructor;
88
import org.springframework.stereotype.Service;
99

src/main/java/com/neighbors/tohero/common/config/SecurityConfig.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
import org.springframework.security.config.http.SessionCreationPolicy;
1616
import org.springframework.security.web.SecurityFilterChain;
1717
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
18+
import org.springframework.web.cors.CorsConfiguration;
19+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
20+
import org.springframework.web.filter.CorsFilter;
21+
22+
import java.util.List;
1823

1924
@Configuration
2025
@RequiredArgsConstructor
@@ -35,6 +40,7 @@ public WebSecurityCustomizer webSecurityCustomizer() {
3540
"/webjars/",
3641
"/v3/api-docs/**",
3742
"/oauth/kakao/callback",
43+
"/oauth/kakao/callback2",
3844
"/auth/refreshToken",
3945
"/address"
4046
);
@@ -61,4 +67,19 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
6167

6268
return http.build();
6369
}
70+
71+
@Bean
72+
public CorsFilter corsFilter() {
73+
CorsConfiguration config = new CorsConfiguration();
74+
config.setAllowCredentials(true); // 쿠키 포함 허용
75+
config.setAllowedOrigins(List.of("http://localhost:5173")); // 허용할 도메인
76+
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // 허용할 HTTP 메서드
77+
config.setAllowedHeaders(List.of("*")); // 모든 헤더 허용
78+
config.setExposedHeaders(List.of("Authorization")); // 노출할 헤더
79+
80+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
81+
source.registerCorsConfiguration("/**", config); // 모든 URL에 대해 설정 적용
82+
83+
return new CorsFilter(source);
84+
}
6485
}

src/main/java/com/neighbors/tohero/common/jwt/JwtUserDetails.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.neighbors.tohero.common.jwt;
22

33
import com.neighbors.tohero.common.enums.Role;
4-
import com.neighbors.tohero.domain.login.model.User;
4+
import com.neighbors.tohero.domain.domain.login.model.User;
55
import lombok.Builder;
66
import lombok.Getter;
77
import lombok.RequiredArgsConstructor;

src/main/java/com/neighbors/tohero/domain/login/model/User.java renamed to src/main/java/com/neighbors/tohero/domain/domain/login/model/User.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.neighbors.tohero.domain.login.model;
1+
package com.neighbors.tohero.domain.domain.login.model;
22

33
import com.neighbors.tohero.common.enums.Role;
44
import lombok.AllArgsConstructor;

0 commit comments

Comments
 (0)