Skip to content

Commit

Permalink
YEL-207 [deploy] notice tag 추가
Browse files Browse the repository at this point in the history
YEL-207 [deploy] notice tag 추가
  • Loading branch information
hyeonjeongs authored Feb 2, 2024
2 parents 95eb114 + 4dbac33 commit e2bcbd2
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 33 deletions.
2 changes: 2 additions & 0 deletions src/docs/asciidoc/edit-user.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ include::{snippets}/api/v1/user/update/http-response.adoc[]
* 해당 정보 수정API는 도메인 별로 만들 예정입니다.
- 비즈니스 로직인 **'1년에 1회 수정 가능하다'**라는 조건과 상관없이 여러번 호출하여 유저 정보 수정이 가능합니다.
* 해당 비즈니스 로직을 만족하기 위해서 link:user-data-get.html[프로필 수정 가능 여부 조회]를 같이 사용해주세요.
** UserGroup(`groupId`, `groupAdmissionYear`)에 대한 정보가 유저의 기존 정보와 달라졌을때**만** `프로필 수정 가능 여부` 가 갱신됩니다.

=== CHANGELOG

- 2024.02.02 groupId, groupAdmissionYear 변경에 따른 제약조건 추가
- 2024.01.31 릴리즈
- 2024.01.09 명세 작성
6 changes: 5 additions & 1 deletion src/docs/asciidoc/find-notice.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ include::{snippets}/api/v1/notice/http-response.adoc[]

*path variable*

- tag(ENUM 값) -> "NOTICE" | "BANNER"
- tag(ENUM 값) -> "NOTICE" | "BANNER | "PROFILE-BANNER"

* NOTICE : 진입시 공지
* BANNER : 내 쪽지 배너
* PROFILE-BANNER : 프로필 배너

