Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public enum BaseResponseMessage {
이메일_형식이_올바르지_못합니다("이메일 형식이 올바르지 못합니다"),
유저가_성공적으로_인증되었습니다("유저가 성공적으로 인증되었습니다"),
GUEST_유저_토큰이_정상적으로_생성되었습니다("GUEST 유저 토큰이 정상적으로 생성되었습니다"),
로그아웃이_성공적으로_실행되었습니다("로그아웃이 성공적으로 실행되었습니다"),
성공적으로_탈퇴했습니다("성공적으로 탈퇴했습니다"),

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

//letter
편지가_성공적으로_생성_되었습니다("편지가 성공적으로 생성 되었습니다"),
편지_생성이_실패_했습니다("편지 생성이 실패했습니다");
편지_생성이_실패_했습니다("편지 생성이 실패했습니다"),
편지가_성공적으로_조회되었습니다("편지가 성공적으로 조회되었습니다"),
일치하는_편지가_없습니다("일치하는 편지가 없습니다"),

//news
뉴스_조회가_성공했습니다("뉴스 조회가 성공했습니다"),
뉴스_조회가_실패했습니다("뉴스 조회가 실패했습니다");

private final String message;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.neighbors.tohero.application.letter.dto;

import jakarta.validation.constraints.NotNull;

public record GetLetterDetailRequest(
@NotNull
long letterId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.neighbors.tohero.application.letter.dto;

import com.neighbors.tohero.domain.domain.mainPage.model.Letter;

public record GetLetterDetailResponse(
LetterInfo letterInfo
) {
public record LetterInfo(
long letterId,
String content,
String from,
String to
){}

public static GetLetterDetailResponse from(Letter letter) {
return new GetLetterDetailResponse(new LetterInfo(letter.getLetterId(), letter.getLetterContent(), letter.getWriter(), letter.getTargetName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import com.neighbors.tohero.application.letter.dto.CreateLetterRequest;
import com.neighbors.tohero.application.letter.dto.CreateLetterResponse;
import com.neighbors.tohero.application.letter.dto.GetLetterDetailRequest;
import com.neighbors.tohero.application.letter.dto.GetLetterDetailResponse;
import com.neighbors.tohero.common.enums.Role;
import com.neighbors.tohero.common.exception.address.AddressException;
import com.neighbors.tohero.common.exception.letter.LetterException;
import com.neighbors.tohero.common.jwt.JwtUserDetails;
import com.neighbors.tohero.domain.domain.address.service.GetAddress;
import com.neighbors.tohero.domain.domain.letter.service.CreateLetter;
import com.neighbors.tohero.domain.domain.mainPage.model.Letter;
import com.neighbors.tohero.domain.domain.mainPage.service.GetLetter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -22,6 +26,7 @@
public class LetterService {

private final CreateLetter createLetter;
private final GetLetter getLetter;
private final GetAddress getAddress;

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

public BaseResponse<GetLetterDetailResponse> getLetterDetail(GetLetterDetailRequest getLetterDetailRequest){
Letter matchedLetter = getLetter.getLetterById(getLetterDetailRequest.letterId());

return new BaseResponse<>(
BaseResponseStatus.OK,
BaseResponseMessage.편지가_성공적으로_조회되었습니다.getMessage(),
GetLetterDetailResponse.from(matchedLetter)
);
}

private BaseResponse<CreateLetterResponse> createGuestLetter(final String nickname, final CreateLetterRequest createLetterRequest) {
long createdLetterId = createLetter.createGuestLetter(
nickname,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.neighbors.tohero.application.news.dto;

import com.neighbors.tohero.domain.domain.news.model.News;

import java.util.List;

public record GetPagedNewsResponse(
List<NewsInfo> newsInfos
) {
public record NewsInfo(
long newsId,
String title,
String content
){
public static NewsInfo from(News news){
return new NewsInfo(news.getNewsId(), news.getTitle(), news.getContent());
}
}

public static GetPagedNewsResponse from(List<News> newsInfos) {
List<NewsInfo> newsInfoList = newsInfos.stream()
.map(NewsInfo::from)
.toList();
return new GetPagedNewsResponse(newsInfoList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.neighbors.tohero.application.news.service;

import com.neighbors.tohero.application.baseResponse.BaseResponse;
import com.neighbors.tohero.application.baseResponse.BaseResponseMessage;
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import com.neighbors.tohero.application.news.dto.GetPagedNewsResponse;
import com.neighbors.tohero.domain.domain.news.model.News;
import com.neighbors.tohero.domain.domain.news.service.GetNews;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class NewsService {

private final GetNews getNews;

public BaseResponse<GetPagedNewsResponse> getPagedNews(Pageable pageable){
List<News> news = getNews.getPagedNews(pageable);

return new BaseResponse<>(
BaseResponseStatus.OK,
BaseResponseMessage.뉴스_조회가_성공했습니다.getMessage(),
GetPagedNewsResponse.from(news)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import com.neighbors.tohero.common.jwt.JwtUserDetails;
import com.neighbors.tohero.domain.domain.user.model.User;
import com.neighbors.tohero.domain.domain.user.service.CreateUser;
import com.neighbors.tohero.domain.domain.user.service.DeleteUser;
import com.neighbors.tohero.domain.domain.user.service.UpdateUser;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

private final UpdateUser updateUser;
private final CreateUser createUser;
private final DeleteUser deleteUser;
private final JwtProvider jwtProvider;

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

public BaseResponse logout(HttpSession httpSession){
//todo : Redis record 삭제
httpSession.invalidate();
return new BaseResponse<>(
BaseResponseStatus.OK,
BaseResponseMessage.로그아웃이_성공적으로_실행되었습니다.getMessage()
);
}

public BaseResponse signout(JwtUserDetails jwtUserDetails, HttpSession httpSession){
httpSession.invalidate();

deleteUser.signout(jwtUserDetails.getUserId());

return new BaseResponse<>(
BaseResponseStatus.OK,
BaseResponseMessage.성공적으로_탈퇴했습니다.getMessage()
);
}

private BaseResponse<AuthenticateUserResponse> returnLoginedUserToken(AuthenticateUserRequest authenticateUserRequest) {
User createdUser = createUser.createUser(User.toEntity(authenticateUserRequest));
AuthTokens authTokens = jwtProvider.createToken(JwtUserDetails.from(createdUser));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public WebSecurityCustomizer webSecurityCustomizer() {
"/auth/refreshToken",
"/address",
"/notice/**",
"/mainPage/**"
"/mainPage/**",
"/letter/detail",
"/news"
);
}

Expand All @@ -64,7 +66,10 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
{
exception.authenticationEntryPoint(customJwtAuthenticationEntryPoint);
exception.accessDeniedHandler(customAccessDeniedHandler);
});
})
.authorizeHttpRequests(auth -> auth
.anyRequest().authenticated()
);

return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.neighbors.tohero.common.exception.address;

import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import lombok.Getter;

@Getter
public class AddressException extends RuntimeException{
private final BaseResponseStatus status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.neighbors.tohero.common.exception.letter;

import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import lombok.Getter;

@Getter
public class LetterException extends RuntimeException {

private final BaseResponseStatus status;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.neighbors.tohero.common.exception.news;

import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import lombok.Getter;

@Getter
public class NewsException extends RuntimeException {

private final BaseResponseStatus status;
private final String message;

public NewsException(BaseResponseStatus status, String message) {
super(message);
this.status = status;
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.neighbors.tohero.common.exception.notice;

import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import lombok.Getter;

@Getter
public class NoticeException extends RuntimeException {

private final BaseResponseStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public long getTotalLetterNumber(){
public List<Letter> getPageableLetter(Pageable pageable){
return letterRepository.getPageableLetter(pageable);
}

public Letter getLetterById(long letterId){
return letterRepository.getLetter(repo -> repo.findByIdAndPublic(letterId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.neighbors.tohero.domain.domain.news.model;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class News {
private long newsId;
private String title;
private String content;

public static News of(long newsId, String title, String content) {
return new News(newsId, title, content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.neighbors.tohero.domain.domain.news.service;

import com.neighbors.tohero.common.annotaion.DomainService;
import com.neighbors.tohero.domain.domain.news.model.News;
import com.neighbors.tohero.domain.query.NewsRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;

import java.util.List;

@DomainService
@RequiredArgsConstructor
public class GetNews {

private final NewsRepository newsRepository;

public List<News> getPagedNews(Pageable pageable){
return newsRepository.getNewsList(repo -> repo.findAllByPagable(pageable));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.neighbors.tohero.domain.domain.user.service;

import com.neighbors.tohero.common.annotaion.DomainService;
import com.neighbors.tohero.domain.query.LetterRepository;
import com.neighbors.tohero.domain.query.UserRepository;
import lombok.RequiredArgsConstructor;

@DomainService
@RequiredArgsConstructor
public class DeleteUser {

private final UserRepository userRepository;
private final LetterRepository letterRepository;

public void signout(long userId){
letterRepository.remainLetterWithoutUser(userId);
userRepository.deleteUser(repo -> repo.deleteById(userId));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.neighbors.tohero.domain.query;

import com.neighbors.tohero.domain.domain.mainPage.model.Letter;
import com.neighbors.tohero.infrastructure.entity.LetterEntity;
import com.neighbors.tohero.infrastructure.repository.LetterEntityRepository;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

public interface LetterRepository {
long getTotalLetterNumber();
List<Letter> getPageableLetter(Pageable pageable);
Letter createLetter(Letter letter);
void remainLetterWithoutUser(long userId);
Letter getLetter(Function<LetterEntityRepository, Optional<LetterEntity>> function);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.neighbors.tohero.domain.query;

import com.neighbors.tohero.domain.domain.news.model.News;
import com.neighbors.tohero.infrastructure.entity.NewsEntity;
import com.neighbors.tohero.infrastructure.repository.NewsEntityRepository;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

public interface NewsRepository {
public List<News> getNewsList(Function<NewsEntityRepository, Optional<List<NewsEntity>>> function);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.neighbors.tohero.infrastructure.repository.UserEntityRepository;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

public interface UserRepository {
User createUser(User user);
User updateUserName(Function<UserEntityRepository, Optional<UserEntity>> findUserFunction, String nickname);
User getUser(Function<UserEntityRepository, Optional<UserEntity>> findUserFunction);
void deleteUser(Consumer<UserEntityRepository> findUserConsumer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public class LetterEntity extends BaseEntity {

@Column(name = "reading_alarm")
private Boolean readingAlarm;

public void remainLetterWithoutUser(){
this.user = null;
this.isPublic = false;
}
}
Loading
Loading