Skip to content

Commit

Permalink
YEL-185 [feat] 공지 조회하기 개발서버 배포
Browse files Browse the repository at this point in the history
YEL-185 [feat] 공지 조회하기 개발서버 배포
  • Loading branch information
hyeonjeongs authored Jan 28, 2024
2 parents 3370f8d + 7fc4149 commit edd401b
Show file tree
Hide file tree
Showing 39 changed files with 1,384 additions and 109 deletions.
98 changes: 98 additions & 0 deletions src/docs/asciidoc/find-friend-votes-v2.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
:reproducible:
== 친구 투표 전체 조회 (명세)

=== 요청

[http]

----
GET /v2/vote/friend?page={}&type={} HTTP/1.1
Authorization: Bearer your-access-token
Content-Type: application-json
----

*업데이트 예정*
- "type": "send" | null

|===
|`+type+`| 조회할 쪽지 종류 (null -> 모든쪽지, send-> 보낸쪽지)
|===

=== 응답

[http, json]
----
{
"status" : 200,
"message" : "투표 조회에 성공했습니다.",
"data" : {
"totalCount" : 1,
"friendVotes" : [ {
"id" : 1,
"senderId" : 1,
"senderName" : "name1",
"senderGender" : "MALE",
"senderYelloId" : "MALE",
"senderProfileImage": "imageUrl",
"receiverId" : 2,
"receiverName" : "name2",
"receiverGender" : "MALE",
"receiverYelloId" : "MALE",
"receiverProfileImage" : "test image",
"vote" : {
"nameHead" : "나는",
"nameFoot" : "와",
"keywordHead" : "멋진",
"keyword" : "test",
"keywordFoot" : "에서 놀고싶어"
},
"isHintUsed" : false,
"createdAt" : "0초 전"
"isUserSenderVote" : true
} ]
}
}
----

*필드 타입*

- "totalCount": Integer
- "friendVotes": *FriendVote*[]
- "isUserSenderVote" : Boolean (내가 보냈는지 여부)
- *FriendVote*
* "id": Long
* "senderId" : Long
* "senderName" : String
* "senderYelloId" : String
* "senderGender": "MALE" | "FEMALE"
* "senderProfileImage" : String
* "receiverId" : Long
* "receiverName": String
* "receiverYelloId" : String
* "receiverGender": "MALE" | "FEMALE"
* "receiverProfileImage": String
* "vote": *Vote*
* "isHintUsed": Boolean
* "createdAt": "{0}초 전" | "{0}분 전" | "{0}시간 전" | "{0}일 전"

- *Vote*
* "nameHead": String
* "nameFoot": String
* "keywordHead": String
* "keyword": String
* "keywordFoot": String

=== NOTE

- 모든 종류의 쪽지를 조회할 때 `/api/v1/vote/friend?page=0` 으로 요청해주세요
* `type=` 을 명시하지 마세요
- 내가 보낸 쪽지를 조회할 때 `/api/v1/vote/friend?page=0&type=send` 으로 요청해주세요
- `senderGender` 필드가 다른 API와 일관되지 못한점 미안해요 ㅠ

=== CHANGELOG
- 2024.01.26 필드 명세 업데이트
- 2024.01.09 `type` 명세 업데이트
16 changes: 3 additions & 13 deletions src/docs/asciidoc/find-friend-votes.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:reproducible:
== 친구 투표 전체 조회 (업데이트)
== 친구 투표 전체 조회 (최신버전 -> v2 확인)

=== 요청

Expand All @@ -9,13 +9,6 @@ include::{snippets}/api/v1/vote/findAllFriendVotes/http-request.adoc[]

include::{snippets}/api/v1/vote/findAllFriendVotes/request-parameters.adoc[]

*업데이트 예정*
- "type": "send" | null

|===
|`+type+`|조회할 쪽지 종류
|===

=== 응답

include::{snippets}/api/v1/vote/findAllFriendVotes/http-response.adoc[]
Expand All @@ -41,11 +34,8 @@ include::{snippets}/api/v1/vote/findAllFriendVotes/http-response.adoc[]

=== NOTE

- 모든 종류의 쪽지를 조회할 때 `/api/v1/vote/friend?page=0` 으로 요청해주세요
* `type=` 을 명시하지 마세요
- 내가 보낸 쪽지를 조회할 때 `/api/v1/vote/friend?page=0&type=send` 으로 요청해주세요
- `senderGender` 필드가 다른 API와 일관되지 못한점 미안해요
- 최신버전 v2를 확인해주세요

=== CHANGELOG

- 2024.01.09 `type` 명세 업데이트
- 2024.01.09 `type` 최신버전 확인 바람
59 changes: 32 additions & 27 deletions src/docs/asciidoc/find-notice.adoc
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
:reproducible:
== 공지 조회 (명세)
== 공지 조회

=== 요청

[http]
----
GET /api/v1/notice HTTP/1.1
Authorization: Bearer your-access-token
----
include::{snippets}/api/v1/notice/http-request.adoc[]

=== 응답

[http,json]
----
HTTP/1.1 200 OK
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
{
"status": 200,
"message": "공지 조회에 성공하였습니다.",
"data": {
"imageUrl" : "url here",
"redirectUrl": "redirect url here",
"startDate": "2021.01.12",
"endDate": "2021.01.17",
"isAvailable": true
}
}
----
include::{snippets}/api/v1/notice/http-response.adoc[]

