Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GBS-23 | Implemented category management functionalities #163

Merged
merged 30 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
da60464
feat: Implemented category management functionalities
aleyna-yildizli Oct 4, 2024
1cea198
fix: Corrected typos in various files
aleyna-yildizli Oct 4, 2024
5e995a9
Merge remote-tracking branch 'origin/main' into enhancement/category-…
agitrubard Oct 5, 2024
8fa5480
chore: Apply review suggestions and minor adjustments to category con…
aleyna-yildizli Oct 5, 2024
774ded9
feat: Add category summary endpoint
aleyna-yildizli Oct 12, 2024
f0aabf6
GBS-23 | `category:get:list` Permission Has Been Renamed as `category…
agitrubard Oct 12, 2024
3e659c0
GBS-23 | `category:get:id` Permission Has Been Renamed as `category:d…
agitrubard Oct 12, 2024
3cde984
GBS-23 | Descriptions of Category Permissions Have Been Refactored
agitrubard Oct 12, 2024
7601367
GBS-23 | Category Endpoints Have Been Renamed
agitrubard Oct 12, 2024
94b97ee
GBS-23 | `CategoryController.getCategoryList()` Method Has Been Renam…
agitrubard Oct 12, 2024
36740af
GBS-23 | `CategoryController.getCategorySummary()` Method Has Been Re…
agitrubard Oct 12, 2024
f63d855
GBS-23 | `@Validated` Annotation Has Been Added to `CategoryControlle…
agitrubard Oct 12, 2024
7798878
GBS-23 | `findAllSummary()` Method Has Been Removed Because It's Dupl…
agitrubard Oct 12, 2024
e13c593
GBS-23 | `@Builder` Annotation Has Been Removed from `CategoryRespons…
agitrubard Oct 12, 2024
c7398df
GBS-23 | `parentId` Field Has Been Added to `CategorySummaryResponse`…
agitrubard Oct 12, 2024
502c149
GBS-23 | `createdBy`, `createdAt`, `updatedBy`, `updatedAt` Fields Ha…
agitrubard Oct 12, 2024
3f7d310
GBS-23 | `CategoryServiceImpl.findAll()` Method Has Been Refactored
agitrubard Oct 12, 2024
127672b
GBS-23 | Pagination and Order Have Been Integrated to Category List E…
agitrubard Oct 12, 2024
f2b0c2f
GBS-23 | `slug` Variable Has Been Deleted from `CategoryCreateRequest…
agitrubard Oct 12, 2024
af207e8
GBS-23 | `PostUtil` Class Has Been Renamed as `SlugUtil`
agitrubard Oct 12, 2024
184d9d8
GBS-23 | `SlugUtil` Class Has Been Moved to `common.util` Package
agitrubard Oct 12, 2024
15cc224
GBS-23 | Slug Has Been Generated in Category Create Flow
agitrubard Oct 12, 2024
88a0164
GBS-23 | Slug Has Been Generated in Category Update Flow
agitrubard Oct 12, 2024
669a973
GBS-23 | Unique Constraint Has Been Added to `name` and `slug` Fields…
agitrubard Oct 12, 2024
dcd6895
GBS-23 | `V1__ddl.sql` File Has Been Formatted
agitrubard Oct 12, 2024
a627630
GBS-23 | `CategoryToCategorySummaryResponseMapper` Class Has Been Ren…
agitrubard Oct 12, 2024
273a9f3
GBS-23 | `CategoryEntityToCategoryMapper` Class Has Been Renamed as `…
agitrubard Oct 12, 2024
f56e446
GBS-23 | `CategoryCreateRequestToCategoryEntityMapper` Class Has Been…
agitrubard Oct 12, 2024
739d784
Merge remote-tracking branch 'origin/main' into enhancement/category-…
agitrubard Oct 12, 2024
29e67c4
GBS-23 | `CategoryServiceImpl.findById()` Method Has Been Refactored …
agitrubard Oct 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.gelecekbilimde.scienceplatform.post.util;
package org.gelecekbilimde.scienceplatform.media.util;

import lombok.experimental.UtilityClass;

