|
| 1 | +package eureca.capstone.project.admin.transaction_feed.document; |
| 2 | + |
| 3 | +import eureca.capstone.project.admin.transaction_feed.entity.TransactionFeed; |
| 4 | +import jakarta.persistence.Id; |
| 5 | +import java.time.LocalDateTime; |
| 6 | +import lombok.AllArgsConstructor; |
| 7 | +import lombok.Builder; |
| 8 | +import lombok.Getter; |
| 9 | +import lombok.NoArgsConstructor; |
| 10 | +import org.springframework.data.elasticsearch.annotations.Document; |
| 11 | +import org.springframework.data.elasticsearch.annotations.Field; |
| 12 | +import org.springframework.data.elasticsearch.annotations.FieldType; |
| 13 | +import org.springframework.data.elasticsearch.annotations.Setting; |
| 14 | + |
| 15 | +@Getter |
| 16 | +@Builder |
| 17 | +@NoArgsConstructor |
| 18 | +@AllArgsConstructor |
| 19 | +@Document(indexName = "transaction_feed") |
| 20 | +@Setting(settingPath = "elasticsearch/analyzer-settings.json") |
| 21 | +public class TransactionFeedDocument { |
| 22 | + |
| 23 | + @Id |
| 24 | + private Long id; |
| 25 | + |
| 26 | + @Field(type = FieldType.Text, analyzer = "nori") |
| 27 | + private String title; |
| 28 | + |
| 29 | + @Field(type = FieldType.Text, analyzer = "nori") |
| 30 | + private String content; |
| 31 | + |
| 32 | + @Field(type = FieldType.Long) |
| 33 | + private Long salesPrice; |
| 34 | + |
| 35 | + @Field(type = FieldType.Long) |
| 36 | + private Long salesDataAmount; |
| 37 | + |
| 38 | + @Field(type = FieldType.Keyword) |
| 39 | + private Long sellerId; |
| 40 | + |
| 41 | + @Field(type = FieldType.Keyword) |
| 42 | + private String nickname; |
| 43 | + |
| 44 | + @Field(type = FieldType.Keyword) |
| 45 | + private Long telecomCompanyId; |
| 46 | + |
| 47 | + @Field(type = FieldType.Text, analyzer = "nori") |
| 48 | + private String telecomCompanyName; // 검색용 |
| 49 | + |
| 50 | + @Field(type = FieldType.Keyword) |
| 51 | + private Long salesTypeId; |
| 52 | + |
| 53 | + @Field(type = FieldType.Keyword) |
| 54 | + private String status; |
| 55 | + |
| 56 | + @Field(type = FieldType.Long) |
| 57 | + private Long defaultImageNumber; |
| 58 | + |
| 59 | + @Field(type = FieldType.Date, format = {}, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSS") |
| 60 | + private LocalDateTime createdAt; |
| 61 | + |
| 62 | + @Field(type = FieldType.Date, format = {}, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSS") |
| 63 | + private LocalDateTime expiresAt; |
| 64 | + |
| 65 | + @Field(type = FieldType.Boolean) |
| 66 | + private boolean isDeleted; |
| 67 | + |
| 68 | + public static TransactionFeedDocument fromEntity(TransactionFeed transactionFeed) { |
| 69 | + return TransactionFeedDocument.builder() |
| 70 | + .id(transactionFeed.getTransactionFeedId()) |
| 71 | + .title(transactionFeed.getTitle()) |
| 72 | + .content(transactionFeed.getContent()) |
| 73 | + .salesPrice(transactionFeed.getSalesPrice()) |
| 74 | + .salesDataAmount(transactionFeed.getSalesDataAmount()) |
| 75 | + .sellerId(transactionFeed.getUser().getUserId()) |
| 76 | + .nickname(transactionFeed.getUser().getNickname()) |
| 77 | + .telecomCompanyId(transactionFeed.getTelecomCompany().getTelecomCompanyId()) |
| 78 | + .telecomCompanyName(transactionFeed.getTelecomCompany().getName()) |
| 79 | + .salesTypeId(transactionFeed.getSalesType().getSalesTypeId()) |
| 80 | + .status(transactionFeed.getStatus().getCode()) |
| 81 | + .defaultImageNumber(transactionFeed.getDefaultImageNumber()) |
| 82 | + .createdAt(transactionFeed.getCreatedAt()) |
| 83 | + .expiresAt(transactionFeed.getExpiresAt()) |
| 84 | + .isDeleted(transactionFeed.isDeleted()) |
| 85 | + .build(); |
| 86 | + } |
| 87 | +} |
0 commit comments