Skip to content

Commit

Permalink
Merge branch 'develop' into feature/44
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsseonn authored Feb 16, 2024
2 parents 2c14f2c + 12e6beb commit 402d92b
Show file tree
Hide file tree
Showing 33 changed files with 2,059 additions and 222 deletions.
12 changes: 12 additions & 0 deletions src/docs/asciidoc/goal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ operation::goal-controller-test/현재_로그인한_사용자가_참여한_현
operation::goal-controller-test/현재_로그인한_사용자가_참여한_종료된_모든_골을_조회한다[snippets='http-request,request-headers']
==== 응답
operation::goal-controller-test/현재_로그인한_사용자가_참여한_종료된_모든_골을_조회한다[snippets='http-response,response-body,response-fields']

=== 골 삭제
==== 요청
operation::goal-controller-test/요청한_아이디의_골을_삭제한다[snippets='http-request,path-parameters,request-headers']
==== 응답
operation::goal-controller-test/요청한_아이디의_골을_삭제한다[snippets='http-response']

=== 골 수정
==== 요청
operation::goal-controller-test/요청한_내용으로_골을_수정한다[snippets='http-request,path-parameters,request-headers']
==== 응답
operation::goal-controller-test/요청한_내용으로_골을_수정한다[snippets='http-response,response-body,response-fields']
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class AuthenticationWebMvcConfiguration implements WebMvcConfigurer {
public void addInterceptors(final InterceptorRegistry registry) {
registry.addInterceptor(authenticationInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/admin/**");
.excludePathPatterns("/admin/**")
.excludePathPatterns("/auth/login/oauth/**", "/auth/reissue");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ public enum ExceptionMessage {
// 골
GOAL_NOT_FOUND("골 정보를 찾을 수 없습니다."),
GOAL_TEAM_NOT_FOUND("골 팀 정보를 찾을 수 없습니다."),
INVALID_GOAL_START_DAY("시작 날짜가 현재 날짜 이전입니다."),
INVALID_GOAL_END_DAY("종료 날짜가 현재 날짜 이전입니다."),
INVALID_GOAL_NAME("골 제목은 비어있거나 50자가 넘을 수 없습니다."),
INVALID_GOAL_START_DATE("시작 날짜가 현재 날짜 이전입니다."),
INVALID_GOAL_END_DATE("종료 날짜가 현재 날짜 이전입니다."),
INVALID_UPDATE_END_DATE("종료날짜는 기존 날짜보다 이전으로 수정 될 수 없습니다."),
INVALID_GOAL_PERIOD("시작 날짜가 종료 날짜 이후입니다."),
INVALID_GOAL_DAYS("골 날짜 수가 범위 밖입니다.(범위: 1~100)"),
INVALID_USERS_SIZE("골에 참여하는 친구가 5명 초과입니다."),
INVALID_USERS_SIZE("골 참여자 수가 범위 밖입니다.(범위: 1~5명)"),
INVALID_USER_TO_PARTICIPATE("골에 참여할 수 없는 사용자입니다. 골에는 친구인 사용자만 초대할 수 있습니다."),
DELETE_GOAL_FORBIDDEN("골을 삭제할 권한이 없습니다."),
UPDATE_GOAL_FORBIDDEN("골을 수정할 권한이 없습니다."),
UPDATE_TEAMS_FORBIDDEN("골 참여자 목록은 비어있을 수 없습니다."),

// 스탬프
INVALID_STAMP_DAY("스탬프 날짜는 골 시작일 이전이거나 종료일 이후일 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import com.backend.blooming.friend.application.exception.FriendAcceptanceForbiddenException;
import com.backend.blooming.friend.application.exception.FriendRequestNotAllowedException;
import com.backend.blooming.friend.application.exception.NotFoundFriendRequestException;
import com.backend.blooming.goal.application.exception.DeleteGoalForbiddenException;
import com.backend.blooming.goal.application.exception.InvalidGoalException;
import com.backend.blooming.goal.application.exception.NotFoundGoalException;
import com.backend.blooming.stamp.application.exception.CreateStampForbiddenException;
import com.backend.blooming.stamp.domain.exception.InvalidStampException;
import com.backend.blooming.goal.application.exception.UpdateGoalForbiddenException;
import com.backend.blooming.themecolor.domain.exception.UnsupportedThemeColorException;
import com.backend.blooming.user.application.exception.NotFoundUserException;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -48,7 +50,9 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
) {
logger.warn(String.format(LOG_MESSAGE_FORMAT, exception.getClass().getSimpleName(), exception.getMessage()));

final String message = exception.getFieldErrors().get(METHOD_ARGUMENT_FIRST_ERROR_INDEX).getDefaultMessage();
final String message = exception.getFieldErrors()
.get(METHOD_ARGUMENT_FIRST_ERROR_INDEX)
.getDefaultMessage();

return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new ExceptionResponse(message));
Expand Down Expand Up @@ -120,7 +124,7 @@ public ResponseEntity<ExceptionResponse> handleInvalidGoalException(
) {
logger.warn(String.format(LOG_MESSAGE_FORMAT, exception.getClass().getSimpleName(), exception.getMessage()));

return ResponseEntity.status(HttpStatus.FORBIDDEN)
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new ExceptionResponse(exception.getMessage()));
}

Expand Down Expand Up @@ -174,6 +178,26 @@ public ResponseEntity<ExceptionResponse> handleDeleteFriendForbiddenException(
.body(new ExceptionResponse(exception.getMessage()));
}

@ExceptionHandler(DeleteGoalForbiddenException.class)
public ResponseEntity<ExceptionResponse> handleDeleteGoalForbiddenException(
final DeleteGoalForbiddenException exception
) {
logger.warn(String.format(LOG_MESSAGE_FORMAT, exception.getClass().getSimpleName(), exception.getMessage()));

return ResponseEntity.status(HttpStatus.FORBIDDEN)
.body(new ExceptionResponse(exception.getMessage()));
}

@ExceptionHandler(UpdateGoalForbiddenException.class)
public ResponseEntity<ExceptionResponse> handleUpdateGoalForbiddenException(
final UpdateGoalForbiddenException exception
) {
logger.warn(String.format(LOG_MESSAGE_FORMAT, exception.getClass().getSimpleName(), exception.getMessage()));

return ResponseEntity.status(HttpStatus.FORBIDDEN)
.body(new ExceptionResponse(exception.getMessage()));
}

@ExceptionHandler(AlreadyRegisterBlackListTokenException.class)
public ResponseEntity<ExceptionResponse> handleAlreadyRegisterBlackListTokenException(
final AlreadyRegisterBlackListTokenException exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.backend.blooming.goal.application.dto.CreateGoalDto;
import com.backend.blooming.goal.application.dto.ReadAllGoalDto;
import com.backend.blooming.goal.application.dto.ReadGoalDetailDto;
import com.backend.blooming.goal.application.dto.UpdateGoalDto;
import com.backend.blooming.goal.application.exception.InvalidGoalException;
import com.backend.blooming.goal.application.exception.NotFoundGoalException;
import com.backend.blooming.goal.application.exception.UpdateGoalForbiddenException;
import com.backend.blooming.goal.domain.Goal;
import com.backend.blooming.goal.infrastructure.repository.GoalRepository;
import com.backend.blooming.user.application.exception.NotFoundUserException;
Expand All @@ -23,6 +25,8 @@
@RequiredArgsConstructor
public class GoalService {

private static final int TEAMS_MAXIMUM_LENGTH = 5;

private final GoalRepository goalRepository;
private final UserRepository userRepository;
private final FriendRepository friendRepository;
Expand All @@ -34,6 +38,10 @@ public Long createGoal(final CreateGoalDto createGoalDto) {
return goal.getId();
}

private List<User> getUsers(final List<Long> userIds) {
return userRepository.findAllByUserIds(userIds);
}

private Goal persistGoal(final CreateGoalDto createGoalDto, final List<User> users) {
final User user = getUser(createGoalDto.managerId());
validateIsFriend(user.getId(), createGoalDto.teamUserIds());
Expand All @@ -55,10 +63,6 @@ private User getUser(final Long userId) {
.orElseThrow(NotFoundUserException::new);
}

private List<User> getUsers(final List<Long> userIds) {
return userRepository.findAllByUserIds(userIds);
}

private void validateIsFriend(final Long userId, final List<Long> teamUserIds) {
final Long countFriends = friendRepository.countByUserIdAndFriendIdsAndIsFriends(userId, teamUserIds);

Expand All @@ -69,12 +73,16 @@ private void validateIsFriend(final Long userId, final List<Long> teamUserIds) {

@Transactional(readOnly = true)
public ReadGoalDetailDto readGoalDetailById(final Long goalId) {
final Goal goal = goalRepository.findByIdAndDeletedIsFalse(goalId)
.orElseThrow(NotFoundGoalException::new);
final Goal goal = getGoal(goalId);

return ReadGoalDetailDto.from(goal);
}

private Goal getGoal(final Long id) {
return goalRepository.findByIdAndDeletedIsFalse(id)
.orElseThrow(NotFoundGoalException::new);
}

@Transactional(readOnly = true)
public ReadAllGoalDto readAllGoalByUserIdAndInProgress(final Long userId, final LocalDate now) {
final List<Goal> goals = goalRepository.findAllByUserIdAndInProgress(userId, now);
Expand All @@ -88,4 +96,41 @@ public ReadAllGoalDto readAllGoalByUserIdAndFinished(final Long userId, final Lo

return ReadAllGoalDto.from(goals);
}

public ReadGoalDetailDto update(final Long userId, final Long goalId, final UpdateGoalDto updateGoalDto) {
final User user = getUser(userId);
final Goal goal = getGoal(goalId);
validateUserToUpdate(goal.getManagerId(), user.getId());
updateGoal(updateGoalDto, goal);

return ReadGoalDetailDto.from(goal);
}

private void validateUserToUpdate(final Long managerId, final Long userId) {
if (!managerId.equals(userId)) {
throw new UpdateGoalForbiddenException.ForbiddenUserToUpdate();
}
}

private void updateGoal(final UpdateGoalDto updateGoalDto, final Goal goal) {
if (updateGoalDto.name() != null) {
goal.updateName(updateGoalDto.name());
}
if (updateGoalDto.memo() != null) {
goal.updateMemo(updateGoalDto.memo());
}
if (updateGoalDto.endDate() != null) {
goal.updateEndDate(updateGoalDto.endDate());
}
if (updateGoalDto.teamUserIds() != null) {
final List<User> users = userRepository.findAllByUserIds(updateGoalDto.teamUserIds());
goal.updateTeams(users);
}
}

public void delete(final Long userId, final Long goalId) {
final User user = getUser(userId);
final Goal goal = getGoal(goalId);
goal.updateDeleted(user.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import java.util.List;

public record ReadAllGoalDto(List<GoalInfoDto> goalInfos) {

public static ReadAllGoalDto from(final List<Goal> goals) {
final List<GoalInfoDto> goalInfos = goals.stream()
.map(GoalInfoDto::from)
.toList();

return new ReadAllGoalDto(goalInfos);
}

public record GoalInfoDto(
Long id,
String name,
Expand All @@ -25,13 +25,14 @@ public record GoalInfoDto(
long days,
List<GoalTeamDto> teams
) {

public static GoalInfoDto from(final Goal goal) {
final List<GoalTeamDto> teams = goal.getTeams()
.getGoalTeams()
.stream()
.map(GoalTeamDto::from)
.toList();

return new GoalInfoDto(
goal.getId(),
goal.getName(),
Expand All @@ -41,9 +42,9 @@ public static GoalInfoDto from(final Goal goal) {
teams
);
}

public record GoalTeamDto(Long id, String name, ThemeColor color) {

public static GoalTeamDto from(final GoalTeam goalTeam) {
return new GoalTeamDto(
goalTeam.getUser().getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public record ReadGoalDetailDto(

public static ReadGoalDetailDto from(final Goal goal) {
final List<GoalTeamDto> teams = goal.getTeams()
.getGoalTeams()
.stream()
.map(GoalTeamDto::from)
.toList();
Expand All @@ -45,7 +46,7 @@ public record GoalTeamDto(

public static GoalTeamDto from(final GoalTeam goalTeam) {
return new GoalTeamDto(
goalTeam.getId(),
goalTeam.getUser().getId(),
goalTeam.getUser().getName(),
goalTeam.getUser().getColor(),
goalTeam.getUser().getStatusMessage()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.backend.blooming.goal.application.dto;

import com.backend.blooming.goal.presentation.dto.request.UpdateGoalRequest;

import java.time.LocalDate;
import java.util.List;

public record UpdateGoalDto(
String name,
String memo,
LocalDate endDate,
List<Long> teamUserIds
) {

public static UpdateGoalDto from(final UpdateGoalRequest request) {
return new UpdateGoalDto(
request.name(),
request.memo(),
request.endDate(),
request.teamUserIds()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.backend.blooming.goal.application.exception;

import com.backend.blooming.exception.BloomingException;
import com.backend.blooming.exception.ExceptionMessage;

public class DeleteGoalForbiddenException extends BloomingException {

public DeleteGoalForbiddenException() {
super(ExceptionMessage.DELETE_GOAL_FORBIDDEN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ private InvalidGoalException(final ExceptionMessage exceptionMessage) {
super(exceptionMessage);
}

public static class InvalidInvalidGoalStartDay extends InvalidGoalException {
public static class InvalidInvalidGoalStartDate extends InvalidGoalException {

public InvalidInvalidGoalStartDay() {
super(ExceptionMessage.INVALID_GOAL_START_DAY);
public InvalidInvalidGoalStartDate() {
super(ExceptionMessage.INVALID_GOAL_START_DATE);
}
}

public static class InvalidInvalidGoalEndDay extends InvalidGoalException {
public static class InvalidInvalidGoalEndDate extends InvalidGoalException {

public InvalidInvalidGoalEndDay() {
super(ExceptionMessage.INVALID_GOAL_END_DAY);
public InvalidInvalidGoalEndDate() {
super(ExceptionMessage.INVALID_GOAL_END_DATE);
}
}

Expand All @@ -40,7 +40,7 @@ public InvalidInvalidGoalDays() {
public static class InvalidInvalidUsersSize extends InvalidGoalException {

public InvalidInvalidUsersSize() {
super(ExceptionMessage.INVALID_GOAL_DAYS);
super(ExceptionMessage.INVALID_USERS_SIZE);
}
}

Expand All @@ -50,4 +50,18 @@ public InvalidInvalidUserToParticipate() {
super(ExceptionMessage.INVALID_USER_TO_PARTICIPATE);
}
}

public static class InvalidInvalidGoalName extends InvalidGoalException {

public InvalidInvalidGoalName() {
super(ExceptionMessage.INVALID_GOAL_NAME);
}
}

public static class InvalidInvalidUpdateEndDate extends InvalidGoalException {

public InvalidInvalidUpdateEndDate() {
super(ExceptionMessage.INVALID_UPDATE_END_DATE);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.backend.blooming.goal.application.exception;

import com.backend.blooming.exception.BloomingException;
import com.backend.blooming.exception.ExceptionMessage;

public class UpdateGoalForbiddenException extends BloomingException {

private UpdateGoalForbiddenException(final ExceptionMessage exceptionMessage) {
super(exceptionMessage);
}

public static class ForbiddenUserToUpdate extends UpdateGoalForbiddenException {

public ForbiddenUserToUpdate() {
super(ExceptionMessage.UPDATE_GOAL_FORBIDDEN);
}
}
}
Loading

0 comments on commit 402d92b

Please sign in to comment.