Skip to content

Commit de61075

Browse files
authored
Merge pull request #17 from Neighbors-dev/develop
[FEAT] 탈퇴하기 API 및 소식 모아보기 API 구현
2 parents 56987f2 + 8aa0899 commit de61075

34 files changed

+482
-13
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public enum BaseResponseMessage {
2525
이메일_형식이_올바르지_못합니다("이메일 형식이 올바르지 못합니다"),
2626
유저가_성공적으로_인증되었습니다("유저가 성공적으로 인증되었습니다"),
2727
GUEST_유저_토큰이_정상적으로_생성되었습니다("GUEST 유저 토큰이 정상적으로 생성되었습니다"),
28+
로그아웃이_성공적으로_실행되었습니다("로그아웃이 성공적으로 실행되었습니다"),
29+
성공적으로_탈퇴했습니다("성공적으로 탈퇴했습니다"),
2830

2931
//jwt error message
3032
JWT_토큰_오류입니다("JWT 토큰 오류입니다"),
@@ -43,7 +45,13 @@ public enum BaseResponseMessage {
4345

4446
//letter
4547
편지가_성공적으로_생성_되었습니다("편지가 성공적으로 생성 되었습니다"),
46-
편지_생성이_실패_했습니다("편지 생성이 실패했습니다");
48+
편지_생성이_실패_했습니다("편지 생성이 실패했습니다"),
49+
편지가_성공적으로_조회되었습니다("편지가 성공적으로 조회되었습니다"),
50+
일치하는_편지가_없습니다("일치하는 편지가 없습니다"),
51+
52+
//news
53+
뉴스_조회가_성공했습니다("뉴스 조회가 성공했습니다"),
54+
뉴스_조회가_실패했습니다("뉴스 조회가 실패했습니다");
4755

4856
private final String message;
4957

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.neighbors.tohero.application.letter.dto;
2+
3+
import jakarta.validation.constraints.NotNull;
4+
5+
public record GetLetterDetailRequest(
6+
@NotNull
7+
long letterId
8+
) {
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.neighbors.tohero.application.letter.dto;
2+
3+
import com.neighbors.tohero.domain.domain.mainPage.model.Letter;
4+
5+
public record GetLetterDetailResponse(
6+
LetterInfo letterInfo
7+
) {
8+
public record LetterInfo(
9+
long letterId,
10+
String content,
11+
String from,
12+
String to
13+
){}
14+
15+
public static GetLetterDetailResponse from(Letter letter) {
16+
return new GetLetterDetailResponse(new LetterInfo(letter.getLetterId(), letter.getLetterContent(), letter.getWriter(), letter.getTargetName()));
17+
}
18+
}

src/main/java/com/neighbors/tohero/application/letter/service/LetterService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
66
import com.neighbors.tohero.application.letter.dto.CreateLetterRequest;
77
import com.neighbors.tohero.application.letter.dto.CreateLetterResponse;
8+
import com.neighbors.tohero.application.letter.dto.GetLetterDetailRequest;
9+
import com.neighbors.tohero.application.letter.dto.GetLetterDetailResponse;
810
import com.neighbors.tohero.common.enums.Role;
911
import com.neighbors.tohero.common.exception.address.AddressException;
1012
import com.neighbors.tohero.common.exception.letter.LetterException;
1113
import com.neighbors.tohero.common.jwt.JwtUserDetails;
1214
import com.neighbors.tohero.domain.domain.address.service.GetAddress;
1315
import com.neighbors.tohero.domain.domain.letter.service.CreateLetter;
16+
import com.neighbors.tohero.domain.domain.mainPage.model.Letter;
17+
import com.neighbors.tohero.domain.domain.mainPage.service.GetLetter;
1418
import lombok.RequiredArgsConstructor;
1519
import org.springframework.stereotype.Service;
1620

@@ -22,6 +26,7 @@
2226
public class LetterService {
2327

2428
private final CreateLetter createLetter;
29+
private final GetLetter getLetter;
2530
private final GetAddress getAddress;
2631

2732
public BaseResponse<CreateLetterResponse> createLetter(final JwtUserDetails jwtUserDetail, final CreateLetterRequest createLetterRequest) {
@@ -46,6 +51,16 @@ public BaseResponse<CreateLetterResponse> createLetter(final JwtUserDetails jwtU
4651
);
4752
}
4853

54+
public BaseResponse<GetLetterDetailResponse> getLetterDetail(GetLetterDetailRequest getLetterDetailRequest){
55+
Letter matchedLetter = getLetter.getLetterById(getLetterDetailRequest.letterId());
56+
57+
return new BaseResponse<>(
58+
BaseResponseStatus.OK,
59+
BaseResponseMessage.편지가_성공적으로_조회되었습니다.getMessage(),
60+
GetLetterDetailResponse.from(matchedLetter)
61+
);
62+
}
63+
4964
private BaseResponse<CreateLetterResponse> createGuestLetter(final String nickname, final CreateLetterRequest createLetterRequest) {
5065
long createdLetterId = createLetter.createGuestLetter(
5166
nickname,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.neighbors.tohero.application.news.dto;
2+
3+
import com.neighbors.tohero.domain.domain.news.model.News;
4+
5+
import java.util.List;
6+
7+
public record GetPagedNewsResponse(
8+
List<NewsInfo> newsInfos
9+
) {
10+
public record NewsInfo(
11+
long newsId,
12+
String title,
13+
String content
14+
){
15+
public static NewsInfo from(News news){
16+
return new NewsInfo(news.getNewsId(), news.getTitle(), news.getContent());
17+
}
18+
}
19+
20+
public static GetPagedNewsResponse from(List<News> newsInfos) {
21+
List<NewsInfo> newsInfoList = newsInfos.stream()
22+
.map(NewsInfo::from)
23+
.toList();
24+
return new GetPagedNewsResponse(newsInfoList);
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.neighbors.tohero.application.news.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.news.dto.GetPagedNewsResponse;
7+
import com.neighbors.tohero.domain.domain.news.model.News;
8+
import com.neighbors.tohero.domain.domain.news.service.GetNews;
9+
import lombok.RequiredArgsConstructor;
10+
import org.springframework.data.domain.Pageable;
11+
import org.springframework.stereotype.Service;
12+
13+
import java.util.List;
14+
15+
@Service
16+
@RequiredArgsConstructor
17+
public class NewsService {
18+
19+
private final GetNews getNews;
20+
21+
public BaseResponse<GetPagedNewsResponse> getPagedNews(Pageable pageable){
22+
List<News> news = getNews.getPagedNews(pageable);
23+
24+
return new BaseResponse<>(
25+
BaseResponseStatus.OK,
26+
BaseResponseMessage.뉴스_조회가_성공했습니다.getMessage(),
27+
GetPagedNewsResponse.from(news)
28+
);
29+
}
30+
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import com.neighbors.tohero.common.jwt.JwtUserDetails;
1212
import com.neighbors.tohero.domain.domain.user.model.User;
1313
import com.neighbors.tohero.domain.domain.user.service.CreateUser;
14+
import com.neighbors.tohero.domain.domain.user.service.DeleteUser;
1415
import com.neighbors.tohero.domain.domain.user.service.UpdateUser;
16+
import jakarta.servlet.http.HttpSession;
1517
import lombok.RequiredArgsConstructor;
1618
import org.springframework.stereotype.Service;
1719

@@ -21,6 +23,7 @@ public class UserService {
2123

2224
private final UpdateUser updateUser;
2325
private final CreateUser createUser;
26+
private final DeleteUser deleteUser;
2427
private final JwtProvider jwtProvider;
2528

2629
public BaseResponse updateUserName(long userId, String nickname){
@@ -39,6 +42,26 @@ public BaseResponse<AuthenticateUserResponse> authenticateUser(AuthenticateUserR
3942
return returnGuestUserToken(authenticateUserRequest);
4043
}
4144

45+
public BaseResponse logout(HttpSession httpSession){
46+
//todo : Redis record 삭제
47+
httpSession.invalidate();
48+
return new BaseResponse<>(
49+
BaseResponseStatus.OK,
50+
BaseResponseMessage.로그아웃이_성공적으로_실행되었습니다.getMessage()
51+
);
52+
}
53+
54+
public BaseResponse signout(JwtUserDetails jwtUserDetails, HttpSession httpSession){
55+
httpSession.invalidate();
56+
57+
deleteUser.signout(jwtUserDetails.getUserId());
58+
59+
return new BaseResponse<>(
60+
BaseResponseStatus.OK,
61+
BaseResponseMessage.성공적으로_탈퇴했습니다.getMessage()
62+
);
63+
}
64+
4265
private BaseResponse<AuthenticateUserResponse> returnLoginedUserToken(AuthenticateUserRequest authenticateUserRequest) {
4366
User createdUser = createUser.createUser(User.toEntity(authenticateUserRequest));
4467
AuthTokens authTokens = jwtProvider.createToken(JwtUserDetails.from(createdUser));

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public WebSecurityCustomizer webSecurityCustomizer() {
4646
"/auth/refreshToken",
4747
"/address",
4848
"/notice/**",
49-
"/mainPage/**"
49+
"/mainPage/**",
50+
"/letter/detail",
51+
"/news"
5052
);
5153
}
5254

@@ -64,7 +66,10 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
6466
{
6567
exception.authenticationEntryPoint(customJwtAuthenticationEntryPoint);
6668
exception.accessDeniedHandler(customAccessDeniedHandler);
67-
});
69+
})
70+
.authorizeHttpRequests(auth -> auth
71+
.anyRequest().authenticated()
72+
);
6873

6974
return http.build();
7075
}

src/main/java/com/neighbors/tohero/common/exception/address/AddressException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.neighbors.tohero.common.exception.address;
22

33
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
4+
import lombok.Getter;
45

6+
@Getter
57
public class AddressException extends RuntimeException{
68
private final BaseResponseStatus status;
79
private final String message;

src/main/java/com/neighbors/tohero/common/exception/letter/LetterException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.neighbors.tohero.common.exception.letter;
22

33
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
4+
import lombok.Getter;
45

6+
@Getter
57
public class LetterException extends RuntimeException {
68

79
private final BaseResponseStatus status;

0 commit comments

Comments
 (0)