*필드 타입*

Expand All @@ -43,14 +20,42 @@ Content-Type: application/json
- "endDate": String(10)
* YYYY-MM-DD (ISO-8601)
- "isAvailable": Boolean
- "type" : String
* ENUM 값 -> "NOTICE" | "BANNER"


=== 주의

[http, json]

*유효한 날짜의 공지가 존재하지 않는 경우*

-> isAvailable은 false로 오고 날짜 제외한 나머지 값은 빈값으로 전달

----
{
"status": 200,
"message": "공지 조회에 성공하였습니다.",
"data": {
"imageUrl": "",
"redirectUrl": "",
"startDate": "2024-01-27",
"endDate": "2024-01-27",
"isAvailable": false,
"type": null,
"title": ""
}
----

=== NOTE

- 공지 정보를 조회하는 API입니다.
- 유효한 1개의 공지를 반환합니다.
- isAvailable true일 때, 유효한 1개의 공지를 반환합니다.
* 요구사항에 따라 여러개의 공지를 반환할 수 있도록 염두하고 있습니다.
* 반환되는 공지를 무조건 View에 띄워주시면 되겠습니다.

=== CHANGELOG

- 2024.01.26 API 릴리즈
- 2024.01.09 명세 작성
6 changes: 4 additions & 2 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@

* link:find-votes.html[내 투표 전체 조회하기]

* ⬆️ link:find-friend-votes.html[친구 투표 전체 조회하기, 2024-01-09]
* link:find-friend-votes.html[친구 투표 전체 조회하기, 2024-01-09]

* ⬆️ link:find-friend-votes-v2.html[친구 투표 전체 조회하기 v2 (명세), 2024-01-26]

* link:get-unread-vote.html[읽지 않은 쪽지 개수 조회하기]

Expand Down Expand Up @@ -102,4 +104,4 @@

=== Notice API

* 🆕 link:find-notice.html[공지 조회 (명세), 2024-01-09]
* 🆕 link:find-notice.html[공지 조회, 2024-01-26]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.yello.server.domain.notice.controller;


import com.yello.server.domain.notice.dto.NoticeDataResponse;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.yello.server.global.common.SuccessCode.READ_NOTICE_SUCCESS;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/v1")
public class NoticeController {

private final NoticeService noticeService;

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

import static com.yello.server.global.common.factory.TimeFactory.toYearAndMonthFormattedString;

import com.yello.server.domain.notice.entity.Notice;
import lombok.Builder;

@Builder
public record NoticeDataResponse(
String imageUrl,
String redirectUrl,
String startDate,
String endDate,
boolean isAvailable,
String type,
String title
) {

public static NoticeDataResponse of(Notice notice, Boolean isAvailable) {
return NoticeDataResponse.builder()
.imageUrl(notice.getImageUrl())
.redirectUrl(notice.getRedirectUrl())
.startDate(toYearAndMonthFormattedString(notice.getStartDate().toLocalDateTime()))
.endDate(toYearAndMonthFormattedString(notice.getEndDate().toLocalDateTime()))
.isAvailable(isAvailable)
.type(notice.getType())
.title(notice.getTitle())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.yello.server.global.common.dto.AuditingTimeEntity;
import java.time.ZonedDateTime;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand Down Expand Up @@ -38,4 +39,11 @@ public class Notice extends AuditingTimeEntity {

@Column(nullable = false)
private Boolean isAvailable;

@Column(nullable = false)
@Convert(converter = TypeConverter.class)
private String type;

@Column(nullable = false)
private String title;
}
28 changes: 28 additions & 0 deletions src/main/java/com/yello/server/domain/notice/entity/Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.yello.server.domain.notice.entity;

import java.text.MessageFormat;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Type {
NOTICE("NOTICE"),
BANNER("BANNER");

private final String intial;

public static Type fromCode(String dbData) {
return Arrays.stream(Type.values())
.filter(v -> v.getIntial().equals(dbData))
.findAny()
.orElseThrow(() -> new IllegalArgumentException(
MessageFormat.format("존재하지 않는 소셜입니다. {0}", dbData)));
}

public String intial() {
return intial;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.yello.server.domain.notice.entity;

import com.yello.server.domain.user.entity.Social;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import lombok.extern.log4j.Log4j2;

@Converter
@Log4j2
public class TypeConverter implements AttributeConverter<Type, String> {

@Override
public String convertToDatabaseColumn(Type type) {
if (type == null) {
return null;
}
return type.getIntial();
}

@Override
public Type convertToEntityAttribute(String dbData) {
if (dbData == null) {
return null;
}
try {
return Type.fromCode(dbData);
} catch (IllegalArgumentException exception) {
log.error("failure to convert cause unexpected code" + dbData + exception);
throw exception;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.yello.server.domain.notice.exception;

import com.yello.server.global.common.ErrorCode;
import com.yello.server.global.exception.CustomException;
import lombok.Getter;

@Getter
public class NoticeNotFoundException extends CustomException {

public NoticeNotFoundException(ErrorCode error) {
super(error, "[NoticeNotFoundException] " + error.getMessage());
}
}
Loading

0 comments on commit edd401b

Please sign in to comment.