Skip to content

Commit 3566b43

Browse files
authored
Merge pull request #163 from prgrms-aibe-devcourse/fix/162-profile-created-at-response
[Bug] 프로필 가입일이 표시되지 않음
2 parents 24f7208 + 6ef8a42 commit 3566b43

6 files changed

Lines changed: 41 additions & 6 deletions

File tree

src/main/java/com/Rootin/domain/ai/service/AiService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class AiService {
4444
/**
4545
* TIL 요약 요청
4646
* [tilIds 없음] 기존 로직: 화분 소유 검증 -> 화분 내 전체 PUBLISHED TIL 사용 (하위 호환)
47-
* [tilIds 있음] 선택 로직: tilIds로 TIL 조회 -> 소유 검증(403) -> 빈 결과(404)
47+
* [tilIds 있음] 선택 로직: tilIds로 TIL 조회 -> 소유 검증(400) -> 빈 결과(404)
4848
* 공통: 포인트 확인(402) -> 합산 -> OpenAI -> 포인트 차감 + PointLog
4949
*/
5050
@Transactional
@@ -95,7 +95,7 @@ public AiSummaryResponse summarize(AiSummaryRequest request, Long userId) {
9595
/**
9696
* 복습 문제 생성 요청
9797
* [tilIds 없음] 기존 로직: 화분 소유 검증 -> 화분 내 전체 PUBLISHED TIL 사용 (하위 호환)
98-
* [tilIds 있음] 선택 로직: tilIds로 TIL 조회 -> 소유 검증(403) -> 빈 결과(404)
98+
* [tilIds 있음] 선택 로직: tilIds로 TIL 조회 -> 소유 검증(400) -> 빈 결과(404)
9999
* 공통: 포인트 확인(402) -> 합산 -> OpenAI -> 포인트 차감 + PointLog
100100
*/
101101
@Transactional

src/main/java/com/Rootin/domain/til/repository/TilRepository.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,4 @@ Page<Til> findByFilters(
6767
List<PotTilCountProjection> countByPotIdInAndStatus(@Param("potIds") List<Long> potIds, @Param("status") PostStatus status);
6868

6969
long countByUserIdAndStatus(Long userId, PostStatus status);
70-
71-
long countByUserIdAndStatusAndPublishedAtBetween(Long userId, PostStatus status, LocalDateTime from, LocalDateTime to);
7270
}

src/main/java/com/Rootin/domain/user/dto/UserMeResponse.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.Rootin.domain.user.dto;
22

33
import com.Rootin.domain.user.entity.User;
4+
import com.fasterxml.jackson.annotation.JsonFormat;
45
import lombok.Builder;
56
import lombok.Getter;
67

8+
import java.time.LocalDateTime;
9+
710
// 로그인한 유저 정보 응답 DTO
811
// API: [GET] /api/v1/users/me, [PATCH] /api/v1/users/me
912
@Getter
@@ -18,6 +21,8 @@ public class UserMeResponse {
1821
private int point;
1922
private String provider;
2023
private long tilCount;
24+
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
25+
private LocalDateTime createdAt;
2126

2227
public static UserMeResponse of(User user, long tilCount) {
2328
return UserMeResponse.builder()
@@ -29,6 +34,7 @@ public static UserMeResponse of(User user, long tilCount) {
2934
.point(user.getPoint())
3035
.provider(user.getProvider() != null ? user.getProvider().name() : null)
3136
.tilCount(tilCount)
37+
.createdAt(user.getCreatedAt())
3238
.build();
3339
}
3440
}

src/main/resources/application.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
spring:
22
application:
33
name: Rootin
4-
54
cors:
65
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:3000,http://localhost:5173}
76

src/test/java/com/Rootin/domain/user/controller/UserControllerTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import org.springframework.test.context.ActiveProfiles;
2121
import org.springframework.test.web.servlet.MockMvc;
2222

23+
import java.time.LocalDateTime;
2324
import java.util.List;
25+
import org.springframework.test.util.ReflectionTestUtils;
2426

2527
import static org.mockito.ArgumentMatchers.any;
2628
import static org.mockito.ArgumentMatchers.anyString;
@@ -67,6 +69,9 @@ void getMe_success() throws Exception {
6769
.provider(Provider.LOCAL)
6870
.build();
6971

72+
LocalDateTime fixedCreatedAt = LocalDateTime.of(2025, 1, 15, 10, 30, 0);
73+
ReflectionTestUtils.setField(mockUser, "createdAt", fixedCreatedAt);
74+
7075
JwtUserDetails jwtUserDetails = new JwtUserDetails(
7176
1L, "test@rootin.com",
7277
List.of(new SimpleGrantedAuthority("ROLE_USER")));
@@ -84,7 +89,9 @@ void getMe_success() throws Exception {
8489
.andExpect(jsonPath("$.data.profileImageUrl").value("https://cdn.rootin.com/profile/1.jpg"))
8590
.andExpect(jsonPath("$.data.point").value(100))
8691
.andExpect(jsonPath("$.data.provider").value("LOCAL"))
87-
.andExpect(jsonPath("$.data.tilCount").value(7));
92+
.andExpect(jsonPath("$.data.tilCount").value(7))
93+
.andExpect(jsonPath("$.data.createdAt").isString())
94+
.andExpect(jsonPath("$.data.createdAt").value("2025-01-15T10:30:00"));
8895
}
8996

9097
@Test

src/test/java/com/Rootin/domain/user/service/UserServiceTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.springframework.security.crypto.password.PasswordEncoder;
2121
import org.springframework.test.util.ReflectionTestUtils;
2222

23+
import java.time.LocalDateTime;
2324
import java.util.Optional;
2425

2526
import static org.assertj.core.api.Assertions.assertThat;
@@ -108,6 +109,30 @@ void getUserMe_success() {
108109
assertThat(response.getPoint()).isEqualTo(100);
109110
}
110111

112+
@Test
113+
@DisplayName("내 정보 조회 성공 — createdAt 포함 반환")
114+
void getUserMe_createdAt_included() {
115+
// given
116+
User user = User.builder()
117+
.email("test@rootin.com")
118+
.nickname("루틴이")
119+
.role(Role.USER)
120+
.provider(Provider.LOCAL)
121+
.build();
122+
123+
LocalDateTime expectedCreatedAt = LocalDateTime.of(2025, 1, 1, 0, 0);
124+
ReflectionTestUtils.setField(user, "createdAt", expectedCreatedAt);
125+
126+
given(userRepository.findById(1L)).willReturn(Optional.of(user));
127+
given(tilRepository.countByUserIdAndStatus(1L, PostStatus.PUBLISHED)).willReturn(0L);
128+
129+
// when
130+
UserMeResponse response = userService.getUserMe(1L);
131+
132+
// then
133+
assertThat(response.getCreatedAt()).isEqualTo(expectedCreatedAt);
134+
}
135+
111136
@Test
112137
@DisplayName("내 정보 조회 — 존재하지 않는 userId → CustomException(404)")
113138
void getUserMe_userNotFound() {

0 commit comments

Comments
 (0)