Skip to content

Commit

Permalink
YEL-192 [�deploy] notice path variable에 tag 추가 개발서버 배포
Browse files Browse the repository at this point in the history
YEL-192 [�deploy] notice path variable에 tag 추가 개발서버 배포
  • Loading branch information
hyeonjeongs authored Jan 29, 2024
2 parents c707b13 + db09386 commit ac861f2
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 42 deletions.
20 changes: 7 additions & 13 deletions src/docs/asciidoc/find-notice.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@

include::{snippets}/api/v1/notice/http-request.adoc[]

=== 요청 파라미터

include::{snippets}/api/v1/notice/path-parameters.adoc[]

=== 응답

include::{snippets}/api/v1/notice/http-response.adoc[]

*필드 타입*

- "imageUrl": String
* 공지로 보여줄 이미지 URL입니다.
- "redirectUrl: String
* 클릭시 이동할 웹 URL입니다.
- "startDate": String(10)
* YYYY-MM-DD (ISO-8601)
- "endDate": String(10)
* YYYY-MM-DD (ISO-8601)
- "isAvailable": Boolean
- "type" : String
* ENUM 값 -> "NOTICE" | "BANNER"
*path variable*

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

=== 주의

Expand Down Expand Up @@ -57,5 +50,6 @@ include::{snippets}/api/v1/notice/http-response.adoc[]

=== CHANGELOG

- 2024.01.29 API tag 추가 및 수정
- 2024.01.26 API 릴리즈
- 2024.01.09 명세 작성
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@


