From e986fa97caa15b4e931f4b5af72b5595b033f4c8 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 4 Dec 2025 15:20:42 -0500 Subject: [PATCH] running finally.. --- .../controllers/CategoryController.java | 34 +++++++ .../ballistic/model/CategoryMapping.java | 98 +++++++++++++++++++ .../dto/admin/MerchantCategoryMappingDto.java | 11 +++ .../web/dto/admin/SimpleMerchantDto.java | 6 ++ .../UpdateMerchantCategoryMappingRequest.java | 5 + 5 files changed, 154 insertions(+) create mode 100644 src/main/java/group/goforward/ballistic/controllers/CategoryController.java create mode 100644 src/main/java/group/goforward/ballistic/model/CategoryMapping.java create mode 100644 src/main/java/group/goforward/ballistic/web/dto/admin/MerchantCategoryMappingDto.java create mode 100644 src/main/java/group/goforward/ballistic/web/dto/admin/SimpleMerchantDto.java create mode 100644 src/main/java/group/goforward/ballistic/web/dto/admin/UpdateMerchantCategoryMappingRequest.java diff --git a/src/main/java/group/goforward/ballistic/controllers/CategoryController.java b/src/main/java/group/goforward/ballistic/controllers/CategoryController.java new file mode 100644 index 0000000..4787170 --- /dev/null +++ b/src/main/java/group/goforward/ballistic/controllers/CategoryController.java @@ -0,0 +1,34 @@ +package group.goforward.ballistic.controllers; + +import group.goforward.ballistic.repos.PartCategoryRepository; +import group.goforward.ballistic.web.dto.admin.PartCategoryDto; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/categories") +@CrossOrigin // you can tighten origins later +public class CategoryController { + + private final PartCategoryRepository partCategories; + + public CategoryController(PartCategoryRepository partCategories) { + this.partCategories = partCategories; + } + + @GetMapping + public List list() { + return partCategories.findAllByOrderByGroupNameAscSortOrderAscNameAsc() + .stream() + .map(pc -> new PartCategoryDto( + pc.getId(), + pc.getSlug(), + pc.getName(), + pc.getDescription(), + pc.getGroupName(), + pc.getSortOrder() + )) + .toList(); + } +} \ No newline at end of file diff --git a/src/main/java/group/goforward/ballistic/model/CategoryMapping.java b/src/main/java/group/goforward/ballistic/model/CategoryMapping.java new file mode 100644 index 0000000..303fd85 --- /dev/null +++ b/src/main/java/group/goforward/ballistic/model/CategoryMapping.java @@ -0,0 +1,98 @@ +// src/main/java/group/goforward/ballistic/model/CategoryMapping.java +package group.goforward.ballistic.model; + +import jakarta.persistence.*; +import java.time.OffsetDateTime; + +@Entity +@Table(name = "category_mappings") +public class CategoryMapping { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Integer id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "merchant_id", nullable = false) + private Merchant merchant; + + @Column(name = "raw_category_path", nullable = false) + private String rawCategoryPath; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "part_category_id") + private PartCategory partCategory; + + @Column(name = "created_at", nullable = false) + private OffsetDateTime createdAt = OffsetDateTime.now(); + + @Column(name = "updated_at", nullable = false) + private OffsetDateTime updatedAt = OffsetDateTime.now(); + + @PrePersist + public void onCreate() { + OffsetDateTime now = OffsetDateTime.now(); + if (createdAt == null) { + createdAt = now; + } + if (updatedAt == null) { + updatedAt = now; + } + } + + @PreUpdate + public void onUpdate() { + this.updatedAt = OffsetDateTime.now(); + } + + // --- getters & setters --- + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Merchant getMerchant() { + return merchant; + } + + public void setMerchant(Merchant merchant) { + this.merchant = merchant; + } + + public String getRawCategoryPath() { + return rawCategoryPath; + } + + public void setRawCategoryPath(String rawCategoryPath) { + this.rawCategoryPath = rawCategoryPath; + } + + public PartCategory getPartCategory() { + return partCategory; + } + + public void setPartCategory(PartCategory partCategory) { + this.partCategory = partCategory; + } + + public OffsetDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(OffsetDateTime createdAt) { + this.createdAt = createdAt; + } + + public OffsetDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(OffsetDateTime updatedAt) { + this.updatedAt = updatedAt; + } +} \ No newline at end of file diff --git a/src/main/java/group/goforward/ballistic/web/dto/admin/MerchantCategoryMappingDto.java b/src/main/java/group/goforward/ballistic/web/dto/admin/MerchantCategoryMappingDto.java new file mode 100644 index 0000000..f8e8f76 --- /dev/null +++ b/src/main/java/group/goforward/ballistic/web/dto/admin/MerchantCategoryMappingDto.java @@ -0,0 +1,11 @@ +// src/main/java/group/goforward/ballistic/web/dto/admin/MerchantCategoryMappingDto.java +package group.goforward.ballistic.web.dto.admin; + +public record MerchantCategoryMappingDto( + Integer id, + Integer merchantId, + String merchantName, + String rawCategoryPath, + Integer partCategoryId, + String partCategoryName +) {} \ No newline at end of file diff --git a/src/main/java/group/goforward/ballistic/web/dto/admin/SimpleMerchantDto.java b/src/main/java/group/goforward/ballistic/web/dto/admin/SimpleMerchantDto.java new file mode 100644 index 0000000..4f7f2a6 --- /dev/null +++ b/src/main/java/group/goforward/ballistic/web/dto/admin/SimpleMerchantDto.java @@ -0,0 +1,6 @@ +package group.goforward.ballistic.web.dto.admin; + +public record SimpleMerchantDto( + Integer id, + String name +) { } \ No newline at end of file diff --git a/src/main/java/group/goforward/ballistic/web/dto/admin/UpdateMerchantCategoryMappingRequest.java b/src/main/java/group/goforward/ballistic/web/dto/admin/UpdateMerchantCategoryMappingRequest.java new file mode 100644 index 0000000..4e55bc4 --- /dev/null +++ b/src/main/java/group/goforward/ballistic/web/dto/admin/UpdateMerchantCategoryMappingRequest.java @@ -0,0 +1,5 @@ +package group.goforward.ballistic.web.dto.admin; + +public record UpdateMerchantCategoryMappingRequest( + Integer partCategoryId +) {} \ No newline at end of file