-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YEL-185 [feat] 공지 조회하기 개발서버 배포
- Loading branch information
Showing
39 changed files
with
1,384 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` 명세 업데이트 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/yello/server/domain/notice/controller/NoticeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/yello/server/domain/notice/dto/NoticeDataResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/yello/server/domain/notice/entity/Type.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/yello/server/domain/notice/entity/TypeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/yello/server/domain/notice/exception/NoticeNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.