diff --git a/src/main/java/com/goormdari/domain/routine/application/RoutineService.java b/src/main/java/com/goormdari/domain/routine/application/RoutineService.java index 1241257..f00b383 100644 --- a/src/main/java/com/goormdari/domain/routine/application/RoutineService.java +++ b/src/main/java/com/goormdari/domain/routine/application/RoutineService.java @@ -6,6 +6,7 @@ import com.goormdari.domain.routine.domain.repository.RoutineRepository; import com.goormdari.domain.user.domain.User; import com.goormdari.domain.user.domain.repository.UserRepository; +import com.goormdari.global.config.s3.S3Service; import com.goormdari.global.payload.Message; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -18,9 +19,8 @@ @Transactional(readOnly = true) public class RoutineService { - final RoutineRepository routineRepository; - final UserRepository userRepository; - + private final RoutineRepository routineRepository; + private final UserRepository userRepository; @Transactional public Message completeRoutine (Long userId, CompleteRoutineRequest completeRoutineRequest, String imgURL) { User user = userRepository.findById(userId) diff --git a/src/main/java/com/goormdari/domain/team/application/TeamService.java b/src/main/java/com/goormdari/domain/team/application/TeamService.java index 75ea096..f3c8ad7 100644 --- a/src/main/java/com/goormdari/domain/team/application/TeamService.java +++ b/src/main/java/com/goormdari/domain/team/application/TeamService.java @@ -5,6 +5,7 @@ import com.goormdari.domain.team.domain.repository.TeamRepository; import com.goormdari.domain.team.dto.request.CreateTeamRequest; import com.goormdari.domain.team.dto.response.CreateTeamResponse; +import com.goormdari.domain.team.dto.response.findAllRoutineByUserIdResponse; import com.goormdari.domain.team.exception.TeamAlreadyExistException; import com.goormdari.domain.user.domain.User; import com.goormdari.domain.user.domain.repository.UserRepository; @@ -26,6 +27,20 @@ public class TeamService { private final EmailClient emailClient; + @Transactional + public findAllRoutineByUserIdResponse findAllRoutineByUserId(Long userId) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new NotFoundException("User not found")); + + Team team = teamRepository.findById(user.getTeam().getId()) + .orElseThrow(() -> new NotFoundException("Team not found")); + return findAllRoutineByUserIdResponse.builder() + .routine1(team.getRoutine1()) + .routine2(team.getRoutine2()) + .routine3(team.getRoutine3()) + .routine4(team.getRoutine4()) + .build(); + } @Transactional public CreateTeamResponse createNewTeam(final String username, final CreateTeamRequest createTeamRequest) { diff --git a/src/main/java/com/goormdari/domain/team/domain/Team.java b/src/main/java/com/goormdari/domain/team/domain/Team.java index 7d5b39f..4c2cc94 100644 --- a/src/main/java/com/goormdari/domain/team/domain/Team.java +++ b/src/main/java/com/goormdari/domain/team/domain/Team.java @@ -1,10 +1,13 @@ package com.goormdari.domain.team.domain; import com.goormdari.domain.common.BaseEntity; +import com.goormdari.domain.user.domain.User; import jakarta.persistence.*; import lombok.*; import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; @Entity @@ -31,7 +34,6 @@ public class Team extends BaseEntity { private String joinCode; - @Builder public Team(String name, String goal, LocalDate deadLine, String routine1, String routine2, String routine3, String routine4, String joinCode) { this.name = name; diff --git a/src/main/java/com/goormdari/domain/team/dto/response/findAllRoutineByUserIdResponse.java b/src/main/java/com/goormdari/domain/team/dto/response/findAllRoutineByUserIdResponse.java new file mode 100644 index 0000000..060eb2f --- /dev/null +++ b/src/main/java/com/goormdari/domain/team/dto/response/findAllRoutineByUserIdResponse.java @@ -0,0 +1,7 @@ +package com.goormdari.domain.team.dto.response; + +import lombok.Builder; + +@Builder +public record findAllRoutineByUserIdResponse(String routine1, String routine2, String routine3, String routine4) { +} diff --git a/src/main/java/com/goormdari/domain/team/presentation/TeamController.java b/src/main/java/com/goormdari/domain/team/presentation/TeamController.java index e1d1553..dc0e067 100644 --- a/src/main/java/com/goormdari/domain/team/presentation/TeamController.java +++ b/src/main/java/com/goormdari/domain/team/presentation/TeamController.java @@ -1,8 +1,10 @@ package com.goormdari.domain.team.presentation; +import com.goormdari.domain.calendar.exception.InvalidTokenException; import com.goormdari.domain.team.application.TeamService; import com.goormdari.domain.team.dto.request.CreateTeamRequest; import com.goormdari.domain.team.dto.response.CreateTeamResponse; +import com.goormdari.domain.team.dto.response.findAllRoutineByUserIdResponse; import com.goormdari.global.config.security.jwt.JWTUtil; import com.goormdari.global.payload.ErrorResponse; import com.goormdari.global.payload.Message; @@ -81,4 +83,26 @@ public ResponseCustom joinTeam( String username = jwtUtil.extractUsername(jwt); return ResponseCustom.OK(teamService.join(username, joinCode)); } + + @Operation(summary = "루틴 목록 조회", description = "teamId로 설정된 루틴 목록 조회") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "루틴 목록 조회 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = CreateTeamResponse.class))}), + @ApiResponse(responseCode = "400", description = "루틴 목록 조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), + }) + @GetMapping("/routine-list") + public ResponseCustom getRoutineList( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @RequestHeader("Authorization") String token + ) { + if (token == null) { + throw new InvalidTokenException(); + } + + String jwt = token.startsWith("Bearer ") ? token.substring(7) : token; + if (!jwtUtil.validateToken(jwt)) { + throw new IllegalArgumentException("Invalid token"); + } + Long userId = jwtUtil.extractId(jwt); + return ResponseCustom.OK(teamService.findAllRoutineByUserId(userId)); + } + } diff --git a/src/main/java/com/goormdari/domain/user/domain/dto/response/findByTeamIdResponse.java b/src/main/java/com/goormdari/domain/user/domain/dto/response/findByTeamIdResponse.java index 8deffd6..1cdc41d 100644 --- a/src/main/java/com/goormdari/domain/user/domain/dto/response/findByTeamIdResponse.java +++ b/src/main/java/com/goormdari/domain/user/domain/dto/response/findByTeamIdResponse.java @@ -2,6 +2,8 @@ import lombok.Builder; +import java.time.LocalDateTime; + @Builder public record findByTeamIdResponse(Long id, String username) { } diff --git a/src/main/java/com/goormdari/domain/user/domain/service/UserService.java b/src/main/java/com/goormdari/domain/user/domain/service/UserService.java index f9f0ea0..d3a26e9 100644 --- a/src/main/java/com/goormdari/domain/user/domain/service/UserService.java +++ b/src/main/java/com/goormdari/domain/user/domain/service/UserService.java @@ -1,6 +1,8 @@ package com.goormdari.domain.user.domain.service; import com.amazonaws.services.kms.model.NotFoundException; +import com.goormdari.domain.team.domain.Team; +import com.goormdari.domain.team.domain.repository.TeamRepository; import com.goormdari.domain.user.domain.dto.response.findByTeamIdResponse; import com.goormdari.domain.user.domain.dto.response.findCurrentStepResponse; import com.goormdari.domain.user.domain.User; @@ -21,6 +23,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Slf4j @@ -31,6 +34,7 @@ public class UserService { private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; private final AuthenticationManager authenticationManager; + private final TeamRepository teamRepository; private final JWTUtil jwtUtil; @Transactional @@ -53,7 +57,6 @@ public List findTeamByUserId(Long userId) { .build()) .collect(Collectors.toList()); } - @Transactional public Long save(AddUserRequest dto) { // 사용자 이름 중복 체크