import java.text.Normalizer;
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PagingResponse<CategoriesResponse>> findAll(@RequestBody @Valid CategoryListRequest listRequest) {

BasePage<Category> pageOfCategories = categoryService.findAll(listRequest);

@GetMapping
SuccessResponse<List<CategoryResponse>> getCategoryList() {
List<Category> categories = categoryService.getCategories();
List<CategoryResponse> categoryResponses = categoryToResponseMapper.map(categories);
return SuccessResponse.success(categoryResponses);
final PagingResponse<CategoriesResponse> pageResponseOfCategory = PagingResponse
.<CategoriesResponse>builder()
.of(pageOfCategories)
.content(
categoryToCategoriesResponseMapper.map(pageOfCategories.getContent())
)
.build();

return SuccessResponse.success(pageResponseOfCategory);
}

@GetMapping("/categories/summary")
SuccessResponse<List<CategorySummaryResponse>> findAllSummary() {
List<Category> categories = categoryService.findAll();
List<CategorySummaryResponse> summaryResponses = categoryToSummaryResponseMapper
.map(categories);
return SuccessResponse.success(summaryResponses);
}

@GetMapping("/category/{id}")
@PreAuthorize("hasAuthority('category:detail')")
SuccessResponse<CategoryResponse> 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<Void> create(@RequestBody @Valid CategoryCreateRequest request) {
categoryService.create(request);
return SuccessResponse.success();
}

@PutMapping("/category/{id}")
@PreAuthorize("hasAuthority('category:update')")
SuccessResponse<Void> update(@PathVariable @Positive Long id, @RequestBody @Valid CategoryUpdateRequest request) {
categoryService.update(id, request);
return SuccessResponse.success();
}

@PostMapping("/create")
SuccessResponse<Void> createCategory(@RequestBody @Valid CategoryCreateRequest request) {
categoryService.createCategory(request);
@DeleteMapping("/category/{id}")
@PreAuthorize("hasAuthority('category:delete')")
SuccessResponse<Void> delete(@PathVariable @Positive Long id) {
categoryService.delete(id);
return SuccessResponse.success();
}

agitrubard marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class Category extends BaseDomainModel {

private Long id;
private String name;
private Integer order;
private String description;
private Integer orderNumber;
agitrubard marked this conversation as resolved.
Show resolved Hide resolved
private String slug;
private String icon;

private Long parentId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public class CategoryEntity extends BaseEntity {
@Column(name = "name")
private String name;

@Column(name = "description")
private String description;
agitrubard marked this conversation as resolved.
Show resolved Hide resolved

@Column(name = "order_number")
private Integer order;
private Integer orderNumber;

@Column(name = "slug")
private String slug;
Expand All @@ -49,6 +52,6 @@ public class CategoryEntity extends BaseEntity {
private CategoryEntity parent;

public void increaseOrder() {
this.order++;
this.orderNumber++;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.mapstruct.factory.Mappers;

@Mapper
public interface CategoryCreateRequestToCategoryEntityMapper extends BaseMapper<CategoryCreateRequest, CategoryEntity> {
public interface CategoryCreateRequestToEntityMapper extends BaseMapper<CategoryCreateRequest, CategoryEntity> {

static CategoryCreateRequestToCategoryEntityMapper initialize() {
return Mappers.getMapper(CategoryCreateRequestToCategoryEntityMapper.class);
static CategoryCreateRequestToEntityMapper initialize() {
return Mappers.getMapper(CategoryCreateRequestToEntityMapper.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.mapstruct.factory.Mappers;

@Mapper
public interface CategoryEntityToCategoryMapper extends BaseMapper<CategoryEntity, Category> {
public interface CategoryEntityToDomainMapper extends BaseMapper<CategoryEntity, Category> {

static CategoryEntityToCategoryMapper initialize() {
return Mappers.getMapper(CategoryEntityToCategoryMapper.class);
static CategoryEntityToDomainMapper initialize() {
return Mappers.getMapper(CategoryEntityToDomainMapper.class);
}

}
Original file line number Diff line number Diff line change
@@ -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<Category, CategoriesResponse> {

static CategoryToCategoriesResponseMapper initialize() {
return Mappers.getMapper(CategoryToCategoriesResponseMapper.class);
}

}
Original file line number Diff line number Diff line change
@@ -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<Category, CategorySummaryResponse> {

static CategoryToSummaryResponseMapper initialize() {
return Mappers.getMapper(CategoryToSummaryResponseMapper.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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<String> acceptedFilterFields = Set.of("createdAt");
return this.isPropertyAccepted(acceptedFilterFields);
}
agitrubard marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;

}
agitrubard marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.gelecekbilimde.scienceplatform.post.model.response;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class CategorySummaryResponse {
agitrubard marked this conversation as resolved.
Show resolved Hide resolved
agitrubard marked this conversation as resolved.
Show resolved Hide resolved

private Long id;
private Long parentId;
private String name;
private Long orderNumber;
private String slug;
private String icon;
agitrubard marked this conversation as resolved.
Show resolved Hide resolved

}
Loading