=== 주의

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class NoticeController {
private final NoticeService noticeService;

@GetMapping("/notice/{tag}")
public BaseResponse<NoticeDataResponse> findNotice(@AccessTokenUser User user, @PathVariable NoticeType tag) {
public BaseResponse<NoticeDataResponse> findNotice(@AccessTokenUser User user, @PathVariable String tag) {
val data = noticeService.findNotice(user.getId(), tag);
return BaseResponse.success(READ_NOTICE_SUCCESS, data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@RequiredArgsConstructor
public enum NoticeType {
NOTICE("NOTICE"),
BANNER("BANNER");
BANNER("BANNER"),
PROFILE_BANNER("PROFILE-BANNER");

private final String initial;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public class NoticeService {
private final NoticeRepository noticeRepository;
private final UserRepository userRepository;

public NoticeDataResponse findNotice(Long userId, NoticeType tag) {
public NoticeDataResponse findNotice(Long userId, String tag) {
ZoneId zoneId = ZoneId.of("Asia/Seoul");
ZonedDateTime now = ZonedDateTime.now(zoneId);
userRepository.findById(userId);
Notice noticeData =
noticeRepository.findTopNotice(tag).orElseGet(
() -> Notice.builder().imageUrl("").redirectUrl("").title("").tag(tag).endDate(now)
noticeRepository.findTopNotice(NoticeType.fromCode(tag)).orElseGet(
() -> Notice.builder().imageUrl("").redirectUrl("").title("").tag(
NoticeType.fromCode(tag)).endDate(now)
.startDate(now).isAvailable(false).build());
return NoticeDataResponse.of(noticeData,
compareNowAndEndData(noticeData.getEndDate()) && noticeData.getIsAvailable());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yello.server.domain.user.dto.request;

import com.yello.server.domain.user.entity.User;
import lombok.Builder;

@Builder
Expand All @@ -13,4 +14,8 @@ public record UserUpdateRequest(
Integer groupAdmissionYear
) {

public boolean groupInfoEquals(User user) {
return groupId.equals(user.getGroup().getId()) &&
groupAdmissionYear.equals(user.getGroupAdmissionYear());
}
}
26 changes: 14 additions & 12 deletions src/main/java/com/yello/server/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,22 @@ public void updateUserProfile(Long userId, UserUpdateRequest request) {
final Optional<UserData> userData = userDataRepository.findByUserIdAndTag(userId,
UserDataType.ACCOUNT_UPDATED_AT);

if (userData.isPresent()) {
userData.get().setValue(
ZonedDateTime.now(ConstantUtil.GlobalZoneId).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
);
} else {
userDataRepository.save(UserData.of(
ACCOUNT_UPDATED_AT,
ZonedDateTime.now(ConstantUtil.GlobalZoneId).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
user
));
}

// logic
user.update(request, gender, userGroup);

if (!request.groupInfoEquals(user)) {
if (userData.isPresent()) {
userData.get().setValue(
ZonedDateTime.now(ConstantUtil.GlobalZoneId).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
);
} else {
userDataRepository.save(UserData.of(
ACCOUNT_UPDATED_AT,
ZonedDateTime.now(ConstantUtil.GlobalZoneId).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
user
));
}
}
}

public UserDataResponse readUserData(Long userId, UserDataType tag) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/resources/static/docs/edit-user.html
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ <h2 id="_유저_프로필_수정">유저 프로필 수정</h2>
<h3 id="_요청">요청</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">DELETE /api/v1/user HTTP/1.1
<pre class="highlight nowrap"><code class="language-http" data-lang="http">POST /api/v1/user HTTP/1.1
Content-Type: application/json;charset=UTF-8
Authorization: Bearer your-access-token
Content-Length: 195
Expand Down Expand Up @@ -521,7 +521,7 @@ <h3 id="_응답">응답</h3>

{
"status" : 200,
"message" : "유저 탈퇴에 성공했습니다."
"message" : "유저 상세 정보 수정에 성공하였습니다."
}</code></pre>
</div>
</div>
Expand Down Expand Up @@ -549,6 +549,13 @@ <h3 id="_note">NOTE</h3>
<ul>
<li>
<p>해당 비즈니스 로직을 만족하기 위해서 <a href="user-data-get.html">프로필 수정 가능 여부 조회</a>를 같이 사용해주세요.</p>
<div class="ulist">
<ul>
<li>
<p>UserGroup(<code>groupId</code>, <code>groupAdmissionYear</code>)에 대한 정보가 유저의 기존 정보와 달라졌을때<strong></strong> <code>프로필 수정 가능 여부</code> 가 갱신됩니다.</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
Expand All @@ -561,6 +568,9 @@ <h3 id="_changelog">CHANGELOG</h3>
<div class="ulist">
<ul>
<li>
<p>2024.02.02 groupId, groupAdmissionYear 변경에 따른 제약조건 추가</p>
</li>
<li>
<p>2024.01.31 릴리즈</p>
</li>
<li>
Expand Down
15 changes: 14 additions & 1 deletion src/main/resources/static/docs/find-notice.html
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,20 @@ <h3 id="_응답">응답</h3>
<div class="ulist">
<ul>
<li>
<p>tag(ENUM 값) &#8594; "NOTICE" | "BANNER"</p>
<p>tag(ENUM 값) &#8594; "NOTICE" | "BANNER | "PROFILE-BANNER"</p>
<div class="ulist">
<ul>
<li>
<p>NOTICE : 진입시 공지</p>
</li>
<li>
<p>BANNER : 내 쪽지 배너</p>
</li>
<li>
<p>PROFILE-BANNER : 프로필 배너</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/purchase-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ <h3 id="_응답">응답</h3>
"data" : {
"id" : 1,
"subscribe" : "normal",
"expiredDate" : "2024-02-07"
"expiredDate" : "2024-01-08"
}
}</code></pre>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void init() {
// given
final NoticeDataResponse noticeDataResponse = NoticeDataResponse.of(notice, false);
NoticeType tag = NoticeType.NOTICE;
given(noticeService.findNotice(anyLong(), eq(tag)))
given(noticeService.findNotice(anyLong(), String.valueOf(eq(tag.getInitial()))))
.willReturn(noticeDataResponse);

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ void init() {
final ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Seoul"));

// when
final NoticeDataResponse noticeResponse = noticeService.findNotice(userId, tag);
final NoticeDataResponse noticeResponse = noticeService.findNotice(userId,
tag.getInitial());

// then
assertThat(noticeResponse.isAvailable()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.yello.server.util.TestDataEntityUtil;
import com.yello.server.util.TestDataUtil;
import com.yello.server.util.WithAccessTokenUser;
import java.time.LocalDateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
Expand Down Expand Up @@ -234,9 +235,9 @@ void init() {
@Test
void 유저_구독_정보_조회에_성공합니다() throws Exception {
// given

LocalDateTime now = LocalDateTime.of(2024, 1, 1, 0, 0, 0);
UserSubscribeDetailResponse userSubscribeDetailResponse =
UserSubscribeDetailResponse.of(testDataUtil.generatePurchase(1L, user));
UserSubscribeDetailResponse.of(testDataUtil.generatePurchase(1L, user, now));
// when
given(userService.getUserSubscribe(anyLong()))
.willReturn(userSubscribeDetailResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ void init() {
.userDataRepository(userDataRepository)
.build();

LocalDateTime now = LocalDateTime.of(2024, 1, 1, 0, 0, 0);
final UserGroup userGroup = testDataUtil.generateGroup(1L, UserGroupType.UNIVERSITY);
final UserGroup userGroup2 = testDataUtil.generateGroup(2L, UserGroupType.UNIVERSITY);
for (int i = 1; i <= 2; i++) {
final User user = testDataUtil.generateUser(i, userGroup);
user.setSubscribe(Subscribe.ACTIVE);
}
final User user = userRepository.getById(1L);
testDataUtil.generatePurchase(1L, user);
testDataUtil.generatePurchase(1L, user, now);
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/yello/server/util/TestDataEntityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public QuestionGroupType generateQuestionGroupType(long index, Question question
}

@Override
public Purchase generatePurchase(long index, User user) {
public Purchase generatePurchase(long index, User user, LocalDateTime createdAt) {
return Purchase.builder()
.id(index)
.gateway(Gateway.APPLE)
Expand All @@ -109,8 +109,8 @@ public Purchase generatePurchase(long index, User user) {
.user(user)
.transactionId("111")
.state(PurchaseState.ACTIVE)
.createdAt(LocalDateTime.now())
.updatedAt(LocalDateTime.now())
.createdAt(createdAt)
.updatedAt(createdAt)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.yello.server.domain.user.repository.UserRepository;
import com.yello.server.domain.vote.entity.Vote;
import com.yello.server.domain.vote.repository.VoteRepository;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;

public class TestDataRepositoryUtil implements TestDataUtil {
Expand Down Expand Up @@ -87,8 +88,8 @@ public QuestionGroupType generateQuestionGroupType(long index, Question question
}

@Override
public Purchase generatePurchase(long index, User user) {
return purchaseRepository.save(testDataEntityUtil.generatePurchase(index, user));
public Purchase generatePurchase(long index, User user, LocalDateTime createdAt) {
return purchaseRepository.save(testDataEntityUtil.generatePurchase(index, user, createdAt));
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/yello/server/util/TestDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.yello.server.domain.question.entity.QuestionGroupType;
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.vote.entity.Vote;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;

public interface TestDataUtil {
Expand All @@ -28,7 +29,7 @@ public interface TestDataUtil {

QuestionGroupType generateQuestionGroupType(long index, Question question);

Purchase generatePurchase(long index, User user);
Purchase generatePurchase(long index, User user, LocalDateTime createdAt);

Notice generateNotice(long index, NoticeType noticeType, ZonedDateTime createdAt);
}
Expand Down

0 comments on commit e2bcbd2

Please sign in to comment.