Skip to content

Commit

Permalink
refactor: 북마크, Recommendation Converter 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-so committed Mar 27, 2024
1 parent 578c2f7 commit e1d8a68
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/eodya/api/bookmark/domain/BookMark.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eodya.api.bookmark.domain;

import com.eodya.api.bookmark.util.BookMarkStatusAttributeConverter;
import com.eodya.api.bookmark.util.BookMarkStatusConverter;
import com.eodya.api.common.entity.BaseEntity;
import com.eodya.api.place.domain.Place;
import com.eodya.api.users.domain.User;
Expand All @@ -25,7 +25,7 @@ public class BookMark extends BaseEntity {
private Long id;

@NotNull
@Convert(converter = BookMarkStatusAttributeConverter.class)
@Convert(converter = BookMarkStatusConverter.class)
@Column(length = 20)
private BookMarkStatus status = FALSE;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/eodya/api/bookmark/domain/Bookmark.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eodya.api.bookmark.domain;

import com.eodya.api.bookmark.util.BookMarkStatusAttributeConverter;
import com.eodya.api.bookmark.util.BookMarkStatusConverter;
import com.eodya.api.common.entity.BaseEntity;
import com.eodya.api.place.domain.Place;
import com.eodya.api.users.domain.User;
Expand All @@ -25,7 +25,7 @@ public class BookMark extends BaseEntity {
private Long id;

@NotNull
@Convert(converter = BookMarkStatusAttributeConverter.class)
@Convert(converter = BookMarkStatusConverter.class)
@Column(length = 20)
private BookMarkStatus status = FALSE;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.eodya.api.bookmark.util;

import com.eodya.api.bookmark.domain.BookMarkStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Component
public class BookMarkStatusConverter implements Converter<String, BookMarkStatus> {
@Converter
public class BookMarkStatusConverter implements AttributeConverter<BookMarkStatus, String> {

@Override
public BookMarkStatus convert(String status) {
public String convertToDatabaseColumn(BookMarkStatus bookMarkStatus) {
return bookMarkStatus.getDescription();
}

@Override
public BookMarkStatus convertToEntityAttribute(String status) {
return BookMarkStatus.from(status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.eodya.api.common.entity.BaseEntity;
import com.eodya.api.place.domain.Place;
import com.eodya.api.recommendation.util.RecommendationStatusAttributeConverter;
import com.eodya.api.recommendation.util.RecommendationStatusConverter;
import com.eodya.api.users.domain.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
Expand All @@ -27,7 +27,7 @@ public class Recommendation extends BaseEntity {
private Long id;

@NotNull
@Convert(converter = RecommendationStatusAttributeConverter.class)
@Convert(converter = RecommendationStatusConverter.class)
@Column(length = 20)
private RecommendationStatus status = FALSE;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.eodya.api.recommendation.util;

import com.eodya.api.recommendation.domain.RecommendationStatus;
import org.springframework.stereotype.Component;
import org.springframework.core.convert.converter.Converter;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter
public class RecommendationStatusConverter implements AttributeConverter<RecommendationStatus, String> {

@Component
public class RecommendationStatusConverter implements Converter<String, RecommendationStatus> {
@Override
public String convertToDatabaseColumn(RecommendationStatus recommendationStatus) {
return recommendationStatus.getDescription();
}

@Override
public RecommendationStatus convert(String status) {
public RecommendationStatus convertToEntityAttribute(String status) {
return RecommendationStatus.from(status);
}
}

0 comments on commit e1d8a68

Please sign in to comment.