Skip to content

Commit

Permalink
YEL-185 [feat] notice type 버그제거
Browse files Browse the repository at this point in the history
YEL-185 [feat] notice type 버그제거
  • Loading branch information
hyeonjeongs authored Jan 29, 2024
2 parents 0320681 + e75392e commit f03c405
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static NoticeDataResponse of(Notice notice, Boolean isAvailable) {
.startDate(toYearAndMonthFormattedString(notice.getStartDate().toLocalDateTime()))
.endDate(toYearAndMonthFormattedString(notice.getEndDate().toLocalDateTime()))
.isAvailable(isAvailable)
.type(notice.getType())
.type(notice.getTag().getIntial())
.title(notice.getTitle())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class Notice extends AuditingTimeEntity {
private Boolean isAvailable;

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

@Column(nullable = false)
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

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

private final String intial;

public static Type fromCode(String dbData) {
return Arrays.stream(Type.values())
public static NoticeType fromCode(String dbData) {
return Arrays.stream(NoticeType.values())
.filter(v -> v.getIntial().equals(dbData))
.findAny()
.orElseThrow(() -> new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
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> {
public class NoticeTypeConverter implements AttributeConverter<NoticeType, String> {

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

@Override
public Type convertToEntityAttribute(String dbData) {
public NoticeType convertToEntityAttribute(String dbData) {
if (dbData == null) {
return null;
}
try {
return Type.fromCode(dbData);
return NoticeType.fromCode(dbData);
} catch (IllegalArgumentException exception) {
log.error("failure to convert cause unexpected code" + dbData + exception);
throw exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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.user.repository.UserRepository;
import java.time.ZoneId;
Expand All @@ -28,7 +29,7 @@ public NoticeDataResponse findNotice(Long userId) {
userRepository.findById(userId);
Notice noticeData =
noticeRepository.findTopNotice().orElseGet(
() -> Notice.builder().imageUrl("").redirectUrl("").title("").type("").endDate(now)
() -> Notice.builder().imageUrl("").redirectUrl("").title("").tag(NoticeType.NOTICE).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,9 +1,6 @@
package com.yello.server.domain.notice;

import static com.yello.server.global.common.ErrorCode.NOT_FOUND_NOTICE_EXCEPTION;

import com.yello.server.domain.notice.entity.Notice;
import com.yello.server.domain.notice.exception.NoticeNotFoundException;
import com.yello.server.domain.notice.repository.NoticeRepository;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -35,13 +32,13 @@ public Optional<Notice> findTopNotice() {
@Override
public Notice save(Notice notice) {
final Notice newNotice = Notice.builder()
.id(notice.getId()==null ? ++id : notice.getId())
.id(notice.getId() == null ? ++id : notice.getId())
.endDate(notice.getEndDate())
.imageUrl(notice.getImageUrl())
.startDate(notice.getStartDate())
.redirectUrl(notice.getRedirectUrl())
.isAvailable(notice.getIsAvailable())
.type(notice.getType())
.tag(notice.getTag())
.title(notice.getTitle())
.build();

Expand Down
9 changes: 5 additions & 4 deletions src/test/java/com/yello/server/util/TestDataEntityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.yello.server.domain.group.entity.UserGroup;
import com.yello.server.domain.group.entity.UserGroupType;
import com.yello.server.domain.notice.entity.Notice;
import com.yello.server.domain.notice.entity.NoticeType;
import com.yello.server.domain.purchase.entity.Gateway;
import com.yello.server.domain.purchase.entity.ProductType;
import com.yello.server.domain.purchase.entity.Purchase;
Expand Down Expand Up @@ -122,9 +123,9 @@ public UserGroup generateGroup(long index, UserGroupType userGroupType) {
@Override
public QuestionGroupType generateQuestionGroupType(long index, Question question) {
return QuestionGroupType.builder()
.userGroupType(UserGroupType.UNIVERSITY)
.question(question)
.build();
.userGroupType(UserGroupType.UNIVERSITY)
.question(question)
.build();
}

@Override
Expand Down Expand Up @@ -153,7 +154,7 @@ public Notice genereateNotice(long index) {
.startDate(now.minusDays(3))
.redirectUrl("redirectUrl")
.isAvailable(true)
.type("event")
.tag(NoticeType.NOTICE)
.title("notice title")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.yello.server.domain.group.entity.UserGroup;
import com.yello.server.domain.group.entity.UserGroupType;
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.purchase.entity.Gateway;
import com.yello.server.domain.purchase.entity.ProductType;
Expand All @@ -29,12 +30,12 @@
public class TestDataRepositoryUtil implements TestDataUtil {

private final FriendRepository friendRepository;
private final NoticeRepository noticeRepository;
private final PurchaseRepository purchaseRepository;
private final QuestionGroupTypeRepository questionGroupTypeRepository;
private final QuestionRepository questionRepository;
private final UserRepository userRepository;
private final VoteRepository voteRepository;
private final NoticeRepository noticeRepository;

public TestDataRepositoryUtil(UserRepository userRepository, VoteRepository voteRepository,
QuestionRepository questionRepository,
Expand Down Expand Up @@ -182,7 +183,7 @@ public Notice genereateNotice(long index) {
.startDate(now.minusDays(3))
.redirectUrl("redirectUrl")
.isAvailable(true)
.type("event")
.tag(NoticeType.NOTICE)
.title("notice title")
.build());
}
Expand Down

0 comments on commit f03c405

Please sign in to comment.