mirror of
https://gitea.gofwd.group/Forward_Group/ballistic-builder-spring.git
synced 2025-12-05 18:46:44 -05:00
Compare commits
12 Commits
d344b372d1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 12d2ee53b5 | |||
| 2969cdfa23 | |||
| e986fa97ca | |||
| c283ec15b6 | |||
| 9096ddd165 | |||
| 3d1501cc87 | |||
| 3ae68f30c0 | |||
| f3626af709 | |||
| 756a6791fc | |||
| 74a5c42e26 | |||
| 5e3f7d5044 | |||
| dc5942c47e |
31
.idea/dataSources.xml
generated
Normal file
31
.idea/dataSources.xml
generated
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="r710" uuid="e6a29f5c-71d9-45f0-931b-554bcf8a94ba">
|
||||||
|
<driver-ref>postgresql</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:postgresql://r710.dev.gofwd.group:5433/postgres</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
<data-source source="LOCAL" name="ss_builder@r710.gofwd.group" uuid="e0fa459b-2f6c-45f1-9c41-66423c870df9">
|
||||||
|
<driver-ref>postgresql</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<imported>true</imported>
|
||||||
|
<remarks>$PROJECT_DIR$/src/main/resources/application.properties</remarks>
|
||||||
|
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:postgresql://r710.gofwd.group:5433/ss_builder</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
3
pom.xml
3
pom.xml
@@ -40,7 +40,8 @@
|
|||||||
<connection></connection>
|
<connection></connection>
|
||||||
<developerConnection>scm:git:https://gitea.gofwd.group/Forward_Group/ballistic-builder-spring.git</developerConnection>
|
<developerConnection>scm:git:https://gitea.gofwd.group/Forward_Group/ballistic-builder-spring.git</developerConnection>
|
||||||
<tag/>
|
<tag/>
|
||||||
<url/>
|
<url>ssh://git@gitea.gofwd.group:2225/Forward_Group/ballistic-builder-spring.git</url>
|
||||||
|
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -24,14 +24,19 @@ public class SecurityConfig {
|
|||||||
sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
)
|
)
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
|
|
||||||
// Auth endpoints always open
|
// Auth endpoints always open
|
||||||
.requestMatchers("/api/auth/**").permitAll()
|
.requestMatchers("/api/auth/**").permitAll()
|
||||||
|
|
||||||
// Swagger / docs
|
// Swagger / docs
|
||||||
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll()
|
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll()
|
||||||
|
|
||||||
// Health
|
// Health
|
||||||
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
|
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
|
||||||
|
|
||||||
// Public product endpoints
|
// Public product endpoints
|
||||||
.requestMatchers("/api/products/gunbuilder/**").permitAll()
|
.requestMatchers("/api/products/gunbuilder/**").permitAll()
|
||||||
|
|
||||||
// Everything else (for now) also open – we can tighten later
|
// Everything else (for now) also open – we can tighten later
|
||||||
.anyRequest().permitAll()
|
.anyRequest().permitAll()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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<PartCategoryDto> list() {
|
||||||
|
return partCategories.findAllByOrderByGroupNameAscSortOrderAscNameAsc()
|
||||||
|
.stream()
|
||||||
|
.map(pc -> new PartCategoryDto(
|
||||||
|
pc.getId(),
|
||||||
|
pc.getSlug(),
|
||||||
|
pc.getName(),
|
||||||
|
pc.getDescription(),
|
||||||
|
pc.getGroupName(),
|
||||||
|
pc.getSortOrder()
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package group.goforward.ballistic.controllers.admin;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.PartCategory;
|
||||||
|
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/admin/categories")
|
||||||
|
@CrossOrigin
|
||||||
|
public class AdminCategoryController {
|
||||||
|
|
||||||
|
private final PartCategoryRepository partCategories;
|
||||||
|
|
||||||
|
public AdminCategoryController(PartCategoryRepository partCategories) {
|
||||||
|
this.partCategories = partCategories;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<PartCategoryDto> listCategories() {
|
||||||
|
return partCategories
|
||||||
|
.findAllByOrderByGroupNameAscSortOrderAscNameAsc()
|
||||||
|
.stream()
|
||||||
|
.map(this::toDto)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PartCategoryDto toDto(PartCategory entity) {
|
||||||
|
return new PartCategoryDto(
|
||||||
|
entity.getId(),
|
||||||
|
entity.getSlug(),
|
||||||
|
entity.getName(),
|
||||||
|
entity.getDescription(),
|
||||||
|
entity.getGroupName(),
|
||||||
|
entity.getSortOrder()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package group.goforward.ballistic.controllers.admin;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.CategoryMapping;
|
||||||
|
import group.goforward.ballistic.model.Merchant;
|
||||||
|
import group.goforward.ballistic.model.PartCategory;
|
||||||
|
import group.goforward.ballistic.repos.CategoryMappingRepository;
|
||||||
|
import group.goforward.ballistic.repos.MerchantRepository;
|
||||||
|
import group.goforward.ballistic.repos.PartCategoryRepository;
|
||||||
|
import group.goforward.ballistic.web.dto.admin.MerchantCategoryMappingDto;
|
||||||
|
import group.goforward.ballistic.web.dto.admin.SimpleMerchantDto;
|
||||||
|
import group.goforward.ballistic.web.dto.admin.UpdateMerchantCategoryMappingRequest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/admin/category-mappings")
|
||||||
|
@CrossOrigin // you can tighten origins later
|
||||||
|
public class AdminCategoryMappingController {
|
||||||
|
|
||||||
|
private final CategoryMappingRepository categoryMappingRepository;
|
||||||
|
private final MerchantRepository merchantRepository;
|
||||||
|
private final PartCategoryRepository partCategoryRepository;
|
||||||
|
|
||||||
|
public AdminCategoryMappingController(
|
||||||
|
CategoryMappingRepository categoryMappingRepository,
|
||||||
|
MerchantRepository merchantRepository,
|
||||||
|
PartCategoryRepository partCategoryRepository
|
||||||
|
) {
|
||||||
|
this.categoryMappingRepository = categoryMappingRepository;
|
||||||
|
this.merchantRepository = merchantRepository;
|
||||||
|
this.partCategoryRepository = partCategoryRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merchants that have at least one category_mappings row.
|
||||||
|
* Used for the "All Merchants" dropdown in the UI.
|
||||||
|
*/
|
||||||
|
@GetMapping("/merchants")
|
||||||
|
public List<SimpleMerchantDto> listMerchantsWithMappings() {
|
||||||
|
List<Merchant> merchants = categoryMappingRepository.findDistinctMerchantsWithMappings();
|
||||||
|
return merchants.stream()
|
||||||
|
.map(m -> new SimpleMerchantDto(m.getId(), m.getName()))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List mappings for a specific merchant, or all mappings if no merchantId is provided.
|
||||||
|
* GET /api/admin/category-mappings?merchantId=1
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public List<MerchantCategoryMappingDto> listByMerchant(
|
||||||
|
@RequestParam(name = "merchantId", required = false) Integer merchantId
|
||||||
|
) {
|
||||||
|
List<CategoryMapping> mappings;
|
||||||
|
|
||||||
|
if (merchantId != null) {
|
||||||
|
mappings = categoryMappingRepository.findByMerchantIdOrderByRawCategoryPathAsc(merchantId);
|
||||||
|
} else {
|
||||||
|
// fall back to all mappings; you can add a more specific repository method later if desired
|
||||||
|
mappings = categoryMappingRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mappings.stream()
|
||||||
|
.map(cm -> new MerchantCategoryMappingDto(
|
||||||
|
cm.getId(),
|
||||||
|
cm.getMerchant().getId(),
|
||||||
|
cm.getMerchant().getName(),
|
||||||
|
cm.getRawCategoryPath(),
|
||||||
|
cm.getPartCategory() != null ? cm.getPartCategory().getId() : null,
|
||||||
|
cm.getPartCategory() != null ? cm.getPartCategory().getName() : null
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a single mapping's part_category.
|
||||||
|
* POST /api/admin/category-mappings/{id}
|
||||||
|
* Body: { "partCategoryId": 24 }
|
||||||
|
*/
|
||||||
|
@PostMapping("/{id}")
|
||||||
|
public MerchantCategoryMappingDto updateMapping(
|
||||||
|
@PathVariable Integer id,
|
||||||
|
@RequestBody UpdateMerchantCategoryMappingRequest request
|
||||||
|
) {
|
||||||
|
CategoryMapping mapping = categoryMappingRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Mapping not found"));
|
||||||
|
|
||||||
|
PartCategory partCategory = null;
|
||||||
|
if (request.partCategoryId() != null) {
|
||||||
|
partCategory = partCategoryRepository.findById(request.partCategoryId())
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "Part category not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
mapping.setPartCategory(partCategory);
|
||||||
|
mapping = categoryMappingRepository.save(mapping);
|
||||||
|
|
||||||
|
return new MerchantCategoryMappingDto(
|
||||||
|
mapping.getId(),
|
||||||
|
mapping.getMerchant().getId(),
|
||||||
|
mapping.getMerchant().getName(),
|
||||||
|
mapping.getRawCategoryPath(),
|
||||||
|
mapping.getPartCategory() != null ? mapping.getPartCategory().getId() : null,
|
||||||
|
mapping.getPartCategory() != null ? mapping.getPartCategory().getName() : null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public MerchantCategoryMappingDto updateMappingPut(
|
||||||
|
@PathVariable Integer id,
|
||||||
|
@RequestBody UpdateMerchantCategoryMappingRequest request
|
||||||
|
) {
|
||||||
|
// just delegate so POST & PUT behave the same
|
||||||
|
return updateMapping(id, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package group.goforward.ballistic.controllers.admin;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.PartCategory;
|
||||||
|
import group.goforward.ballistic.model.PartRoleMapping;
|
||||||
|
import group.goforward.ballistic.repos.PartCategoryRepository;
|
||||||
|
import group.goforward.ballistic.repos.PartRoleMappingRepository;
|
||||||
|
import group.goforward.ballistic.web.dto.admin.AdminPartRoleMappingDto;
|
||||||
|
import group.goforward.ballistic.web.dto.admin.CreatePartRoleMappingRequest;
|
||||||
|
import group.goforward.ballistic.web.dto.admin.UpdatePartRoleMappingRequest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/admin/part-role-mappings")
|
||||||
|
@CrossOrigin
|
||||||
|
public class AdminPartRoleMappingController {
|
||||||
|
|
||||||
|
private final PartRoleMappingRepository partRoleMappingRepository;
|
||||||
|
private final PartCategoryRepository partCategoryRepository;
|
||||||
|
|
||||||
|
public AdminPartRoleMappingController(
|
||||||
|
PartRoleMappingRepository partRoleMappingRepository,
|
||||||
|
PartCategoryRepository partCategoryRepository
|
||||||
|
) {
|
||||||
|
this.partRoleMappingRepository = partRoleMappingRepository;
|
||||||
|
this.partCategoryRepository = partCategoryRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /api/admin/part-role-mappings?platform=AR-15
|
||||||
|
@GetMapping
|
||||||
|
public List<AdminPartRoleMappingDto> list(
|
||||||
|
@RequestParam(name = "platform", required = false) String platform
|
||||||
|
) {
|
||||||
|
List<PartRoleMapping> mappings;
|
||||||
|
|
||||||
|
if (platform != null && !platform.isBlank()) {
|
||||||
|
mappings = partRoleMappingRepository.findByPlatformOrderByPartRoleAsc(platform);
|
||||||
|
} else {
|
||||||
|
mappings = partRoleMappingRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mappings.stream()
|
||||||
|
.map(this::toDto)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /api/admin/part-role-mappings
|
||||||
|
@PostMapping
|
||||||
|
public AdminPartRoleMappingDto create(
|
||||||
|
@RequestBody CreatePartRoleMappingRequest request
|
||||||
|
) {
|
||||||
|
PartCategory category = partCategoryRepository.findBySlug(request.categorySlug())
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"PartCategory not found for slug: " + request.categorySlug()
|
||||||
|
));
|
||||||
|
|
||||||
|
PartRoleMapping mapping = new PartRoleMapping();
|
||||||
|
mapping.setPlatform(request.platform());
|
||||||
|
mapping.setPartRole(request.partRole());
|
||||||
|
mapping.setPartCategory(category);
|
||||||
|
mapping.setNotes(request.notes());
|
||||||
|
|
||||||
|
mapping = partRoleMappingRepository.save(mapping);
|
||||||
|
return toDto(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT /api/admin/part-role-mappings/{id}
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public AdminPartRoleMappingDto update(
|
||||||
|
@PathVariable Integer id,
|
||||||
|
@RequestBody UpdatePartRoleMappingRequest request
|
||||||
|
) {
|
||||||
|
PartRoleMapping mapping = partRoleMappingRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Mapping not found"));
|
||||||
|
|
||||||
|
if (request.platform() != null) {
|
||||||
|
mapping.setPlatform(request.platform());
|
||||||
|
}
|
||||||
|
if (request.partRole() != null) {
|
||||||
|
mapping.setPartRole(request.partRole());
|
||||||
|
}
|
||||||
|
if (request.categorySlug() != null) {
|
||||||
|
PartCategory category = partCategoryRepository.findBySlug(request.categorySlug())
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"PartCategory not found for slug: " + request.categorySlug()
|
||||||
|
));
|
||||||
|
mapping.setPartCategory(category);
|
||||||
|
}
|
||||||
|
if (request.notes() != null) {
|
||||||
|
mapping.setNotes(request.notes());
|
||||||
|
}
|
||||||
|
|
||||||
|
mapping = partRoleMappingRepository.save(mapping);
|
||||||
|
return toDto(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE /api/admin/part-role-mappings/{id}
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||||
|
public void delete(@PathVariable Integer id) {
|
||||||
|
if (!partRoleMappingRepository.existsById(id)) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Mapping not found");
|
||||||
|
}
|
||||||
|
partRoleMappingRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AdminPartRoleMappingDto toDto(PartRoleMapping mapping) {
|
||||||
|
PartCategory cat = mapping.getPartCategory();
|
||||||
|
return new AdminPartRoleMappingDto(
|
||||||
|
mapping.getId(),
|
||||||
|
mapping.getPlatform(),
|
||||||
|
mapping.getPartRole(),
|
||||||
|
cat != null ? cat.getSlug() : null,
|
||||||
|
cat != null ? cat.getGroupName() : null,
|
||||||
|
mapping.getNotes()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package group.goforward.ballistic.controllers.admin;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.PartCategory;
|
||||||
|
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/admin/part-categories")
|
||||||
|
@CrossOrigin // keep it loose for now, you can tighten origins later
|
||||||
|
public class PartCategoryAdminController {
|
||||||
|
|
||||||
|
private final PartCategoryRepository partCategories;
|
||||||
|
|
||||||
|
public PartCategoryAdminController(PartCategoryRepository partCategories) {
|
||||||
|
this.partCategories = partCategories;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<PartCategoryDto> list() {
|
||||||
|
return partCategories.findAllByOrderByGroupNameAscSortOrderAscNameAsc()
|
||||||
|
.stream()
|
||||||
|
.map(pc -> new PartCategoryDto(
|
||||||
|
pc.getId(),
|
||||||
|
pc.getSlug(),
|
||||||
|
pc.getName(),
|
||||||
|
pc.getDescription(),
|
||||||
|
pc.getGroupName(),
|
||||||
|
pc.getSortOrder()
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,23 +5,32 @@ import jakarta.persistence.*;
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "affiliate_category_map")
|
@Table(name = "affiliate_category_map")
|
||||||
public class AffiliateCategoryMap {
|
public class AffiliateCategoryMap {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id", nullable = false)
|
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@Column(name = "feedname", nullable = false, length = 100)
|
// e.g. "PART_ROLE", "RAW_CATEGORY", etc.
|
||||||
private String feedname;
|
@Column(name = "source_type", nullable = false)
|
||||||
|
private String sourceType;
|
||||||
|
|
||||||
@Column(name = "affiliatecategory", nullable = false)
|
// the value we’re mapping from (e.g. "suppressor", "TRIGGER")
|
||||||
private String affiliatecategory;
|
@Column(name = "source_value", nullable = false)
|
||||||
|
private String sourceValue;
|
||||||
|
|
||||||
@Column(name = "buildercategoryid", nullable = false)
|
// optional platform ("AR-15", "PRECISION", etc.)
|
||||||
private Integer buildercategoryid;
|
@Column(name = "platform")
|
||||||
|
private String platform;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "part_category_id", nullable = false)
|
||||||
|
private PartCategory partCategory;
|
||||||
|
|
||||||
@Column(name = "notes")
|
@Column(name = "notes")
|
||||||
private String notes;
|
private String notes;
|
||||||
|
|
||||||
|
// --- getters / setters ---
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -30,28 +39,36 @@ public class AffiliateCategoryMap {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFeedname() {
|
public String getSourceType() {
|
||||||
return feedname;
|
return sourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFeedname(String feedname) {
|
public void setSourceType(String sourceType) {
|
||||||
this.feedname = feedname;
|
this.sourceType = sourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAffiliatecategory() {
|
public String getSourceValue() {
|
||||||
return affiliatecategory;
|
return sourceValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAffiliatecategory(String affiliatecategory) {
|
public void setSourceValue(String sourceValue) {
|
||||||
this.affiliatecategory = affiliatecategory;
|
this.sourceValue = sourceValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getBuildercategoryid() {
|
public String getPlatform() {
|
||||||
return buildercategoryid;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBuildercategoryid(Integer buildercategoryid) {
|
public void setPlatform(String platform) {
|
||||||
this.buildercategoryid = buildercategoryid;
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PartCategory getPartCategory() {
|
||||||
|
return partCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPartCategory(PartCategory partCategory) {
|
||||||
|
this.partCategory = partCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNotes() {
|
public String getNotes() {
|
||||||
@@ -61,5 +78,4 @@ public class AffiliateCategoryMap {
|
|||||||
public void setNotes(String notes) {
|
public void setNotes(String notes) {
|
||||||
this.notes = notes;
|
this.notes = notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,49 @@
|
|||||||
package group.goforward.ballistic.model;
|
package group.goforward.ballistic.model;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "part_categories")
|
@Table(name = "part_categories")
|
||||||
public class PartCategory {
|
public class PartCategory {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id", nullable = false)
|
@Column(name = "id", nullable = false)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@Column(name = "slug", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "slug", nullable = false, unique = true)
|
||||||
private String slug;
|
private String slug;
|
||||||
|
|
||||||
@Column(name = "name", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "name", nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(name = "description", length = Integer.MAX_VALUE)
|
@Column(name = "description")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@ColumnDefault("gen_random_uuid()")
|
||||||
|
@Column(name = "uuid", nullable = false)
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
@Column(name = "group_name")
|
||||||
|
private String groupName;
|
||||||
|
|
||||||
|
@Column(name = "sort_order")
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
// --- Getters & Setters ---
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -51,4 +76,43 @@ public class PartCategory {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUuid(UUID uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupName() {
|
||||||
|
return groupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupName(String groupName) {
|
||||||
|
this.groupName = groupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package group.goforward.ballistic.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "part_role_category_mappings",
|
||||||
|
uniqueConstraints = @UniqueConstraint(columnNames = {"platform", "part_role"}))
|
||||||
|
public class PartRoleCategoryMapping {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "platform", nullable = false)
|
||||||
|
private String platform;
|
||||||
|
|
||||||
|
@Column(name = "part_role", nullable = false)
|
||||||
|
private String partRole;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "category_slug", referencedColumnName = "slug", nullable = false)
|
||||||
|
private PartCategory category;
|
||||||
|
|
||||||
|
@Column(name = "notes")
|
||||||
|
private String notes;
|
||||||
|
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
// getters/setters…
|
||||||
|
|
||||||
|
public Integer getId() { return id; }
|
||||||
|
public void setId(Integer id) { this.id = id; }
|
||||||
|
|
||||||
|
public String getPlatform() { return platform; }
|
||||||
|
public void setPlatform(String platform) { this.platform = platform; }
|
||||||
|
|
||||||
|
public String getPartRole() { return partRole; }
|
||||||
|
public void setPartRole(String partRole) { this.partRole = partRole; }
|
||||||
|
|
||||||
|
public PartCategory getCategory() { return category; }
|
||||||
|
public void setCategory(PartCategory category) { this.category = category; }
|
||||||
|
|
||||||
|
public String getNotes() { return notes; }
|
||||||
|
public void setNotes(String notes) { this.notes = notes; }
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package group.goforward.ballistic.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "part_role_mappings")
|
||||||
|
public class PartRoleMapping {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String platform; // e.g. "AR-15"
|
||||||
|
|
||||||
|
@Column(name = "part_role", nullable = false)
|
||||||
|
private String partRole; // e.g. "UPPER", "BARREL", etc.
|
||||||
|
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
@JoinColumn(name = "part_category_id")
|
||||||
|
private PartCategory partCategory;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "text")
|
||||||
|
private String notes;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(String platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPartRole() {
|
||||||
|
return partRole;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPartRole(String partRole) {
|
||||||
|
this.partRole = partRole;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PartCategory getPartCategory() {
|
||||||
|
return partCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPartCategory(PartCategory partCategory) {
|
||||||
|
this.partCategory = partCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotes() {
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotes(String notes) {
|
||||||
|
this.notes = notes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,36 @@ package group.goforward.ballistic.model;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.ProductOffer;
|
||||||
import group.goforward.ballistic.model.ProductConfiguration;
|
import group.goforward.ballistic.model.ProductConfiguration;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "products")
|
@Table(name = "products")
|
||||||
|
@NamedQuery(name="Products.findByPlatformWithBrand", query= "" +
|
||||||
|
"SELECT p FROM Product p" +
|
||||||
|
" JOIN FETCH p.brand b" +
|
||||||
|
" WHERE p.platform = :platform" +
|
||||||
|
" AND p.deletedAt IS NULL")
|
||||||
|
|
||||||
|
@NamedQuery(name="Product.findByPlatformAndPartRoleInWithBrand", query= "" +
|
||||||
|
"SELECT p FROM Product p JOIN FETCH p.brand b" +
|
||||||
|
" WHERE p.platform = :platform" +
|
||||||
|
" AND p.partRole IN :roles" +
|
||||||
|
" AND p.deletedAt IS NULL")
|
||||||
|
|
||||||
|
@NamedQuery(name="Product.findProductsbyBrandByOffers", query="" +
|
||||||
|
" SELECT DISTINCT p FROM Product p" +
|
||||||
|
" LEFT JOIN FETCH p.brand b" +
|
||||||
|
" LEFT JOIN FETCH p.offers o" +
|
||||||
|
" WHERE p.platform = :platform" +
|
||||||
|
" AND p.deletedAt IS NULL")
|
||||||
|
|
||||||
public class Product {
|
public class Product {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@@ -68,7 +93,16 @@ public class Product {
|
|||||||
@Column(name = "platform_locked", nullable = false)
|
@Column(name = "platform_locked", nullable = false)
|
||||||
private Boolean platformLocked = false;
|
private Boolean platformLocked = false;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "product", fetch = FetchType.LAZY)
|
||||||
|
private Set<ProductOffer> offers = new HashSet<>();
|
||||||
|
|
||||||
|
public Set<ProductOffer> getOffers() {
|
||||||
|
return offers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOffers(Set<ProductOffer> offers) {
|
||||||
|
this.offers = offers;
|
||||||
|
}
|
||||||
|
|
||||||
// --- lifecycle hooks ---
|
// --- lifecycle hooks ---
|
||||||
|
|
||||||
@@ -236,4 +270,41 @@ public class Product {
|
|||||||
public void setConfiguration(ProductConfiguration configuration) {
|
public void setConfiguration(ProductConfiguration configuration) {
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
}
|
}
|
||||||
|
// Convenience: best offer price for Gunbuilder
|
||||||
|
public BigDecimal getBestOfferPrice() {
|
||||||
|
if (offers == null || offers.isEmpty()) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return offers.stream()
|
||||||
|
// pick sale_price if present, otherwise retail_price
|
||||||
|
.map(offer -> {
|
||||||
|
if (offer.getSalePrice() != null) {
|
||||||
|
return offer.getSalePrice();
|
||||||
|
}
|
||||||
|
return offer.getRetailPrice();
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.min(BigDecimal::compareTo)
|
||||||
|
.orElse(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convenience: URL for the best-priced offer
|
||||||
|
public String getBestOfferBuyUrl() {
|
||||||
|
if (offers == null || offers.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return offers.stream()
|
||||||
|
.sorted(Comparator.comparing(offer -> {
|
||||||
|
if (offer.getSalePrice() != null) {
|
||||||
|
return offer.getSalePrice();
|
||||||
|
}
|
||||||
|
return offer.getRetailPrice();
|
||||||
|
}, Comparator.nullsLast(BigDecimal::compareTo)))
|
||||||
|
.map(ProductOffer::getAffiliateUrl)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import org.hibernate.annotations.OnDeleteAction;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "product_offers")
|
@Table(name = "product_offers")
|
||||||
public class ProductOffer {
|
public class ProductOffer {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id", nullable = false)
|
@Column(name = "id", nullable = false)
|
||||||
@@ -26,16 +26,16 @@ public class ProductOffer {
|
|||||||
@JoinColumn(name = "merchant_id", nullable = false)
|
@JoinColumn(name = "merchant_id", nullable = false)
|
||||||
private Merchant merchant;
|
private Merchant merchant;
|
||||||
|
|
||||||
@Column(name = "avantlink_product_id", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "avantlink_product_id", nullable = false)
|
||||||
private String avantlinkProductId;
|
private String avantlinkProductId;
|
||||||
|
|
||||||
@Column(name = "sku", length = Integer.MAX_VALUE)
|
@Column(name = "sku")
|
||||||
private String sku;
|
private String sku;
|
||||||
|
|
||||||
@Column(name = "upc", length = Integer.MAX_VALUE)
|
@Column(name = "upc")
|
||||||
private String upc;
|
private String upc;
|
||||||
|
|
||||||
@Column(name = "buy_url", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "buy_url", nullable = false)
|
||||||
private String buyUrl;
|
private String buyUrl;
|
||||||
|
|
||||||
@Column(name = "price", nullable = false, precision = 10, scale = 2)
|
@Column(name = "price", nullable = false, precision = 10, scale = 2)
|
||||||
@@ -45,7 +45,7 @@ public class ProductOffer {
|
|||||||
private BigDecimal originalPrice;
|
private BigDecimal originalPrice;
|
||||||
|
|
||||||
@ColumnDefault("'USD'")
|
@ColumnDefault("'USD'")
|
||||||
@Column(name = "currency", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "currency", nullable = false)
|
||||||
private String currency;
|
private String currency;
|
||||||
|
|
||||||
@ColumnDefault("true")
|
@ColumnDefault("true")
|
||||||
@@ -60,6 +60,10 @@ public class ProductOffer {
|
|||||||
@Column(name = "first_seen_at", nullable = false)
|
@Column(name = "first_seen_at", nullable = false)
|
||||||
private OffsetDateTime firstSeenAt;
|
private OffsetDateTime firstSeenAt;
|
||||||
|
|
||||||
|
// -----------------------------------------------------
|
||||||
|
// Getters & setters
|
||||||
|
// -----------------------------------------------------
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -164,14 +168,26 @@ public class ProductOffer {
|
|||||||
this.firstSeenAt = firstSeenAt;
|
this.firstSeenAt = firstSeenAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------
|
||||||
|
// Helper Methods (used by Product entity)
|
||||||
|
// -----------------------------------------------------
|
||||||
|
|
||||||
|
public BigDecimal getSalePrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getRetailPrice() {
|
||||||
|
return originalPrice != null ? originalPrice : price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAffiliateUrl() {
|
||||||
|
return buyUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public BigDecimal getEffectivePrice() {
|
public BigDecimal getEffectivePrice() {
|
||||||
// Prefer a true sale price when it's lower than the original
|
|
||||||
if (price != null && originalPrice != null && price.compareTo(originalPrice) < 0) {
|
if (price != null && originalPrice != null && price.compareTo(originalPrice) < 0) {
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, use whatever is available
|
|
||||||
return price != null ? price : originalPrice;
|
return price != null ? price : originalPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,22 @@
|
|||||||
package group.goforward.ballistic.repos;
|
package group.goforward.ballistic.repos;
|
||||||
|
|
||||||
import group.goforward.ballistic.model.AffiliateCategoryMap;
|
import group.goforward.ballistic.model.CategoryMapping;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import group.goforward.ballistic.model.Merchant;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
public interface CategoryMappingRepository extends JpaRepository<AffiliateCategoryMap, Integer> {
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CategoryMappingRepository extends JpaRepository<CategoryMapping, Integer> {
|
||||||
|
|
||||||
|
// All mappings for a merchant, ordered nicely
|
||||||
|
List<CategoryMapping> findByMerchantIdOrderByRawCategoryPathAsc(Integer merchantId);
|
||||||
|
|
||||||
|
// Merchants that actually have mappings (for the dropdown)
|
||||||
|
@Query("""
|
||||||
|
select distinct cm.merchant
|
||||||
|
from CategoryMapping cm
|
||||||
|
order by cm.merchant.name asc
|
||||||
|
""")
|
||||||
|
List<Merchant> findDistinctMerchantsWithMappings();
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
package group.goforward.ballistic.repos;
|
package group.goforward.ballistic.repos;
|
||||||
|
|
||||||
import group.goforward.ballistic.model.PartCategory;
|
import group.goforward.ballistic.model.PartCategory;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import java.util.Optional;
|
|
||||||
|
import java.util.List;
|
||||||
public interface PartCategoryRepository extends JpaRepository<PartCategory, Integer> {
|
import java.util.Optional;
|
||||||
Optional<PartCategory> findBySlug(String slug);
|
|
||||||
|
public interface PartCategoryRepository extends JpaRepository<PartCategory, Integer> {
|
||||||
|
|
||||||
|
Optional<PartCategory> findBySlug(String slug);
|
||||||
|
|
||||||
|
List<PartCategory> findAllByOrderByGroupNameAscSortOrderAscNameAsc();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package group.goforward.ballistic.repos;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.PartRoleCategoryMapping;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface PartRoleCategoryMappingRepository extends JpaRepository<PartRoleCategoryMapping, Integer> {
|
||||||
|
|
||||||
|
List<PartRoleCategoryMapping> findAllByPlatformOrderByPartRoleAsc(String platform);
|
||||||
|
|
||||||
|
Optional<PartRoleCategoryMapping> findByPlatformAndPartRole(String platform, String partRole);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package group.goforward.ballistic.repos;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.PartRoleMapping;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface PartRoleMappingRepository extends JpaRepository<PartRoleMapping, Integer> {
|
||||||
|
|
||||||
|
// List mappings for a platform, ordered nicely for the UI
|
||||||
|
List<PartRoleMapping> findByPlatformOrderByPartRoleAsc(String platform);
|
||||||
|
}
|
||||||
@@ -1,53 +1,65 @@
|
|||||||
package group.goforward.ballistic.repos;
|
package group.goforward.ballistic.repos;
|
||||||
|
|
||||||
import group.goforward.ballistic.model.Product;
|
import group.goforward.ballistic.model.Brand;
|
||||||
import group.goforward.ballistic.model.Brand;
|
import group.goforward.ballistic.model.Product;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.List;
|
public interface ProductRepository extends JpaRepository<Product, Integer> {
|
||||||
import java.util.Collection;
|
|
||||||
|
// -------------------------------------------------
|
||||||
public interface ProductRepository extends JpaRepository<Product, Integer> {
|
// Used by MerchantFeedImportServiceImpl
|
||||||
|
// -------------------------------------------------
|
||||||
Optional<Product> findByUuid(UUID uuid);
|
|
||||||
|
List<Product> findAllByBrandAndMpn(Brand brand, String mpn);
|
||||||
boolean existsBySlug(String slug);
|
|
||||||
|
List<Product> findAllByBrandAndUpc(Brand brand, String upc);
|
||||||
List<Product> findAllByBrandAndMpn(Brand brand, String mpn);
|
|
||||||
|
boolean existsBySlug(String slug);
|
||||||
List<Product> findAllByBrandAndUpc(Brand brand, String upc);
|
|
||||||
|
// -------------------------------------------------
|
||||||
// All products for a given platform (e.g. "AR-15")
|
// Used by ProductController for platform views
|
||||||
List<Product> findByPlatform(String platform);
|
// -------------------------------------------------
|
||||||
|
|
||||||
// Products filtered by platform + part roles (e.g. upper-receiver, barrel, etc.)
|
@Query("""
|
||||||
List<Product> findByPlatformAndPartRoleIn(String platform, Collection<String> partRoles);
|
SELECT p
|
||||||
|
FROM Product p
|
||||||
// ---------- Optimized variants for Gunbuilder (fetch brand to avoid N+1) ----------
|
JOIN FETCH p.brand b
|
||||||
|
WHERE p.platform = :platform
|
||||||
@Query("""
|
AND p.deletedAt IS NULL
|
||||||
SELECT p
|
""")
|
||||||
FROM Product p
|
List<Product> findByPlatformWithBrand(@Param("platform") String platform);
|
||||||
JOIN FETCH p.brand b
|
|
||||||
WHERE p.platform = :platform
|
@Query(name="Products.findByPlatformWithBrand")
|
||||||
AND p.deletedAt IS NULL
|
List<Product> findByPlatformWithBrandNQ(@Param("platform") String platform);
|
||||||
""")
|
|
||||||
List<Product> findByPlatformWithBrand(@Param("platform") String platform);
|
@Query("""
|
||||||
|
SELECT p
|
||||||
@Query("""
|
FROM Product p
|
||||||
SELECT p
|
JOIN FETCH p.brand b
|
||||||
FROM Product p
|
WHERE p.platform = :platform
|
||||||
JOIN FETCH p.brand b
|
AND p.partRole IN :roles
|
||||||
WHERE p.platform = :platform
|
AND p.deletedAt IS NULL
|
||||||
AND p.partRole IN :partRoles
|
""")
|
||||||
AND p.deletedAt IS NULL
|
List<Product> findByPlatformAndPartRoleInWithBrand(
|
||||||
""")
|
@Param("platform") String platform,
|
||||||
List<Product> findByPlatformAndPartRoleInWithBrand(
|
@Param("roles") List<String> roles
|
||||||
@Param("platform") String platform,
|
);
|
||||||
@Param("partRoles") Collection<String> partRoles
|
|
||||||
);
|
// -------------------------------------------------
|
||||||
|
// Used by Gunbuilder service (if you wired this)
|
||||||
|
// -------------------------------------------------
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
SELECT DISTINCT p
|
||||||
|
FROM Product p
|
||||||
|
LEFT JOIN FETCH p.brand b
|
||||||
|
LEFT JOIN FETCH p.offers o
|
||||||
|
WHERE p.platform = :platform
|
||||||
|
AND p.deletedAt IS NULL
|
||||||
|
""")
|
||||||
|
List<Product> findSomethingForGunbuilder(@Param("platform") String platform);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package group.goforward.ballistic.services;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.PartCategory;
|
||||||
|
import group.goforward.ballistic.model.Product;
|
||||||
|
import group.goforward.ballistic.repos.ProductRepository;
|
||||||
|
import group.goforward.ballistic.web.dto.GunbuilderProductDto;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GunbuilderProductService {
|
||||||
|
|
||||||
|
private final ProductRepository productRepository;
|
||||||
|
private final PartCategoryResolverService partCategoryResolverService;
|
||||||
|
|
||||||
|
public GunbuilderProductService(
|
||||||
|
ProductRepository productRepository,
|
||||||
|
PartCategoryResolverService partCategoryResolverService
|
||||||
|
) {
|
||||||
|
this.productRepository = productRepository;
|
||||||
|
this.partCategoryResolverService = partCategoryResolverService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GunbuilderProductDto> listGunbuilderProducts(String platform) {
|
||||||
|
|
||||||
|
List<Product> products = productRepository.findSomethingForGunbuilder(platform);
|
||||||
|
|
||||||
|
return products.stream()
|
||||||
|
.map(p -> {
|
||||||
|
var maybeCategory = partCategoryResolverService
|
||||||
|
.resolveForPlatformAndPartRole(platform, p.getPartRole());
|
||||||
|
|
||||||
|
if (maybeCategory.isEmpty()) {
|
||||||
|
// you can also log here
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
PartCategory cat = maybeCategory.get();
|
||||||
|
|
||||||
|
return new GunbuilderProductDto(
|
||||||
|
p.getId(),
|
||||||
|
p.getName(),
|
||||||
|
p.getBrand().getName(),
|
||||||
|
platform,
|
||||||
|
p.getPartRole(),
|
||||||
|
p.getBestOfferPrice(),
|
||||||
|
p.getMainImageUrl(),
|
||||||
|
p.getBestOfferBuyUrl(),
|
||||||
|
cat.getSlug(),
|
||||||
|
cat.getGroupName()
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.filter(dto -> dto != null)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package group.goforward.ballistic.services;
|
||||||
|
|
||||||
|
import group.goforward.ballistic.model.PartCategory;
|
||||||
|
import group.goforward.ballistic.repos.PartCategoryRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PartCategoryResolverService {
|
||||||
|
|
||||||
|
private final PartCategoryRepository partCategoryRepository;
|
||||||
|
|
||||||
|
public PartCategoryResolverService(PartCategoryRepository partCategoryRepository) {
|
||||||
|
this.partCategoryRepository = partCategoryRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the canonical PartCategory for a given platform + partRole.
|
||||||
|
*
|
||||||
|
* For now we keep it simple:
|
||||||
|
* - We treat partRole as the slug (e.g. "barrel", "upper", "trigger").
|
||||||
|
* - Normalize to lower-kebab (spaces -> dashes, lowercased).
|
||||||
|
* - Look up by slug in part_categories.
|
||||||
|
*
|
||||||
|
* Later, if we want per-merchant / per-platform overrides using category_mappings,
|
||||||
|
* we can extend this method without changing callers.
|
||||||
|
*/
|
||||||
|
public Optional<PartCategory> resolveForPlatformAndPartRole(String platform, String partRole) {
|
||||||
|
if (partRole == null || partRole.isBlank()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalizedSlug = partRole
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(" ", "-");
|
||||||
|
|
||||||
|
return partCategoryRepository.findBySlug(normalizedSlug);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package group.goforward.ballistic.web.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public class GunbuilderProductDto {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private String brand;
|
||||||
|
private String platform;
|
||||||
|
private String partRole;
|
||||||
|
private BigDecimal price;
|
||||||
|
private String imageUrl;
|
||||||
|
private String buyUrl;
|
||||||
|
private String categorySlug;
|
||||||
|
private String categoryGroup;
|
||||||
|
|
||||||
|
public GunbuilderProductDto(
|
||||||
|
Integer id,
|
||||||
|
String name,
|
||||||
|
String brand,
|
||||||
|
String platform,
|
||||||
|
String partRole,
|
||||||
|
BigDecimal price,
|
||||||
|
String imageUrl,
|
||||||
|
String buyUrl,
|
||||||
|
String categorySlug,
|
||||||
|
String categoryGroup
|
||||||
|
) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.brand = brand;
|
||||||
|
this.platform = platform;
|
||||||
|
this.partRole = partRole;
|
||||||
|
this.price = price;
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
this.buyUrl = buyUrl;
|
||||||
|
this.categorySlug = categorySlug;
|
||||||
|
this.categoryGroup = categoryGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Getters only (DTOs are read-only in most cases) ---
|
||||||
|
public Integer getId() { return id; }
|
||||||
|
public String getName() { return name; }
|
||||||
|
public String getBrand() { return brand; }
|
||||||
|
public String getPlatform() { return platform; }
|
||||||
|
public String getPartRole() { return partRole; }
|
||||||
|
public BigDecimal getPrice() { return price; }
|
||||||
|
public String getImageUrl() { return imageUrl; }
|
||||||
|
public String getBuyUrl() { return buyUrl; }
|
||||||
|
public String getCategorySlug() { return categorySlug; }
|
||||||
|
public String getCategoryGroup() { return categoryGroup; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package group.goforward.ballistic.web.dto.admin;
|
||||||
|
|
||||||
|
public record AdminPartRoleMappingDto(
|
||||||
|
Integer id,
|
||||||
|
String platform,
|
||||||
|
String partRole,
|
||||||
|
String categorySlug,
|
||||||
|
String groupName,
|
||||||
|
String notes
|
||||||
|
) {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package group.goforward.ballistic.web.dto.admin;
|
||||||
|
|
||||||
|
public record CreatePartRoleMappingRequest(
|
||||||
|
String platform,
|
||||||
|
String partRole,
|
||||||
|
String categorySlug,
|
||||||
|
String notes
|
||||||
|
) {}
|
||||||
@@ -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
|
||||||
|
) {}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package group.goforward.ballistic.web.dto.admin;
|
||||||
|
|
||||||
|
public record PartCategoryDto(
|
||||||
|
Integer id,
|
||||||
|
String slug,
|
||||||
|
String name,
|
||||||
|
String description,
|
||||||
|
String groupName,
|
||||||
|
Integer sortOrder
|
||||||
|
) {}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package group.goforward.ballistic.web.dto.admin;
|
||||||
|
|
||||||
|
public record PartRoleMappingDto(
|
||||||
|
Integer id,
|
||||||
|
String platform,
|
||||||
|
String partRole,
|
||||||
|
String categorySlug,
|
||||||
|
String groupName,
|
||||||
|
String notes
|
||||||
|
) {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package group.goforward.ballistic.web.dto.admin;
|
||||||
|
|
||||||
|
public record PartRoleMappingRequest(
|
||||||
|
String platform,
|
||||||
|
String partRole,
|
||||||
|
String categorySlug,
|
||||||
|
String notes
|
||||||
|
) {}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package group.goforward.ballistic.web.dto.admin;
|
||||||
|
|
||||||
|
public record SimpleMerchantDto(
|
||||||
|
Integer id,
|
||||||
|
String name
|
||||||
|
) { }
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package group.goforward.ballistic.web.dto.admin;
|
||||||
|
|
||||||
|
public record UpdateMerchantCategoryMappingRequest(
|
||||||
|
Integer partCategoryId
|
||||||
|
) {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package group.goforward.ballistic.web.dto.admin;
|
||||||
|
|
||||||
|
public record UpdatePartRoleMappingRequest(
|
||||||
|
String platform,
|
||||||
|
String partRole,
|
||||||
|
String categorySlug,
|
||||||
|
String notes
|
||||||
|
) {}
|
||||||
Reference in New Issue
Block a user