diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/util/PostUtil.java b/src/main/java/org/gelecekbilimde/scienceplatform/media/util/SlugUtil.java similarity index 85% rename from src/main/java/org/gelecekbilimde/scienceplatform/post/util/PostUtil.java rename to src/main/java/org/gelecekbilimde/scienceplatform/media/util/SlugUtil.java index 04a14243..489e457d 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/util/PostUtil.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/media/util/SlugUtil.java @@ -1,4 +1,4 @@ -package org.gelecekbilimde.scienceplatform.post.util; +package org.gelecekbilimde.scienceplatform.media.util; import lombok.experimental.UtilityClass; @@ -6,7 +6,7 @@ import java.util.regex.Pattern; @UtilityClass -public class PostUtil { +public class SlugUtil { public String slugging(String text) { String normalizedText = Normalizer.normalize(text, Normalizer.Form.NFD) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/controller/CategoryController.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/controller/CategoryController.java index 5a999f38..7aaeafb4 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/controller/CategoryController.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/controller/CategoryController.java @@ -1,40 +1,100 @@ package org.gelecekbilimde.scienceplatform.post.controller; import jakarta.validation.Valid; +import jakarta.validation.constraints.Positive; import lombok.RequiredArgsConstructor; +import org.gelecekbilimde.scienceplatform.common.model.BasePage; +import org.gelecekbilimde.scienceplatform.common.model.response.PagingResponse; import org.gelecekbilimde.scienceplatform.common.model.response.SuccessResponse; import org.gelecekbilimde.scienceplatform.post.model.Category; +import org.gelecekbilimde.scienceplatform.post.model.mapper.CategoryToCategoriesResponseMapper; import org.gelecekbilimde.scienceplatform.post.model.mapper.CategoryToResponseMapper; +import org.gelecekbilimde.scienceplatform.post.model.mapper.CategoryToSummaryResponseMapper; import org.gelecekbilimde.scienceplatform.post.model.request.CategoryCreateRequest; +import org.gelecekbilimde.scienceplatform.post.model.request.CategoryListRequest; +import org.gelecekbilimde.scienceplatform.post.model.request.CategoryUpdateRequest; +import org.gelecekbilimde.scienceplatform.post.model.response.CategoriesResponse; import org.gelecekbilimde.scienceplatform.post.model.response.CategoryResponse; +import org.gelecekbilimde.scienceplatform.post.model.response.CategorySummaryResponse; import org.gelecekbilimde.scienceplatform.post.service.CategoryService; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; +@Validated @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/category") +@RequestMapping("/api/v1") class CategoryController { private final CategoryService categoryService; + private final CategoryToResponseMapper categoryToResponseMapper = CategoryToResponseMapper.initialize(); + private final CategoryToSummaryResponseMapper categoryToSummaryResponseMapper = CategoryToSummaryResponseMapper.initialize(); + private final CategoryToCategoriesResponseMapper categoryToCategoriesResponseMapper = CategoryToCategoriesResponseMapper.initialize(); + + + @PostMapping("/categories") + @PreAuthorize("hasAuthority('category:list')") + SuccessResponse> findAll(@RequestBody @Valid CategoryListRequest listRequest) { + + BasePage pageOfCategories = categoryService.findAll(listRequest); - @GetMapping - SuccessResponse> getCategoryList() { - List categories = categoryService.getCategories(); - List categoryResponses = categoryToResponseMapper.map(categories); - return SuccessResponse.success(categoryResponses); + final PagingResponse pageResponseOfCategory = PagingResponse + .builder() + .of(pageOfCategories) + .content( + categoryToCategoriesResponseMapper.map(pageOfCategories.getContent()) + ) + .build(); + + return SuccessResponse.success(pageResponseOfCategory); + } + + @GetMapping("/categories/summary") + SuccessResponse> findAllSummary() { + List categories = categoryService.findAll(); + List summaryResponses = categoryToSummaryResponseMapper + .map(categories); + return SuccessResponse.success(summaryResponses); + } + + @GetMapping("/category/{id}") + @PreAuthorize("hasAuthority('category:detail')") + SuccessResponse findById(@PathVariable @Positive Long id) { + Category category = categoryService.findById(id); + CategoryResponse categoryResponse = categoryToResponseMapper.map(category); + return SuccessResponse.success(categoryResponse); + } + + @PostMapping("/category") + @PreAuthorize("hasAuthority('category:create')") + SuccessResponse create(@RequestBody @Valid CategoryCreateRequest request) { + categoryService.create(request); + return SuccessResponse.success(); + } + + @PutMapping("/category/{id}") + @PreAuthorize("hasAuthority('category:update')") + SuccessResponse update(@PathVariable @Positive Long id, @RequestBody @Valid CategoryUpdateRequest request) { + categoryService.update(id, request); + return SuccessResponse.success(); } - @PostMapping("/create") - SuccessResponse createCategory(@RequestBody @Valid CategoryCreateRequest request) { - categoryService.createCategory(request); + @DeleteMapping("/category/{id}") + @PreAuthorize("hasAuthority('category:delete')") + SuccessResponse delete(@PathVariable @Positive Long id) { + categoryService.delete(id); return SuccessResponse.success(); } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/Category.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/Category.java index fe46011b..a4aad826 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/Category.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/Category.java @@ -14,10 +14,10 @@ public class Category extends BaseDomainModel { private Long id; private String name; - private Integer order; + private String description; + private Integer orderNumber; private String slug; private String icon; - private Long parentId; } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/entity/CategoryEntity.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/entity/CategoryEntity.java index b4f6d85d..63acebad 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/entity/CategoryEntity.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/entity/CategoryEntity.java @@ -32,8 +32,11 @@ public class CategoryEntity extends BaseEntity { @Column(name = "name") private String name; + @Column(name = "description") + private String description; + @Column(name = "order_number") - private Integer order; + private Integer orderNumber; @Column(name = "slug") private String slug; @@ -49,6 +52,6 @@ public class CategoryEntity extends BaseEntity { private CategoryEntity parent; public void increaseOrder() { - this.order++; + this.orderNumber++; } } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryCreateRequestToCategoryEntityMapper.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryCreateRequestToEntityMapper.java similarity index 58% rename from src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryCreateRequestToCategoryEntityMapper.java rename to src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryCreateRequestToEntityMapper.java index baff0450..c70a3e55 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryCreateRequestToCategoryEntityMapper.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryCreateRequestToEntityMapper.java @@ -7,10 +7,10 @@ import org.mapstruct.factory.Mappers; @Mapper -public interface CategoryCreateRequestToCategoryEntityMapper extends BaseMapper { +public interface CategoryCreateRequestToEntityMapper extends BaseMapper { - static CategoryCreateRequestToCategoryEntityMapper initialize() { - return Mappers.getMapper(CategoryCreateRequestToCategoryEntityMapper.class); + static CategoryCreateRequestToEntityMapper initialize() { + return Mappers.getMapper(CategoryCreateRequestToEntityMapper.class); } } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryEntityToCategoryMapper.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryEntityToDomainMapper.java similarity index 62% rename from src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryEntityToCategoryMapper.java rename to src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryEntityToDomainMapper.java index c0053d30..8ab654e2 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryEntityToCategoryMapper.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryEntityToDomainMapper.java @@ -7,10 +7,10 @@ import org.mapstruct.factory.Mappers; @Mapper -public interface CategoryEntityToCategoryMapper extends BaseMapper { +public interface CategoryEntityToDomainMapper extends BaseMapper { - static CategoryEntityToCategoryMapper initialize() { - return Mappers.getMapper(CategoryEntityToCategoryMapper.class); + static CategoryEntityToDomainMapper initialize() { + return Mappers.getMapper(CategoryEntityToDomainMapper.class); } } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryToCategoriesResponseMapper.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryToCategoriesResponseMapper.java new file mode 100644 index 00000000..2d7e5f23 --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryToCategoriesResponseMapper.java @@ -0,0 +1,16 @@ +package org.gelecekbilimde.scienceplatform.post.model.mapper; + +import org.gelecekbilimde.scienceplatform.common.model.mapper.BaseMapper; +import org.gelecekbilimde.scienceplatform.post.model.Category; +import org.gelecekbilimde.scienceplatform.post.model.response.CategoriesResponse; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CategoryToCategoriesResponseMapper extends BaseMapper { + + static CategoryToCategoriesResponseMapper initialize() { + return Mappers.getMapper(CategoryToCategoriesResponseMapper.class); + } + +} diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryToSummaryResponseMapper.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryToSummaryResponseMapper.java new file mode 100644 index 00000000..6ade7372 --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/CategoryToSummaryResponseMapper.java @@ -0,0 +1,16 @@ +package org.gelecekbilimde.scienceplatform.post.model.mapper; + +import org.gelecekbilimde.scienceplatform.common.model.mapper.BaseMapper; +import org.gelecekbilimde.scienceplatform.post.model.Category; +import org.gelecekbilimde.scienceplatform.post.model.response.CategorySummaryResponse; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CategoryToSummaryResponseMapper extends BaseMapper { + + static CategoryToSummaryResponseMapper initialize() { + return Mappers.getMapper(CategoryToSummaryResponseMapper.class); + } + +} diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/PostManagerControlRequestToPostProcessEntityMapper.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/PostManagerControlRequestToPostProcessEntityMapper.java index 50d1d195..27813cb7 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/PostManagerControlRequestToPostProcessEntityMapper.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/mapper/PostManagerControlRequestToPostProcessEntityMapper.java @@ -16,8 +16,7 @@ default PostProcessEntity mapForSaving(PostManagerControlRequest postManagerCont .content(postManagerControlRequest.getContent()) .categoryEntity(CategoryEntity.builder() .name(postManagerControlRequest.getCategory().getName()) - .order(postManagerControlRequest.getCategory().getOrder()) - .slug(postManagerControlRequest.getCategory().getSlug()) + .orderNumber(postManagerControlRequest.getCategory().getOrderNumber()) .icon(postManagerControlRequest.getCategory().getIcon()) .parentId(postManagerControlRequest.getCategory().getParentId()) .build()) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryCreateRequest.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryCreateRequest.java index 08803edf..ca2f29b0 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryCreateRequest.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryCreateRequest.java @@ -1,18 +1,32 @@ package org.gelecekbilimde.scienceplatform.post.model.request; import jakarta.validation.constraints.NotBlank; -import lombok.Builder; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; +import jakarta.validation.constraints.Size; import lombok.Getter; import lombok.Setter; @Getter @Setter -@Builder public class CategoryCreateRequest { + @NotBlank + @Size(min = 2, max = 50) private String name; - private Integer order; - private String slug; + + @NotBlank + @Size(min = 2, max = 255) + private String description; + + @NotNull + @Positive + private Integer orderNumber; + + @Size(max = 50) private String icon; + + @Positive private Long parentId; + } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryListRequest.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryListRequest.java new file mode 100644 index 00000000..fac9b5a6 --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryListRequest.java @@ -0,0 +1,23 @@ +package org.gelecekbilimde.scienceplatform.post.model.request; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.validation.constraints.AssertTrue; +import lombok.Getter; +import lombok.Setter; +import org.gelecekbilimde.scienceplatform.common.model.request.PagingRequest; + +import java.util.Set; + +@Getter +@Setter +public class CategoryListRequest extends PagingRequest { + + @JsonIgnore + @AssertTrue + @Override + public boolean isOrderPropertyAccepted() { + final Set acceptedFilterFields = Set.of("createdAt"); + return this.isPropertyAccepted(acceptedFilterFields); + } + +} diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryUpdateRequest.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryUpdateRequest.java new file mode 100644 index 00000000..e44e0143 --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/request/CategoryUpdateRequest.java @@ -0,0 +1,22 @@ +package org.gelecekbilimde.scienceplatform.post.model.request; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CategoryUpdateRequest { + + @NotBlank + @Size(min = 2, max = 50) + private String name; + + @NotBlank + @Size(min = 2, max = 255) + private String description; + + private Long parentId; + +} diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategoriesResponse.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategoriesResponse.java new file mode 100644 index 00000000..27e93a18 --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategoriesResponse.java @@ -0,0 +1,21 @@ +package org.gelecekbilimde.scienceplatform.post.model.response; + +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Getter +@Setter +public class CategoriesResponse { + + private Long id; + private Long parentId; + private String name; + private Long orderNumber; + private String slug; + private String icon; + private String createdBy; + private LocalDateTime createdAt; + +} diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategoryResponse.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategoryResponse.java index 2795bff8..c374375a 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategoryResponse.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategoryResponse.java @@ -1,19 +1,23 @@ package org.gelecekbilimde.scienceplatform.post.model.response; -import lombok.Builder; import lombok.Getter; import lombok.Setter; -@Builder +import java.time.LocalDateTime; + @Getter @Setter public class CategoryResponse { private Long id; private String name; - private Long order; + private String description; + private Long orderNumber; private String slug; private String icon; - private Long parentId; + private String createdBy; + private LocalDateTime createdAt; + private String updatedBy; + private LocalDateTime updatedAt; } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategorySummaryResponse.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategorySummaryResponse.java new file mode 100644 index 00000000..7be97cd2 --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/model/response/CategorySummaryResponse.java @@ -0,0 +1,17 @@ +package org.gelecekbilimde.scienceplatform.post.model.response; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CategorySummaryResponse { + + private Long id; + private Long parentId; + private String name; + private Long orderNumber; + private String slug; + private String icon; + +} diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/repository/CategoryRepository.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/repository/CategoryRepository.java index f070f533..ed0f6088 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/repository/CategoryRepository.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/repository/CategoryRepository.java @@ -2,15 +2,19 @@ import org.gelecekbilimde.scienceplatform.post.model.entity.CategoryEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import java.util.Optional; import java.util.Set; -public interface CategoryRepository extends JpaRepository { +public interface CategoryRepository extends JpaRepository, JpaSpecificationExecutor { Set findAllByParentId(Long parentId); - boolean existsByName(String name); + Optional findBySlug(String slug); + + boolean existsBySlug(String slug); boolean existsByParentId(Long parentId); diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/service/CategoryService.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/service/CategoryService.java index cd8e3063..0b0e2ec7 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/service/CategoryService.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/service/CategoryService.java @@ -1,29 +1,28 @@ package org.gelecekbilimde.scienceplatform.post.service; -import org.gelecekbilimde.scienceplatform.post.exception.CategoryAlreadyExistException; -import org.gelecekbilimde.scienceplatform.post.exception.CategoryNotFoundException; +import org.gelecekbilimde.scienceplatform.common.model.BasePage; import org.gelecekbilimde.scienceplatform.post.model.Category; import org.gelecekbilimde.scienceplatform.post.model.request.CategoryCreateRequest; +import org.gelecekbilimde.scienceplatform.post.model.request.CategoryListRequest; +import org.gelecekbilimde.scienceplatform.post.model.request.CategoryUpdateRequest; import java.util.List; public interface CategoryService { - List getCategories(); + BasePage findAll(CategoryListRequest listRequest); - Category getCategory(Long categoryId); + List findAll(); - /** - * Creates a new category. - * If there is a category with same order, it increases the order of the siblings (categories with the same parent). - * - * @param request The request object that contains the name,order and if it has a parent, parentId of the category. - * @throws CategoryAlreadyExistException throws if a category with the same name already exists. - * @throws CategoryNotFoundException throws if there is no category with the given parentId. - */ - void createCategory(CategoryCreateRequest request); + Category findById(Long id); - void changeCategoryName(Long id, String newName); + void create(CategoryCreateRequest request); + + void update(Long id, CategoryUpdateRequest request); + + void delete(Long id); - void deleteCategory(Long categoryId); } + + + diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/CategoryServiceImpl.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/CategoryServiceImpl.java index 8d5270f4..50e0e8c7 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/CategoryServiceImpl.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/CategoryServiceImpl.java @@ -1,21 +1,27 @@ package org.gelecekbilimde.scienceplatform.post.service.impl; import lombok.RequiredArgsConstructor; +import org.gelecekbilimde.scienceplatform.common.model.BasePage; +import org.gelecekbilimde.scienceplatform.media.util.SlugUtil; import org.gelecekbilimde.scienceplatform.post.exception.CategoryAlreadyExistException; import org.gelecekbilimde.scienceplatform.post.exception.CategoryHasChildException; import org.gelecekbilimde.scienceplatform.post.exception.CategoryNotFoundException; import org.gelecekbilimde.scienceplatform.post.exception.CategoryParentNotFoundException; import org.gelecekbilimde.scienceplatform.post.model.Category; import org.gelecekbilimde.scienceplatform.post.model.entity.CategoryEntity; -import org.gelecekbilimde.scienceplatform.post.model.mapper.CategoryCreateRequestToCategoryEntityMapper; -import org.gelecekbilimde.scienceplatform.post.model.mapper.CategoryEntityToCategoryMapper; +import org.gelecekbilimde.scienceplatform.post.model.mapper.CategoryCreateRequestToEntityMapper; +import org.gelecekbilimde.scienceplatform.post.model.mapper.CategoryEntityToDomainMapper; import org.gelecekbilimde.scienceplatform.post.model.request.CategoryCreateRequest; +import org.gelecekbilimde.scienceplatform.post.model.request.CategoryListRequest; +import org.gelecekbilimde.scienceplatform.post.model.request.CategoryUpdateRequest; import org.gelecekbilimde.scienceplatform.post.repository.CategoryRepository; import org.gelecekbilimde.scienceplatform.post.service.CategoryService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import java.util.List; -import java.util.Optional; @Service @RequiredArgsConstructor @@ -23,54 +29,102 @@ class CategoryServiceImpl implements CategoryService { private final CategoryRepository categoryRepository; - private final CategoryEntityToCategoryMapper categoryEntityToCategoryMapper = CategoryEntityToCategoryMapper.initialize(); - private final CategoryCreateRequestToCategoryEntityMapper categoryCreateRequestToCategoryEntityMapper = CategoryCreateRequestToCategoryEntityMapper.initialize(); + + private final CategoryEntityToDomainMapper categoryEntityToDomainMapper = CategoryEntityToDomainMapper.initialize(); + private final CategoryCreateRequestToEntityMapper categoryCreateRequestToEntityMapper = CategoryCreateRequestToEntityMapper.initialize(); + + + @Override + public BasePage findAll(final CategoryListRequest listRequest) { + + final Pageable pageable = listRequest.getPageable().toPageable(); + + final Page categoriesPage = categoryRepository + .findAll(Specification.allOf(), pageable); + + final List categories = categoryEntityToDomainMapper + .map(categoriesPage.getContent()); + + return BasePage.of( + categoriesPage, + categories + ); + } + @Override - public List getCategories() { - return categoryEntityToCategoryMapper.map(categoryRepository.findAll()); + public List findAll() { + List categories = categoryRepository.findAll(); + return categoryEntityToDomainMapper.map(categories); } + @Override - public Category getCategory(Long id) { - Optional category = categoryRepository.findById(id); - if (category.isEmpty()) { - throw new CategoryNotFoundException(id); - } - return categoryEntityToCategoryMapper.map(category.get()); + public Category findById(Long id) { + CategoryEntity categoryEntity = categoryRepository.findById(id) + .orElseThrow(() -> new CategoryNotFoundException(id)); + return categoryEntityToDomainMapper.map(categoryEntity); } + @Override - public void createCategory(CategoryCreateRequest request) { - if (categoryRepository.existsByName(request.getName())) { + public void create(CategoryCreateRequest request) { + + final String slug = SlugUtil.slugging(request.getName()); + final boolean exists = categoryRepository.existsBySlug(slug); + if (exists) { throw new CategoryAlreadyExistException(request.getName()); } + if (request.getParentId() != null && !categoryRepository.existsById(request.getParentId())) { throw new CategoryParentNotFoundException(request.getParentId()); } List categories = categoryRepository.findAllByParentId(request.getParentId()).stream().toList(); for (CategoryEntity categoryEntity : categories) { - if (categoryEntity.getOrder() >= request.getOrder()) { + if (categoryEntity.getOrderNumber() >= request.getOrderNumber()) { categoryEntity.increaseOrder(); } } - categoryRepository.save(categoryCreateRequestToCategoryEntityMapper.map(request)); + CategoryEntity categoryEntity = categoryCreateRequestToEntityMapper.map(request); + categoryEntity.setSlug(slug); + categoryRepository.save(categoryEntity); categoryRepository.saveAll(categories); } + @Override - public void changeCategoryName(Long id, String newName) { + public void update(Long id, CategoryUpdateRequest request) { + CategoryEntity categoryEntity = categoryRepository.findById(id) .orElseThrow(() -> new CategoryNotFoundException(id)); - categoryEntity.setName(newName); + final String slug = SlugUtil.slugging(request.getName()); + final boolean exists = categoryRepository.findBySlug(slug) + .filter(existingCategory -> !existingCategory.getId().equals(id)) + .isPresent(); + if (exists) { + throw new CategoryAlreadyExistException(request.getName()); + } + + categoryEntity.setName(request.getName()); + categoryEntity.setSlug(slug); + + if (request.getParentId() != null) { + if (!categoryRepository.existsById(request.getParentId())) { + throw new CategoryParentNotFoundException(request.getParentId()); + } + categoryEntity.setParentId(request.getParentId()); + } + + categoryEntity.setDescription(request.getDescription()); + categoryRepository.save(categoryEntity); } @Override - public void deleteCategory(Long id) { + public void delete(Long id) { CategoryEntity categoryEntity = categoryRepository.findById(id) .orElseThrow(() -> new CategoryNotFoundException(id)); diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/PostProcessServiceImpl.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/PostProcessServiceImpl.java index 4e83608c..5c2a92b3 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/PostProcessServiceImpl.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/PostProcessServiceImpl.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import org.gelecekbilimde.scienceplatform.auth.model.Identity; +import org.gelecekbilimde.scienceplatform.media.util.SlugUtil; import org.gelecekbilimde.scienceplatform.post.exception.PostNotAvailableToUpdateException; import org.gelecekbilimde.scienceplatform.post.exception.PostNotFoundByIdException; import org.gelecekbilimde.scienceplatform.post.exception.PostProcessNotFoundByPostIdException; @@ -16,7 +17,6 @@ import org.gelecekbilimde.scienceplatform.post.repository.PostProcessRepository; import org.gelecekbilimde.scienceplatform.post.repository.PostRepository; import org.gelecekbilimde.scienceplatform.post.service.PostProcessService; -import org.gelecekbilimde.scienceplatform.post.util.PostUtil; import org.springframework.security.access.AuthorizationServiceException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -82,7 +82,7 @@ private void updateControl(PostProcessEntity postProcessEntity, PostManagerContr //TODO: Category kontrolü yapılacak - postManagerControlRequest.setSlug(PostUtil.slugging(postManagerControlRequest.getHeader())); + postManagerControlRequest.setSlug(SlugUtil.slugging(postManagerControlRequest.getHeader())); final PostProcessEntity postProcessEntityBuild = postManagerControlRequestToPostProcessEntityMapper.mapForSaving(postManagerControlRequest, identity.getUserId(), true); postProcessRepository.save(postProcessEntityBuild); diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/PostServiceImpl.java b/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/PostServiceImpl.java index 2e80d4b9..c5067984 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/PostServiceImpl.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/post/service/impl/PostServiceImpl.java @@ -2,8 +2,9 @@ import lombok.RequiredArgsConstructor; import org.gelecekbilimde.scienceplatform.auth.model.Identity; -import org.gelecekbilimde.scienceplatform.common.model.BaseSpecification; import org.gelecekbilimde.scienceplatform.common.model.BasePage; +import org.gelecekbilimde.scienceplatform.common.model.BaseSpecification; +import org.gelecekbilimde.scienceplatform.media.util.SlugUtil; import org.gelecekbilimde.scienceplatform.post.model.Post; import org.gelecekbilimde.scienceplatform.post.model.entity.PostEntity; import org.gelecekbilimde.scienceplatform.post.model.enums.Process; @@ -16,7 +17,6 @@ import org.gelecekbilimde.scienceplatform.post.service.PostMediaService; import org.gelecekbilimde.scienceplatform.post.service.PostProcessService; import org.gelecekbilimde.scienceplatform.post.service.PostService; -import org.gelecekbilimde.scienceplatform.post.util.PostUtil; import org.springframework.data.domain.Page; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; @@ -45,7 +45,7 @@ public Post save(PostCreateRequest postCreateRequest) { } postCreateRequest.setLastProcess(Process.CREATE); - postCreateRequest.setSlug(PostUtil.slugging(postCreateRequest.getHeader())); + postCreateRequest.setSlug(SlugUtil.slugging(postCreateRequest.getHeader())); final PostEntity postEntity = createRequestToEntityMapper.map(postCreateRequest); postEntity.setUserId(identity.getUserId()); diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/entity/UserFollowEntity.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/entity/UserFollowEntity.java index 7db30189..e550389a 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/entity/UserFollowEntity.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/entity/UserFollowEntity.java @@ -24,5 +24,4 @@ public class UserFollowEntity extends BaseEntity { @Column(name = "followed_user_id") private String followedUserId; - } diff --git a/src/main/resources/db/migration/V1__ddl.sql b/src/main/resources/db/migration/V1__ddl.sql index 8941b065..53ebcf2a 100644 --- a/src/main/resources/db/migration/V1__ddl.sql +++ b/src/main/resources/db/migration/V1__ddl.sql @@ -1,321 +1,324 @@ create table if not exists gb_permission ( - id varchar(36) not null primary key, - description varchar(255) not null, - name varchar(255) not null, - is_hidden boolean, - status varchar(25), - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint c__gb_permission__status check ( status in ('ACTIVE', 'PASSIVE')) + id varchar(36) not null primary key, + description varchar(255) not null, + name varchar(255) not null, + is_hidden boolean, + status varchar(25), + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint c__gb_permission__status check ( status in ('ACTIVE', 'PASSIVE')) ); create table if not exists gb_role ( - id varchar(36) not null primary key, - name varchar(55) not null, - description varchar(255) not null, - status varchar(25) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint u__gb_role__name unique (name), - constraint c__gb_role__status check (status in ('ACTIVE', 'PASSIVE')) + id varchar(36) not null primary key, + name varchar(55) not null, + description varchar(255) not null, + status varchar(25) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint u__gb_role__name unique (name), + constraint c__gb_role__status check (status in ('ACTIVE', 'PASSIVE')) ); create table if not exists gb_role_permission ( - id bigint generated always as identity primary key, - role_id varchar(36) not null, - permission_id varchar(36) not null, - constraint u__gb_role_permission__role_id__permission_id unique (role_id, permission_id), - constraint fk__gb_role_permission__role_id foreign key (role_id) references gb_role (id), - constraint fk__gb_role_permission__permission_id foreign key (permission_id) references gb_permission (id) + id bigint generated always as identity primary key, + role_id varchar(36) not null, + permission_id varchar(36) not null, + constraint u__gb_role_permission__role_id__permission_id unique (role_id, permission_id), + constraint fk__gb_role_permission__role_id foreign key (role_id) references gb_role (id), + constraint fk__gb_role_permission__permission_id foreign key (permission_id) references gb_permission (id) ); create table if not exists gb_user ( - id varchar(36) not null primary key, - role_id varchar(36) not null, - email varchar(255) not null, - password varchar(255) not null, - first_name varchar(25) not null, - last_name varchar(25) not null, - avatar_path varchar(255), - biography text, - birth_date date, - degree varchar(30), - gender varchar(25), - status varchar(25) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_user__role_id foreign key (role_id) references gb_role (id), - constraint c__gb_user__status check ( status in ('NOT_VERIFIED', 'VERIFIED', 'BLOCKED')) + id varchar(36) not null primary key, + role_id varchar(36) not null, + email varchar(255) not null, + password varchar(255) not null, + first_name varchar(25) not null, + last_name varchar(25) not null, + avatar_path varchar(255), + biography text, + birth_date date, + degree varchar(30), + gender varchar(25), + status varchar(25) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_user__role_id foreign key (role_id) references gb_role (id), + constraint c__gb_user__status check ( status in ('NOT_VERIFIED', 'VERIFIED', 'BLOCKED')) ); create table if not exists gb_user_verification ( - id varchar(36) not null primary key, - user_id varchar(36) not null, - status varchar(25) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_user_verification__user_id foreign key (user_id) references gb_user (id) + id varchar(36) not null primary key, + user_id varchar(36) not null, + status varchar(25) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_user_verification__user_id foreign key (user_id) references gb_user (id) ); create table if not exists gb_user_follow ( - id bigint generated always as identity primary key, - follower_user_id - varchar(36) not null, - followed_user_id varchar(36) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint u__gb_user_follow__follower_user_id__followed_user_id unique (follower_user_id, followed_user_id), - constraint fk__gb_user_follow__follower_user_id foreign key (follower_user_id) references gb_user (id), - constraint fk__gb_user_follow__followed_user_id foreign key (followed_user_id) references gb_user (id) + id bigint generated always as identity primary key, + follower_user_id + varchar(36) not null, + followed_user_id varchar(36) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint u__gb_user_follow__follower_user_id__followed_user_id unique (follower_user_id, followed_user_id), + constraint fk__gb_user_follow__follower_user_id foreign key (follower_user_id) references gb_user (id), + constraint fk__gb_user_follow__followed_user_id foreign key (followed_user_id) references gb_user (id) ); create table if not exists gb_notification_token ( - id bigint generated always as identity primary key, - user_id varchar(36), - device_id varchar(255), - device_token text, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - CONSTRAINT fk__gb_notification_token__user_id FOREIGN KEY (user_id) REFERENCES gb_user (id) + id bigint generated always as identity primary key, + user_id varchar(36), + device_id varchar(255), + device_token text, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + CONSTRAINT fk__gb_notification_token__user_id FOREIGN KEY (user_id) REFERENCES gb_user (id) ); create table if not exists gb_category ( - id bigint generated always as identity primary key, - order_number integer not null, - parent_id bigint, - name varchar(36) not null, - slug varchar(36) not null, - icon varchar(36), - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0) + id bigint generated always as identity primary key, + order_number integer not null, + parent_id bigint, + name varchar(50) not null, + description varchar(255) not null, + slug varchar(50) not null, + icon varchar(50), + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint u__gb_category__name unique (name), + constraint u__gb_category__slug unique (slug) ); create table if not exists gb_media_group ( - id bigint generated always as identity primary key, - user_id varchar(36) not null, - parent_id bigint, - name varchar(50), - status varchar(25), - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_media__user_id foreign key (user_id) references gb_user (id), - constraint c__gb_media_group__status check ( status in ('ACTIVE', 'DELETED')) + id bigint generated always as identity primary key, + user_id varchar(36) not null, + parent_id bigint, + name varchar(50), + status varchar(25), + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_media__user_id foreign key (user_id) references gb_user (id), + constraint c__gb_media_group__status check ( status in ('ACTIVE', 'DELETED')) ); create table if not exists gb_media ( - id bigint generated always as identity primary key, - user_id varchar(36) not null, - group_id bigint, - type varchar(25) not null, - is_shared boolean not null default false, - title varchar(100) not null, - content_type varchar(25) not null, - url varchar(255) not null, - status varchar(25), - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_media__user_id foreign key (user_id) references gb_user (id), - constraint fk__gb_media__group_id foreign key (group_id) references gb_media_group (id), - constraint c__gb_media__status check ( status in ('ACTIVE', 'DELETED')) + id bigint generated always as identity primary key, + user_id varchar(36) not null, + group_id bigint, + type varchar(25) not null, + is_shared boolean not null default false, + title varchar(100) not null, + content_type varchar(25) not null, + url varchar(255) not null, + status varchar(25), + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_media__user_id foreign key (user_id) references gb_user (id), + constraint fk__gb_media__group_id foreign key (group_id) references gb_media_group (id), + constraint c__gb_media__status check ( status in ('ACTIVE', 'DELETED')) ); create table if not exists gb_post ( - id varchar(36) not null primary key, - category_id bigint not null, - user_id varchar(36) not null, - header varchar(255) not null, - content text not null, - like_count integer default 0, - slug varchar(255) not null, - is_active boolean default false, - copyright_control boolean default false, - typo_control boolean default false, - dangerous_control boolean default false, - last_process varchar(25), - status varchar(25), - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_post__user_id foreign key (user_id) references gb_user (id), - constraint fk__gb_post__category_id foreign key (category_id) references gb_category (id), - constraint c__gb_post__status check ( status in ('ACTIVE', 'PASSIVE')) + id varchar(36) not null primary key, + category_id bigint not null, + user_id varchar(36) not null, + header varchar(255) not null, + content text not null, + like_count integer default 0, + slug varchar(255) not null, + is_active boolean default false, + copyright_control boolean default false, + typo_control boolean default false, + dangerous_control boolean default false, + last_process varchar(25), + status varchar(25), + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_post__user_id foreign key (user_id) references gb_user (id), + constraint fk__gb_post__category_id foreign key (category_id) references gb_category (id), + constraint c__gb_post__status check ( status in ('ACTIVE', 'PASSIVE')) ); create table if not exists gb_post_like ( - id bigint generated always as identity primary key, - post_id varchar(36) not null, - user_id varchar(36) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint u__gb_post_like__post_id__user_id unique (post_id, user_id), - constraint fk__gb_post_like__user_id foreign key (user_id) references gb_user (id), - constraint fk__gb_post_like__post_id foreign key (post_id) references gb_post (id) + id bigint generated always as identity primary key, + post_id varchar(36) not null, + user_id varchar(36) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint u__gb_post_like__post_id__user_id unique (post_id, user_id), + constraint fk__gb_post_like__user_id foreign key (user_id) references gb_user (id), + constraint fk__gb_post_like__post_id foreign key (post_id) references gb_post (id) ); create table if not exists gb_comment ( - id bigint generated always as identity primary key, - post_id varchar(36) not null, - message text not null, - like_count integer null default 0, - status varchar(25) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_comment__post_id foreign key (post_id) references gb_post (id), - constraint c__gb_comment__status check ( status in ('DONE', 'DELETED')) + id bigint generated always as identity primary key, + post_id varchar(36) not null, + message text not null, + like_count integer null default 0, + status varchar(25) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_comment__post_id foreign key (post_id) references gb_post (id), + constraint c__gb_comment__status check ( status in ('DONE', 'DELETED')) ); create table if not exists gb_post_media ( - id bigint generated always as identity primary key, - media_id bigint not null, - post_id varchar(36) not null, - is_cover boolean not null default false, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_post_media__post_id foreign key (post_id) references gb_post (id), - constraint fk__gb_post_media__media_id foreign key (media_id) references gb_media (id) + id bigint generated always as identity primary key, + media_id bigint not null, + post_id varchar(36) not null, + is_cover boolean not null default false, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_post_media__post_id foreign key (post_id) references gb_post (id), + constraint fk__gb_post_media__media_id foreign key (media_id) references gb_media (id) ); create table if not exists gb_post_process ( - id bigint generated always as identity primary key, - post_id varchar(36) not null, - user_id varchar(36) not null, - content text not null, - header varchar(255) not null, - message text, - process varchar(25), - slug varchar(255) not null, - copyright_control boolean default false, - typo_control boolean default false, - dangerous_control boolean default false, - done boolean, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_post_process__post_id foreign key (post_id) references gb_post (id), - constraint fk__gb_post_process__user_id foreign key (user_id) references gb_user (id) + id bigint generated always as identity primary key, + post_id varchar(36) not null, + user_id varchar(36) not null, + content text not null, + header varchar(255) not null, + message text, + process varchar(25), + slug varchar(255) not null, + copyright_control boolean default false, + typo_control boolean default false, + dangerous_control boolean default false, + done boolean, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_post_process__post_id foreign key (post_id) references gb_post (id), + constraint fk__gb_post_process__user_id foreign key (user_id) references gb_user (id) ); create table if not exists gb_invalid_token ( - id bigint generated always as identity primary key, - token_id varchar(36) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0) + id bigint generated always as identity primary key, + token_id varchar(36) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0) ); create table if not exists gb_setting ( - id bigint generated always as identity primary key, - group_name varchar(100) not null, - name varchar(100) not null, - definition text, - is_hidden boolean, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint u__gb_setting__name__group_name unique (group_name, name) + id bigint generated always as identity primary key, + group_name varchar(100) not null, + name varchar(100) not null, + definition text, + is_hidden boolean, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint u__gb_setting__name__group_name unique (group_name, name) ); create table if not exists gb_ticket ( - id varchar(36) not null primary key, - user_id varchar(36) not null, - subject varchar(255) not null, - description text not null, - status varchar(50) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_ticket__user_id foreign key (user_id) references gb_user (id), - constraint c__gb_ticket__subject check ( status in ('TECHNICAL', 'POST', 'YOUR_QUESTION_REQUESTS', 'FEEDBACK', - 'COLLABORATION', 'OTHER')), - constraint c__gb_ticket__status check ( status in ('OPEN', 'IN_PROGRESS', 'ON_HOLD', 'CLOSED', - 'REOPENED', 'CANCELED', 'RESOLVED')) + id varchar(36) not null primary key, + user_id varchar(36) not null, + subject varchar(255) not null, + description text not null, + status varchar(50) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_ticket__user_id foreign key (user_id) references gb_user (id), + constraint c__gb_ticket__subject check ( status in ('TECHNICAL', 'POST', 'YOUR_QUESTION_REQUESTS', 'FEEDBACK', + 'COLLABORATION', 'OTHER')), + constraint c__gb_ticket__status check ( status in ('OPEN', 'IN_PROGRESS', 'ON_HOLD', 'CLOSED', + 'REOPENED', 'CANCELED', 'RESOLVED')) ); create table if not exists gb_ticket_message ( - id bigint generated always as identity primary key, - ticket_id varchar(36) not null, - user_id varchar(36) not null, - message text, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0) + id bigint generated always as identity primary key, + ticket_id varchar(36) not null, + user_id varchar(36) not null, + message text, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0) ); create table if not exists gb_role_application ( - id varchar(36) not null primary key, - user_id varchar(36) not null, - role_id varchar(36) not null, - status varchar(10) not null, - created_by varchar(255) not null, - created_at timestamp(0) not null, - updated_by varchar(255), - updated_at timestamp(0), - constraint fk__gb_role_application__user_id foreign key (user_id) references gb_user (id), - constraint fk__gb_role_application__role_id foreign key (role_id) references gb_role (id), - constraint c__gb_role_application__status check ( status in ('IN_REVIEW', 'CANCELLED', 'APPROVED', 'REJECTED')) + id varchar(36) not null primary key, + user_id varchar(36) not null, + role_id varchar(36) not null, + status varchar(10) not null, + created_by varchar(255) not null, + created_at timestamp(0) not null, + updated_by varchar(255), + updated_at timestamp(0), + constraint fk__gb_role_application__user_id foreign key (user_id) references gb_user (id), + constraint fk__gb_role_application__role_id foreign key (role_id) references gb_role (id), + constraint c__gb_role_application__status check ( status in ('IN_REVIEW', 'CANCELLED', 'APPROVED', 'REJECTED')) ); diff --git a/src/main/resources/db/migration/V2__dml.sql b/src/main/resources/db/migration/V2__dml.sql index 740727a9..5e1609d8 100644 --- a/src/main/resources/db/migration/V2__dml.sql +++ b/src/main/resources/db/migration/V2__dml.sql @@ -78,6 +78,22 @@ values ('171ca9a7-311d-40b6-b538-024b5870471a', 'Moderatör Olmak İçin Kendi A insert into gb_permission (id, description, name, is_hidden, created_by, created_at) values ('d7a49ea4-fae1-4dac-8e07-c1d823841b50', 'Kendi Adına Var Olan Rol Başvurusunu İptal Eder', 'role:application:cancel:self', false, 'gelecekbilimde', current_timestamp); +insert into gb_permission (id, description, name, is_hidden, created_by, created_at) +values ('5a32defb-14c0-44b2-b518-fb482ca768e6', 'Kategorileri Listeler', + 'category:list', false, 'gelecekbilimde', current_timestamp); +insert into gb_permission (id, description, name, is_hidden, created_by, created_at) +values ('9e25ae21-9b35-4511-bdd5-c0e2ec96b8d4', 'Kategori Detayını Görüntüler', + 'category:detail', false, 'gelecekbilimde', current_timestamp); +insert into gb_permission (id, description, name, is_hidden, created_by, created_at) +values ('6db2bee3-5f77-4782-8d87-6baa22048a47', 'Kategori Oluşturur', + 'category:create', false, 'gelecekbilimde', current_timestamp); +insert into gb_permission (id, description, name, is_hidden, created_by, created_at) +values ('0920ce1f-fdda-4f73-963f-304b98d7af2f', 'Kategori Günceller', + 'category:update', false, 'gelecekbilimde', current_timestamp); +insert into gb_permission (id, description, name, is_hidden, created_by, created_at) +values ('889c4c62-73c8-465f-a6e3-ee54ab790007', 'Kategori Siler', + 'category:delete', false, 'gelecekbilimde', current_timestamp); + insert into gb_role_permission (role_id, permission_id) @@ -100,6 +116,16 @@ insert into gb_role_permission (role_id, permission_id) values ('c147b5c2-87f7-4bb7-a165-368f639d8c3c', '0352ee79-e844-4e91-968f-c9f3e4a27515'); insert into gb_role_permission (role_id, permission_id) values ('c147b5c2-87f7-4bb7-a165-368f639d8c3c', '31366d9d-5282-4fe2-9d45-4551e114bc7d'); +insert into gb_role_permission (role_id, permission_id) +values ('c147b5c2-87f7-4bb7-a165-368f639d8c3c', '5a32defb-14c0-44b2-b518-fb482ca768e6'); +insert into gb_role_permission (role_id, permission_id) +values ('c147b5c2-87f7-4bb7-a165-368f639d8c3c', '9e25ae21-9b35-4511-bdd5-c0e2ec96b8d4'); +insert into gb_role_permission (role_id, permission_id) +values ('c147b5c2-87f7-4bb7-a165-368f639d8c3c', '6db2bee3-5f77-4782-8d87-6baa22048a47'); +insert into gb_role_permission (role_id, permission_id) +values ('c147b5c2-87f7-4bb7-a165-368f639d8c3c', '0920ce1f-fdda-4f73-963f-304b98d7af2f'); +insert into gb_role_permission (role_id, permission_id) +values ('c147b5c2-87f7-4bb7-a165-368f639d8c3c', '889c4c62-73c8-465f-a6e3-ee54ab790007'); INSERT INTO gb_role_permission (role_id, permission_id) VALUES ('1ed82a25-d348-4576-b4e6-1f2a7c430ca7', '9c032c81-5c0e-4d08-b3a6-e7d524b354cb'); @@ -123,6 +149,16 @@ insert into gb_role_permission (role_id, permission_id) values ('1ed82a25-d348-4576-b4e6-1f2a7c430ca7', 'e7c0ddb6-5371-449f-841e-65b14f53f200'); insert into gb_role_permission (role_id, permission_id) values ('1ed82a25-d348-4576-b4e6-1f2a7c430ca7', 'f8217f8d-8d67-496f-8761-53201e690078'); +insert into gb_role_permission (role_id, permission_id) +values ('1ed82a25-d348-4576-b4e6-1f2a7c430ca7', '5a32defb-14c0-44b2-b518-fb482ca768e6'); +insert into gb_role_permission (role_id, permission_id) +values ('1ed82a25-d348-4576-b4e6-1f2a7c430ca7', '9e25ae21-9b35-4511-bdd5-c0e2ec96b8d4'); +insert into gb_role_permission (role_id, permission_id) +values ('1ed82a25-d348-4576-b4e6-1f2a7c430ca7', '6db2bee3-5f77-4782-8d87-6baa22048a47'); +insert into gb_role_permission (role_id, permission_id) +values ('1ed82a25-d348-4576-b4e6-1f2a7c430ca7', '0920ce1f-fdda-4f73-963f-304b98d7af2f'); +insert into gb_role_permission (role_id, permission_id) +values ('1ed82a25-d348-4576-b4e6-1f2a7c430ca7', '889c4c62-73c8-465f-a6e3-ee54ab790007'); INSERT INTO gb_role_permission (role_id, permission_id) VALUES ('4d98a76c-9841-4aea-b296-2f27aa610b6c', '9c032c81-5c0e-4d08-b3a6-e7d524b354cb'); @@ -176,35 +212,32 @@ values ('e3a1a32d-fcd7-46f0-bb2b-201df6b2b808', '2902d3c0-040e-47f6-b894-e724842 -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (0, 1, 'Fizik', 'fizik', null, - 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (1, 1, 'Biyoloji', 'biyoloji', null, +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (0, 1, 'Fizik', 'Fizik kategorisidir.', 'fizik', null, 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (2, 1, 'Kimya', 'kimya', null, +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (1, 1, 'Biyoloji', 'Biyoloji kategorisidir.', 'biyoloji', null, 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (1, null, 'Teknoloji', 'teknoloji', 'cpu', +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (2, 1, 'Kimya', 'Kimya kategorisidir.', 'kimya', null, 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (2, null, 'Felsefe', 'felsefe', 'book', +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (1, null, 'Teknoloji', 'Teknoloji kategorisidir.', 'teknoloji', 'cpu', 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (1, 6, 'Ontoloji', 'ontoloji', null, +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (2, null, 'Felsefe', 'Felsefe kategorisidir.', 'felsefe', 'book', 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (2, 6, 'Ahlak Felsefesi', 'ahlak-felsefesi', null, +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (1, 6, 'Ontoloji', 'Ontoloji kategorisidir.', 'ontoloji', null, 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (0, 6, 'Epistemoloji', 'epistelomoji', null, +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (2, 6, 'Ahlak Felsefesi', 'Ahlak Felsefesi kategorisidir.', 'ahlak-felsefesi', null, 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (5, null, 'testCat', 'test-category', 'g', +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (0, 6, 'Epistemoloji', 'Epistemoloji kategorisidir.', 'epistemoloji', null, 'gelecekbilimde', current_timestamp); -insert into gb_category (order_number, parent_id, name, slug, icon, created_by, created_at) -values (0, null, 'Bilim', 'bilim', 'flask-conical', +insert into gb_category (order_number, parent_id, name, description, slug, icon, created_by, created_at) +values (0, null, 'Bilim', 'Bilim kategorisidir.', 'bilim', 'flask-conical', 'gelecekbilimde', current_timestamp);