Skip to content

Commit

Permalink
Merge branch 'main' into fix/group_pray_sort
Browse files Browse the repository at this point in the history
  • Loading branch information
baebae02 authored Apr 26, 2024
2 parents e19885e + 3bf9b02 commit 3ec6165
Show file tree
Hide file tree
Showing 25 changed files with 66 additions and 129 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/uspray/uspray/domain/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public void kickMember(GroupMember groupMember) {

public void validateGroupName(String newName) {
if (this.name.equals(newName)) {
throw new CustomException(ErrorStatus.ALREADY_EXIST_GROUP_NAME_EXCEPTION,
ErrorStatus.ALREADY_EXIST_GROUP_NAME_EXCEPTION.getMessage());
throw new CustomException(ErrorStatus.ALREADY_EXIST_GROUP_NAME_EXCEPTION);
}
}

Expand All @@ -75,8 +74,7 @@ public void checkLeaderAuthorization(Member member) {
System.out.println(leader.getUserId());
System.out.println(member.getUserId());
if (!leader.equals(member)) {
throw new CustomException(ErrorStatus.GROUP_UNAUTHORIZED_EXCEPTION,
ErrorStatus.GROUP_UNAUTHORIZED_EXCEPTION.getMessage());
throw new CustomException(ErrorStatus.GROUP_UNAUTHORIZED_EXCEPTION);
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/uspray/uspray/domain/Pray.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public void update(PrayUpdateRequestDto prayUpdateRequestDto,

private void handleUpdateContentSharedPray(boolean isShared, String content) {
if (isShared && content != null) {
throw new NotFoundException(ErrorStatus.ALREADY_SHARED_EXCEPTION,
ErrorStatus.ALREADY_SHARED_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.ALREADY_SHARED_EXCEPTION);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/uspray/uspray/exception/ErrorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum ErrorStatus {
CANNOT_RECEIVE_SHARED_PRAY_EXCEPTION(HttpStatus.BAD_REQUEST,
"이미 보관함에 있는 기도제목이거나 공유받을 수 없는 기도제목입니다."),
ALREADY_EXIST_PHONE_EXCEPTION(HttpStatus.BAD_REQUEST, "이미 사용중인 핸드폰 번호입니다."),
NO_CATEGORY_EXCEPTION(HttpStatus.BAD_REQUEST, "카테고리가 존재하지 않습니다."),

/*
* 401 UNAUTHORIZED
Expand All @@ -44,10 +45,11 @@ public enum ErrorStatus {
* 403 FORBIDDEN
*/
PRAY_UNAUTHORIZED_EXCEPTION(HttpStatus.FORBIDDEN, "해당 기도제목에 대한 권한이 없습니다."),
SHARE_NOT_AUTHORIZED_EXCEPTION(HttpStatus.UNAUTHORIZED, "기도제목을 공유할 권한이 없습니다."),
DELETE_NOT_AUTHORIZED_EXCEPTION(HttpStatus.UNAUTHORIZED, "기도제목을 삭제할 권한이 없습니다."),
CATEGORY_UNAUTHORIZED_EXCEPTION(HttpStatus.UNAUTHORIZED, "해당 카테고리에 대한 권한이 없습니다."),
GROUP_UNAUTHORIZED_EXCEPTION(HttpStatus.UNAUTHORIZED, "해당 모임에 대한 권한이 없습니다."),
SHARE_NOT_AUTHORIZED_EXCEPTION(HttpStatus.FORBIDDEN, "기도제목을 공유할 권한이 없습니다."),
DELETE_NOT_AUTHORIZED_EXCEPTION(HttpStatus.FORBIDDEN, "기도제목을 삭제할 권한이 없습니다."),
CATEGORY_UNAUTHORIZED_EXCEPTION(HttpStatus.FORBIDDEN, "해당 카테고리에 대한 권한이 없습니다."),
GROUP_UNAUTHORIZED_EXCEPTION(HttpStatus.FORBIDDEN, "해당 모임에 대한 권한이 없습니다."),
HISTORY_MISS_MATCH_EXCEPTION(HttpStatus.FORBIDDEN, "해당 히스토리에 대한 접근 권한이 없습니다."),

/**
* 404 NOT FOUND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
public class CustomException extends RuntimeException{
private final ErrorStatus errorStatus;

public CustomException(ErrorStatus errorStatus, String message) {
super(message);
public CustomException(ErrorStatus errorStatus) {
super(errorStatus.getMessage());
this.errorStatus = errorStatus;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.uspray.uspray.exception.ErrorStatus;
public class NotFoundException extends CustomException{

public NotFoundException(ErrorStatus errorStatus,
String message) {
super(errorStatus, message);
public NotFoundException(ErrorStatus errorStatus) {
super(errorStatus);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,19 @@ default Category getCategoryByIdAndMember(Long categoryId, Member member) {
Category category = findById(categoryId)
.filter(c -> c.getMember().equals(member))
.orElseThrow(() -> new NotFoundException(
ErrorStatus.CATEGORY_NOT_FOUND_EXCEPTION,
ErrorStatus.CATEGORY_NOT_FOUND_EXCEPTION.getMessage()
ErrorStatus.CATEGORY_NOT_FOUND_EXCEPTION
));

if (!category.getCategoryType().equals(CategoryType.PERSONAL)) {
throw new CustomException(ErrorStatus.PRAY_CATEGORY_TYPE_MISMATCH,
ErrorStatus.PRAY_CATEGORY_TYPE_MISMATCH.getMessage());
throw new CustomException(ErrorStatus.PRAY_CATEGORY_TYPE_MISMATCH);
}

return category;
}

default void checkDuplicate(String name, Member member, CategoryType type) {
if (existsByNameAndMemberAndCategoryType(name, member, type)) {
throw new NotFoundException(ErrorStatus.CATEGORY_DUPLICATE_EXCEPTION,
ErrorStatus.CATEGORY_DUPLICATE_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.CATEGORY_DUPLICATE_EXCEPTION);
}
}

Expand All @@ -59,8 +56,7 @@ default int checkDuplicateAndReturnMaxOrder(String name, Member member, Category
default int getMaxCategoryOrder(Member member, CategoryType type) {
Category category = getCategoriesByMemberAndCategoryTypeOrderByOrder(member, type).stream()
.reduce((first, second) -> second)
.orElseThrow(() -> new NotFoundException(ErrorStatus.CATEGORY_NOT_FOUND_EXCEPTION,
ErrorStatus.CATEGORY_NOT_FOUND_EXCEPTION.getMessage()));
.orElseThrow(() -> new NotFoundException(ErrorStatus.CATEGORY_NOT_FOUND_EXCEPTION));
return category.getOrder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ public interface GroupMemberRepository extends JpaRepository<GroupMember, Long>

default GroupMember getGroupMemberByGroupAndMember(Group group, Member member) {
return this.findByGroupAndMember(group, member).orElseThrow(
() -> new NotFoundException(ErrorStatus.NOT_FOUND_GROUP_MEMBER_EXCEPTION,
ErrorStatus.NOT_FOUND_GROUP_MEMBER_EXCEPTION.getMessage()));
() -> new NotFoundException(ErrorStatus.NOT_FOUND_GROUP_MEMBER_EXCEPTION));
}

default GroupMember getGroupMemberByGroupIdAndMemberId(Long groupId, Long memberId) {
return this.findByGroupIdAndMemberId(groupId, memberId).orElseThrow(
() -> new NotFoundException(ErrorStatus.NOT_FOUND_GROUP_MEMBER_EXCEPTION,
ErrorStatus.NOT_FOUND_GROUP_MEMBER_EXCEPTION.getMessage()));
() -> new NotFoundException(ErrorStatus.NOT_FOUND_GROUP_MEMBER_EXCEPTION));
}

GroupMember findGroupMemberByMemberAndGroupId(Member member, Long groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public interface GroupPrayRepository extends JpaRepository<GroupPray, Long> {

default GroupPray getGroupPrayById(Long id) {
return this.findById(id).orElseThrow(
() -> new NotFoundException(ErrorStatus.NOT_FOUND_GROUP_PRAY_EXCEPTION,
ErrorStatus.NOT_FOUND_GROUP_PRAY_EXCEPTION.getMessage()));
() -> new NotFoundException(ErrorStatus.NOT_FOUND_GROUP_PRAY_EXCEPTION));
}

default void deleteAllByGroup(Group group) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public interface GroupRepository extends JpaRepository<Group, Long>, GroupReposi

default Group getGroupById(Long id) {
return this.findById(id).orElseThrow(
() -> new NotFoundException(ErrorStatus.NOT_FOUND_GROUP_EXCEPTION,
ErrorStatus.NOT_FOUND_GROUP_EXCEPTION.getMessage()));
() -> new NotFoundException(ErrorStatus.NOT_FOUND_GROUP_EXCEPTION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ public interface HistoryRepository extends JpaRepository<History, Long>, History

default History getHistoryByIdAndMember(Long historyId, Member member) {
return findByIdAndMember(historyId, member)
.orElseThrow(() -> new NotFoundException(ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION,
ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION.getMessage()));
.orElseThrow(() -> new NotFoundException(ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION));
}

default History getHistoryById(Long historyId) {
return findById(historyId)
.orElseThrow(() -> new NotFoundException(
ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION,
ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION.getMessage()
ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

default Member getMemberByUserId(String userId) {
return this.findByUserId(userId).orElseThrow(
() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION,
ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));
() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION));
}

default Member getMemberById(Long id) {
return this.findById(id).orElseThrow(
() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION,
ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));
() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ public interface PrayRepository extends JpaRepository<Pray, Long>, PrayRepositor

default Pray getPrayById(Long id) {
return findById(id).orElseThrow(
() -> new NotFoundException(ErrorStatus.PRAY_NOT_FOUND_EXCEPTION,
ErrorStatus.PRAY_NOT_FOUND_EXCEPTION.getMessage()));
() -> new NotFoundException(ErrorStatus.PRAY_NOT_FOUND_EXCEPTION));
}

@EntityGraph(attributePaths = {"groupPray"})
default Pray getPrayByIdAndMemberId(Long prayId, String username) throws NotFoundException {
return findById(prayId)
.filter(pray -> pray.getMember().getUserId().equals(username))
.orElseThrow(() -> new NotFoundException(
ErrorStatus.PRAY_NOT_FOUND_EXCEPTION,
ErrorStatus.PRAY_NOT_FOUND_EXCEPTION.getMessage()
ErrorStatus.PRAY_NOT_FOUND_EXCEPTION
));
}

Expand All @@ -47,8 +45,7 @@ default Pray getPrayByIdAndMemberId(Long prayId, String username) throws NotFoun
default Pray cancelPray(Long prayId, String username) {
Pray pray = getPrayByIdAndMemberId(prayId, username);
if (!Objects.equals(pray.getLastPrayedAt(), LocalDate.now())) {
throw new NotFoundException(ErrorStatus.ALREADY_CANCEL_EXCEPTION,
ErrorStatus.ALREADY_CANCEL_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.ALREADY_CANCEL_EXCEPTION);
}
pray.deleteLastPrayedAt();
return pray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import com.uspray.uspray.domain.Member;
import com.uspray.uspray.domain.Pray;
import com.uspray.uspray.domain.SharedPray;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

import com.uspray.uspray.exception.ErrorStatus;
import com.uspray.uspray.exception.model.NotFoundException;
import java.time.LocalDate;
import java.util.List;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -26,7 +24,6 @@ public interface SharedPrayRepository extends JpaRepository<SharedPray, Long> {

default SharedPray getSharedPrayById(Long id) {
return this.findById(id).orElseThrow(
() -> new NotFoundException(ErrorStatus.NOT_FOUND_SHARED_PRAY_EXCEPTION,
ErrorStatus.NOT_FOUND_SHARED_PRAY_EXCEPTION.getMessage()));
() -> new NotFoundException(ErrorStatus.NOT_FOUND_SHARED_PRAY_EXCEPTION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.uspray.uspray.domain.Category;
import com.uspray.uspray.domain.Member;
import com.uspray.uspray.domain.Pray;
import com.uspray.uspray.exception.ErrorStatus;
import com.uspray.uspray.exception.model.CustomException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -34,6 +36,10 @@ public List<PrayListResponseDto> findAllWithOrderAndType(String username, String
.orderBy(category.order.asc())
.fetch();

if (categories.size() == 0) {
throw new CustomException(ErrorStatus.NO_CATEGORY_EXCEPTION);
}

// 각 카테고리 별로 PrayResponseDto 목록 가져오기
List<PrayListResponseDto> prayListResponseDtos = new ArrayList<>();
for (Category cat : categories) {
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/com/uspray/uspray/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ public MemberResponseDto signup(MemberRequestDto memberRequestDto) {
// 핸드폰번호가 존재하거나 아이디가 존재하면 에러
// 핸드폰 번호 또는 아이디가 이미 존재하는지 확인
if (memberRepository.existsByUserId(memberRequestDto.getUserId())) {
throw new NotFoundException(ErrorStatus.ALREADY_EXIST_ID_EXCEPTION,
ErrorStatus.ALREADY_EXIST_ID_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.ALREADY_EXIST_ID_EXCEPTION);
}
if (memberRepository.existsByPhone(memberRequestDto.getPhone())) {
throw new NotFoundException(ErrorStatus.ALREADY_EXIST_PHONE_EXCEPTION,
ErrorStatus.ALREADY_EXIST_PHONE_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.ALREADY_EXIST_PHONE_EXCEPTION);
}

Member member = memberRequestDto.toMember(passwordEncoder);
Expand Down Expand Up @@ -83,20 +81,17 @@ public TokenDto login(MemberLoginRequestDto memberLoginRequestDto) {

return tokenDto;
} catch (AuthenticationException e) {
throw new NotFoundException(ErrorStatus.WRONG_LOGIN_INFO_EXCEPTION,
ErrorStatus.WRONG_LOGIN_INFO_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.WRONG_LOGIN_INFO_EXCEPTION);
} catch (Exception e) {
throw new CustomException(ErrorStatus.INTERNAL_SERVER_ERROR,
ErrorStatus.INTERNAL_SERVER_ERROR.getMessage());
throw new CustomException(ErrorStatus.INTERNAL_SERVER_ERROR);
}
}

@Transactional
public TokenDto reissue(String refreshToken) {
// 1. Refresh Token 검증
if (!tokenProvider.validateToken(refreshToken)) {
throw new NotFoundException(ErrorStatus.REFRESH_TOKEN_NOT_VALID_EXCEPTION,
ErrorStatus.REFRESH_TOKEN_NOT_VALID_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.REFRESH_TOKEN_NOT_VALID_EXCEPTION);
}

// 2. Access Token 에서 Member ID 가져오기
Expand All @@ -108,8 +103,7 @@ public TokenDto reissue(String refreshToken) {

// 4. Refresh Token 일치하는지 검사
if (!refreshToken.equals(refreshTokenValue)) {
throw new NotFoundException(ErrorStatus.REFRESH_TOKEN_NOT_VALID_EXCEPTION,
ErrorStatus.REFRESH_TOKEN_NOT_VALID_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.REFRESH_TOKEN_NOT_VALID_EXCEPTION);
}

// 5. 새로운 토큰 생성
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/uspray/uspray/service/CategoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ private static int getNewOrder(int index, List<Category> categories, Category ca

private static void validateIndex(int index, int size) {
if (index < 1 || index > size) {
throw new NotFoundException(ErrorStatus.INDEX_OUT_OF_BOUND_EXCEPTION,
ErrorStatus.INDEX_OUT_OF_BOUND_EXCEPTION.getMessage());
throw new NotFoundException(ErrorStatus.INDEX_OUT_OF_BOUND_EXCEPTION);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/uspray/uspray/service/HistoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public HistoryListResponseDto getHistoryList(String username, String type, int p
return new HistoryListResponseDto(historyList.getContent(),
historyList.getTotalPages());
}
throw new CustomException(ErrorStatus.INVALID_TYPE_EXCEPTION,
ErrorStatus.INVALID_TYPE_EXCEPTION.getMessage());
throw new CustomException(ErrorStatus.INVALID_TYPE_EXCEPTION);
}

@Transactional(readOnly = true)
Expand All @@ -73,9 +72,8 @@ public HistoryListResponseDto searchHistoryList(String username,
public HistoryDetailResponseDto getHistoryDetail(String username, Long historyId) {
Member member = memberRepository.getMemberByUserId(username);
History history = historyRepository.getHistoryById(historyId);
if (!history.getMember().equals(member)) {
throw new NotFoundException(ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION,
ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION.getMessage());
if (!history.getMember().getId().equals(member.getId())) {
throw new NotFoundException(ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION);
}
if (history.getPrayType().equals(PrayType.SHARED)) {
Pray originPray = prayRepository.getPrayById(history.getOriginPrayId());
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/uspray/uspray/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class MemberService {
@Transactional
public void changePhone(String userId, String phone) {
if (memberRepository.existsByPhone(phone)) {
throw new CustomException(ErrorStatus.ALREADY_EXIST_PHONE_EXCEPTION,
ErrorStatus.ALREADY_EXIST_PHONE_EXCEPTION.getMessage());
throw new CustomException(ErrorStatus.ALREADY_EXIST_PHONE_EXCEPTION);
}
memberRepository.getMemberByUserId(userId).changePhone(phone);
}
Expand All @@ -46,17 +45,16 @@ public void changeNotificationAgree(String userId, NotificationAgreeDto notifica
public void changeName(OauthNameDto oauthNameDto) {
Member member = memberRepository.findBySocialId(oauthNameDto.getId())
.orElseThrow(() -> new NotFoundException(
ErrorStatus.NOT_FOUND_USER_EXCEPTION,
ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));
ErrorStatus.NOT_FOUND_USER_EXCEPTION)
);
member.changeName(oauthNameDto.getName());
member.changeAuthority(Authority.ROLE_USER);
}

public Boolean checkPw(String userId, CheckPwDTO checkPwDto) {
Member member = memberRepository.getMemberByUserId(userId);
if (!passwordEncoder.matches(checkPwDto.getPassword(), member.getPassword())) {
throw new CustomException(ErrorStatus.NOT_FOUND_USER_EXCEPTION,
ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage());
throw new CustomException(ErrorStatus.NOT_FOUND_USER_EXCEPTION);
}
return true;
}
Expand Down
Loading

0 comments on commit 3ec6165

Please sign in to comment.