import com.yello.server.domain.notice.dto.NoticeDataResponse;
import com.yello.server.domain.notice.entity.NoticeType;
import com.yello.server.domain.notice.service.NoticeService;
import com.yello.server.domain.user.entity.User;
import com.yello.server.global.common.annotation.AccessTokenUser;
import com.yello.server.global.common.dto.BaseResponse;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -21,9 +23,9 @@ public class NoticeController {

private final NoticeService noticeService;

@GetMapping("/notice")
public BaseResponse<NoticeDataResponse> findNotice(@AccessTokenUser User user) {
val data = noticeService.findNotice(user.getId());
@GetMapping("/notice/{tag}")
public BaseResponse<NoticeDataResponse> findNotice(@AccessTokenUser User user, @PathVariable NoticeType tag) {
val data = noticeService.findNotice(user.getId(), tag);
return BaseResponse.success(READ_NOTICE_SUCCESS, data);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.yello.server.domain.notice.repository;

import com.yello.server.domain.notice.entity.Notice;
import com.yello.server.domain.notice.entity.NoticeType;

import java.util.Optional;

public interface NoticeRepository {

Optional<Notice> findTopNotice();
Optional<Notice> findTopNotice(NoticeType tag);
Notice save(Notice notice);

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.yello.server.domain.notice.repository;

import static com.yello.server.domain.notice.entity.QNotice.notice;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.yello.server.domain.notice.entity.Notice;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Optional;
import com.yello.server.domain.notice.entity.NoticeType;
import lombok.RequiredArgsConstructor;
import org.aspectj.weaver.ast.Not;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Optional;

import static com.yello.server.domain.notice.entity.QNotice.notice;

@Repository
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -21,16 +22,17 @@ public class NoticeRepositoryImpl implements NoticeRepository {
private final JPAQueryFactory jpaQueryFactory;

@Override
public Optional<Notice> findTopNotice() {
public Optional<Notice> findTopNotice(NoticeType tag) {
ZoneId zoneId = ZoneId.of("Asia/Seoul");
ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId);
return Optional.ofNullable(jpaQueryFactory
.selectFrom(notice)
.where(notice.isAvailable.eq(true)
.and(notice.startDate.loe(zonedDateTime))
.and(notice.endDate.goe(zonedDateTime)))
.orderBy(notice.endDate.desc())
.fetchFirst());
.selectFrom(notice)
.where(notice.isAvailable.eq(true)
.and(notice.startDate.loe(zonedDateTime))
.and(notice.endDate.goe(zonedDateTime))
.and(notice.tag.eq(tag)))
.orderBy(notice.endDate.desc())
.fetchFirst());
}

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

public NoticeDataResponse findNotice(Long userId) {
public NoticeDataResponse findNotice(Long userId, NoticeType tag) {
ZoneId zoneId = ZoneId.of("Asia/Seoul");
ZonedDateTime now = ZonedDateTime.now(zoneId);
userRepository.findById(userId);
Notice noticeData =
noticeRepository.findTopNotice().orElseGet(
() -> Notice.builder().imageUrl("").redirectUrl("").title("").tag(NoticeType.NOTICE).endDate(now)
noticeRepository.findTopNotice(tag).orElseGet(
() -> Notice.builder().imageUrl("").redirectUrl("").title("").tag(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,6 +1,7 @@
package com.yello.server.domain.notice;

import com.yello.server.domain.notice.entity.Notice;
import com.yello.server.domain.notice.entity.NoticeType;
import com.yello.server.domain.notice.repository.NoticeRepository;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand All @@ -15,15 +16,16 @@ public class FakeNoticeRepository implements NoticeRepository {
private Long id = 0L;

@Override
public Optional<Notice> findTopNotice() {
public Optional<Notice> findTopNotice(NoticeType tag) {
ZoneId zoneId = ZoneId.of("Asia/Seoul");
ZonedDateTime now = ZonedDateTime.now(zoneId);

return data.stream()
.filter(notice ->
notice.getIsAvailable().equals(true) &&
!notice.getStartDate().isAfter(now) &&
!notice.getEndDate().isBefore(now)
!notice.getEndDate().isBefore(now) &&
notice.getTag().equals(tag)
)
.sorted(Comparator.comparing(Notice::getEndDate).reversed())
.findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.removeHeaders;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -15,6 +18,7 @@
import com.yello.server.domain.notice.controller.NoticeController;
import com.yello.server.domain.notice.dto.NoticeDataResponse;
import com.yello.server.domain.notice.entity.Notice;
import com.yello.server.domain.notice.entity.NoticeType;
import com.yello.server.domain.notice.service.NoticeService;
import com.yello.server.domain.purchase.controller.PurchaseController;
import com.yello.server.domain.user.entity.User;
Expand Down Expand Up @@ -81,21 +85,22 @@ void init() {
void 공지_조회하기_검증에_성공합니다() throws Exception {
// given
final NoticeDataResponse noticeDataResponse = NoticeDataResponse.of(notice, true);

given(noticeService.findNotice(anyLong()))
NoticeType tag = NoticeType.NOTICE;
given(noticeService.findNotice(anyLong(), eq(tag)))
.willReturn(noticeDataResponse);

// when
// then
mockMvc.perform(RestDocumentationRequestBuilders
.get("/api/v1/notice")
.get("/api/v1/notice/{tag}", "NOTICE")
.header(HttpHeaders.AUTHORIZATION, "Bearer your-access-token"))
.andDo(print())
.andDo(document("api/v1/notice",
Preprocessors.preprocessRequest(prettyPrint(),
removeHeaders(excludeRequestHeaders)),
Preprocessors.preprocessResponse(prettyPrint(),
removeHeaders(excludeResponseHeaders)))
removeHeaders(excludeResponseHeaders)),
pathParameters(parameterWithName("tag").description("공지의 종류")))
)
.andExpect(MockMvcResultMatchers.status().isOk());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.yello.server.domain.notice.FakeNoticeRepository;
import com.yello.server.domain.notice.dto.NoticeDataResponse;
import com.yello.server.domain.notice.entity.Notice;
import com.yello.server.domain.notice.entity.NoticeType;
import com.yello.server.domain.notice.repository.NoticeRepository;
import com.yello.server.domain.notice.service.NoticeService;
import com.yello.server.domain.purchase.FakePurchaseRepository;
Expand Down Expand Up @@ -74,9 +75,10 @@ void init() {
void 공지_조회에_성공합니다() {
// given
final Long userId = 1L;
final NoticeType tag = NoticeType.NOTICE;

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

// then
assertThat(notice.isAvailable()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ void init() {
// given
final UserDeleteReasonRequest request =
UserDeleteReasonRequest.builder().value("오류가 많아서").build();
/*

doNothing()
.when(userService)
.deleteUserWithReason(anyLong(), request);*/
.deleteUserWithReason(anyLong(), eq(request));
// when
// then
mockMvc.perform(RestDocumentationRequestBuilders.delete("/api/v2/user")
Expand Down

0 comments on commit ac861f2

Please sign in to comment.