-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 프로젝트 분리 : admin-service(mvc+jpa), user-service(webflux+r2dbc)
- Loading branch information
1 parent
d281aa8
commit 10fde93
Showing
147 changed files
with
4,724 additions
and
3,173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
id 'org.springframework.boot' version '2.6.2' | ||
id 'io.spring.dependency-management' version '1.0.11.RELEASE' | ||
} | ||
|
||
dependencies { | ||
implementation project(path: ':common', configuration: 'default') | ||
|
||
developmentOnly 'org.springframework.boot:spring-boot-devtools' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-jdbc' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
|
||
runtimeOnly 'mysql:mysql-connector-java' | ||
|
||
testImplementation 'com.h2database:h2' | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' | ||
|
||
// lombok | ||
annotationProcessor 'org.projectlombok:lombok' | ||
compileOnly 'org.projectlombok:lombok' | ||
testImplementation 'org.projectlombok:lombok' | ||
} |
11 changes: 11 additions & 0 deletions
11
admin-service/src/main/java/org/bbaemin/AdminServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.bbaemin; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class AdminServiceApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(AdminServiceApplication.class, args); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
admin-service/src/main/java/org/bbaemin/admin/category/controller/CategoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.bbaemin.admin.category.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.bbaemin.admin.category.controller.request.CreateCategoryRequest; | ||
import org.bbaemin.admin.category.controller.request.UpdateCategoryRequest; | ||
import org.bbaemin.admin.category.controller.response.CategoryResponse; | ||
import org.bbaemin.admin.category.service.CategoryService; | ||
import org.bbaemin.admin.category.vo.Category; | ||
import org.bbaemin.config.response.ApiResult; | ||
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; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/categories") | ||
public class CategoryController { | ||
|
||
private final CategoryService categoryService; | ||
|
||
@GetMapping | ||
public ApiResult<List<CategoryResponse>> listCategory() { | ||
return ApiResult.ok(categoryService.listCategory().stream() | ||
.map(category -> CategoryResponse.builder() | ||
.code(category.getCode()) | ||
.name(category.getName()) | ||
.description(category.getDescription()) | ||
.parentCode(category.getParent().getCode()) | ||
.build()) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
@GetMapping("/{categoryId}") | ||
public ApiResult<CategoryResponse> getCategory(@PathVariable Long categoryId) { | ||
Category category = categoryService.getCategory(categoryId); | ||
return ApiResult.ok(CategoryResponse.builder() | ||
.code(category.getCode()) | ||
.name(category.getName()) | ||
.description(category.getDescription()) | ||
.parentCode(category.getParent().getCode()) | ||
.build()); | ||
} | ||
|
||
@PostMapping | ||
public ApiResult<CategoryResponse> createCategory(@Validated @RequestBody CreateCategoryRequest createCategoryRequest) { | ||
|
||
Category category = Category.builder() | ||
.code(createCategoryRequest.getCode()) | ||
.name(createCategoryRequest.getName()) | ||
.description(createCategoryRequest.getDescription()) | ||
.parent(createCategoryRequest.getParentId() != null ? | ||
categoryService.getCategory(createCategoryRequest.getParentId()) : null) | ||
.build(); | ||
Category saved = categoryService.createCategory(category); | ||
CategoryResponse categoryResponse = CategoryResponse.builder() | ||
.code(saved.getCode()) | ||
.name(saved.getName()) | ||
.description(saved.getDescription()) | ||
.parentCode(saved.getParent().getCode()) | ||
.build(); | ||
return ApiResult.created(categoryResponse); | ||
} | ||
|
||
@PutMapping("/{categoryId}") | ||
public ApiResult<CategoryResponse> updateCategory(@PathVariable Long categoryId, @Validated @RequestBody UpdateCategoryRequest updateCategoryRequest) { | ||
|
||
Category updated = categoryService.updateCategory(categoryId, | ||
updateCategoryRequest.getCode(), | ||
updateCategoryRequest.getName(), | ||
updateCategoryRequest.getDescription(), | ||
updateCategoryRequest.getParentId()); | ||
|
||
CategoryResponse categoryResponse = CategoryResponse.builder() | ||
.code(updated.getCode()) | ||
.name(updated.getName()) | ||
.description(updated.getDescription()) | ||
.parentCode(updated.getParent().getCode()) | ||
.build(); | ||
return ApiResult.ok(categoryResponse); | ||
} | ||
|
||
@DeleteMapping("/{categoryId}") | ||
public ApiResult<Long> deleteCategory(@PathVariable Long categoryId) { | ||
return ApiResult.ok(categoryService.deleteCategory(categoryId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ervice/src/main/java/org/bbaemin/admin/category/controller/response/CategoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.bbaemin.admin.category.controller.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CategoryResponse { | ||
|
||
private Integer code; | ||
private String name; | ||
private String description; | ||
private Integer parentCode; | ||
|
||
@Builder | ||
private CategoryResponse(Integer code, String name, String description, Integer parentCode) { | ||
this.code = code; | ||
this.name = name; | ||
this.description = description; | ||
this.parentCode = parentCode; | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...tegory/repository/CategoryRepository.java → ...tegory/repository/CategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
admin-service/src/main/java/org/bbaemin/admin/category/service/CategoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.bbaemin.admin.category.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.bbaemin.admin.category.repository.CategoryRepository; | ||
import org.bbaemin.admin.category.vo.Category; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CategoryService { | ||
|
||
private final CategoryRepository categoryRepository; | ||
|
||
|
||
@Transactional(readOnly = true) | ||
public List<Category> listCategory() { | ||
return categoryRepository.findAll(); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public Category getCategory(Long categoryId) { | ||
return categoryRepository.findById(categoryId) | ||
.orElseThrow(() -> new NoSuchElementException("categoryId : " + categoryId)); | ||
} | ||
|
||
@Transactional | ||
public Category createCategory(Category category) { | ||
return categoryRepository.save(category); | ||
} | ||
|
||
@Transactional | ||
public Category updateCategory(Long categoryId, Integer code, String name, String description, Long parentId) { | ||
|
||
Category updated = getCategory(categoryId); | ||
updated.setCode(code); | ||
updated.setName(name); | ||
updated.setDescription(description); | ||
|
||
if (!ObjectUtils.isEmpty(parentId)) { | ||
Category parent = getCategory(parentId); | ||
updated.setParent(parent); | ||
} | ||
|
||
return updated; | ||
} | ||
|
||
@Transactional | ||
public Long deleteCategory(Long categoryId) { | ||
categoryRepository.deleteById(categoryId); | ||
return categoryId; | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
admin-service/src/main/java/org/bbaemin/admin/category/vo/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.bbaemin.admin.category.vo; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.bbaemin.admin.delivery.vo.Store; | ||
import org.bbaemin.admin.item.vo.Item; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.Lob; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Category { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "category_id") | ||
private Long categoryId; | ||
|
||
@Column(name = "code", nullable = false, unique = true) | ||
private Integer code; | ||
|
||
@Column(name = "name") | ||
private String name; | ||
|
||
@Column(name = "description") | ||
@Lob | ||
private String description; | ||
|
||
@JoinColumn(name = "parent_id") | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
private Category parent; | ||
|
||
@OneToMany(mappedBy = "parent", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, orphanRemoval = true) | ||
private List<Category> children = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "storeCategory") | ||
private List<Store> storeList = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "itemCategory") | ||
private List<Item> itemList = new ArrayList<>(); | ||
|
||
@Builder | ||
private Category(Long categoryId, Integer code, String name, String description, Category parent, List<Category> children, List<Store> storeList, List<Item> itemList) { | ||
this.categoryId = categoryId; | ||
this.code = code; | ||
this.name = name; | ||
this.description = description; | ||
if (!Objects.isNull(parent)) { | ||
this.parent = parent; | ||
parent.addChildren(this); | ||
} | ||
this.children = children; | ||
this.storeList = storeList; | ||
this.itemList = itemList; | ||
} | ||
|
||
public void setCode(Integer code) { | ||
this.code = code; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public void setParent(Category parent) { | ||
this.parent = parent; | ||
parent.addChildren(this); | ||
} | ||
|
||
public void addChildren(Category category) { | ||
if (this.children == null) { | ||
this.children = new ArrayList<>(); | ||
} | ||
this.children.add(category); | ||
} | ||
|
||
public void addStore(Store store) { | ||
if (this.storeList == null) { | ||
this.storeList = new ArrayList<>(); | ||
} | ||
this.storeList.add(store); | ||
} | ||
|
||
public void addItem(Item item) { | ||
if (this.itemList == null) { | ||
this.itemList = new ArrayList<>(); | ||
} | ||
this.itemList.add(item); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
admin-service/src/main/java/org/bbaemin/admin/delivery/controller/DeliveryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.bbaemin.admin.delivery.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.bbaemin.admin.delivery.service.DeliveryService; | ||
import org.bbaemin.config.response.ApiResult; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequestMapping("/api/v1/delivery") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class DeliveryController { | ||
|
||
private final DeliveryService deliveryService; | ||
|
||
@GetMapping("/fee") | ||
public ApiResult<Integer> getDeliveryFee(@RequestParam(name = "orderAmount") Integer orderAmount) { | ||
int deliveryFee = deliveryService.getDeliveryFee(orderAmount); | ||
return ApiResult.ok(deliveryFee); | ||
} | ||
} |
Oops, something went wrong.