-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from Kernel360/develop
메인 브랜치로 merge 24.03.04
- Loading branch information
Showing
58 changed files
with
1,049 additions
and
210 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
39 changes: 39 additions & 0 deletions
39
module-admin/src/main/java/com/kernel360/brand/code/BrandBusinessCode.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,39 @@ | ||
package com.kernel360.brand.code; | ||
|
||
import com.kernel360.code.BusinessCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public enum BrandBusinessCode implements BusinessCode { | ||
|
||
SUCCESS_FOUND_BRAND_LIST(HttpStatus.OK.value(),"BMB001","브랜드 목록 조회 성공"), | ||
SUCCESS_FOUND_EXACT_BRAND(HttpStatus.OK.value(),"BMB002","브랜드 상세 조회 성공"), | ||
SUCCESS_CREATED_BRAND(HttpStatus.CREATED.value(), "BMB003","브랜드 추가 성공" ), | ||
SUCCESS_DELETED_BRAND(HttpStatus.OK.value(), "BMB004","브랜드 삭제 성공"), | ||
SUCCESS_UPDATED_BRAND(HttpStatus.OK.value(), "BMB005","브랜드 업데이트 성공" ); | ||
|
||
|
||
private final int status; | ||
private final String code; | ||
private final String message; | ||
|
||
BrandBusinessCode(int status, String code, String message) { | ||
this.status = status; | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
module-admin/src/main/java/com/kernel360/brand/code/BrandErrorCode.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,34 @@ | ||
package com.kernel360.brand.code; | ||
|
||
import com.kernel360.code.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public enum BrandErrorCode implements ErrorCode { | ||
FAILED_CANNOT_FOUND_ANY_BRAND(HttpStatus.NOT_FOUND.value(), "EBC001", "브랜드 목록이 비어있음"), | ||
FAILED_ALREADY_EXISTS_BRAND(HttpStatus.BAD_REQUEST.value(), "EBC002", "생성하려는 브랜드가 이미 존재함"), | ||
FAILED_CANNOT_FOUND_EXACT_BRAND(HttpStatus.NOT_FOUND.value(), "EBC003", "변경하려는 브랜드가 존재하지 않음"); | ||
private final int status; | ||
private final String code; | ||
private final String message; | ||
|
||
BrandErrorCode(int status, String code, String message) { | ||
this.status = status; | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
module-admin/src/main/java/com/kernel360/brand/controller/BrandController.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,97 @@ | ||
package com.kernel360.brand.controller; | ||
|
||
import com.kernel360.brand.code.BrandBusinessCode; | ||
import com.kernel360.brand.dto.BrandDto; | ||
import com.kernel360.brand.service.BrandServiceImpl; | ||
import com.kernel360.response.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
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.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/admin/brands") | ||
@RequiredArgsConstructor | ||
public class BrandController { | ||
|
||
private final BrandServiceImpl brandService; | ||
|
||
@GetMapping | ||
public ResponseEntity<ApiResponse<Object>> getBrandList() { | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_FOUND_BRAND_LIST, brandService.findAllBrand()); | ||
} | ||
|
||
@GetMapping("/brand") | ||
public ResponseEntity<ApiResponse<Object>> findBrandById(@RequestBody BrandDto brandDto) { | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_FOUND_EXACT_BRAND, | ||
brandService.findBrandByBrandId(brandDto.brandNo())); | ||
} | ||
|
||
@GetMapping("/brandName") | ||
public ResponseEntity<ApiResponse<BrandDto>> findBrandByBrandName(@RequestBody BrandDto brandDto) { | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_FOUND_EXACT_BRAND, | ||
brandService.findBrandByBrandName(brandDto.brandName())); | ||
} | ||
|
||
|
||
@PostMapping("/brand") | ||
public ResponseEntity<ApiResponse<Object>> createBrand(@RequestBody BrandDto brandDto) { | ||
brandService.createBrand(brandDto); | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_CREATED_BRAND); | ||
} | ||
|
||
@DeleteMapping("/brand") | ||
public ResponseEntity<ApiResponse<BrandDto>> deleteBrand(@RequestBody BrandDto brandDto) { | ||
brandService.deleteBrand(brandDto.brandNo()); | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_DELETED_BRAND); | ||
} | ||
|
||
@PutMapping("/brand") | ||
public ResponseEntity<ApiResponse<BrandDto>> updateAll(@RequestBody BrandDto brandDto) { | ||
brandService.updateBrand(brandDto); | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_UPDATED_BRAND); | ||
} | ||
|
||
@PatchMapping("/description") | ||
public ResponseEntity<ApiResponse<BrandDto>> updateBrandDescription(@RequestBody BrandDto brandDto) { | ||
brandService.updateBrandDescription(brandDto.brandNo(), brandDto.description()); | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_UPDATED_BRAND); | ||
} | ||
|
||
@PatchMapping("/brandName") | ||
public ResponseEntity<ApiResponse<BrandDto>> updateBrandName(@RequestBody BrandDto brandDto) { | ||
brandService.updateBrandName(brandDto.brandNo(), brandDto.brandName()); | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_UPDATED_BRAND); | ||
} | ||
|
||
@PatchMapping("/companyName") | ||
public ResponseEntity<ApiResponse<BrandDto>> updateBrandCompanyName(@RequestBody BrandDto brandDto) { | ||
brandService.updateBrandCompanyName(brandDto.brandNo(), brandDto.companyName()); | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_UPDATED_BRAND); | ||
} | ||
|
||
@PatchMapping("/nationName") | ||
public ResponseEntity<ApiResponse<BrandDto>> updateBrandNationName(@RequestBody BrandDto brandDto) { | ||
brandService.updateBrandNationName(brandDto.brandNo(), brandDto.nationName()); | ||
|
||
return ApiResponse.toResponseEntity(BrandBusinessCode.SUCCESS_UPDATED_BRAND); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
module-admin/src/main/java/com/kernel360/brand/dto/BrandDto.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,20 @@ | ||
package com.kernel360.brand.dto; | ||
|
||
import com.kernel360.brand.entity.Brand; | ||
|
||
public record BrandDto(Long brandNo, String brandName, String companyName, String description, String nationName) { | ||
|
||
public static BrandDto of(Long brandNo, String brandName, String companyName, String description, String nationName) { | ||
return new BrandDto(brandNo, brandName, companyName, description, nationName); | ||
} | ||
|
||
public static BrandDto of(String brandName, String companyName, String description, String nationName) { | ||
return new BrandDto(null, brandName, companyName, description, nationName); | ||
} | ||
|
||
public static BrandDto fromEntity(Brand brand) { | ||
return new BrandDto(brand.getBrandNo(), brand.getBrandName(), brand.getCompanyName(), brand.getDescription(), | ||
brand.getNationName()); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
module-admin/src/main/java/com/kernel360/brand/service/BrandService.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,28 @@ | ||
package com.kernel360.brand.service; | ||
|
||
import com.kernel360.brand.dto.BrandDto; | ||
import java.util.List; | ||
import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException; | ||
|
||
public interface BrandService { | ||
|
||
List<BrandDto> findAllBrand(); | ||
|
||
BrandDto findBrandByBrandId(Long brandNo); | ||
|
||
BrandDto findBrandByBrandName(String brandName); | ||
|
||
void createBrand(BrandDto brandDto); | ||
|
||
void deleteBrand(final Long brandNo); | ||
|
||
void updateBrand(BrandDto brandDto); | ||
|
||
void updateBrandDescription(final Long brandNo, final String description); | ||
|
||
void updateBrandName(final Long brandNo, final String brandName); | ||
|
||
void updateBrandCompanyName(final Long brandNo, final String companyName); | ||
|
||
void updateBrandNationName(final Long brandNo, final String nationName); | ||
} |
133 changes: 133 additions & 0 deletions
133
module-admin/src/main/java/com/kernel360/brand/service/BrandServiceImpl.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,133 @@ | ||
package com.kernel360.brand.service; | ||
|
||
import com.kernel360.brand.code.BrandErrorCode; | ||
import com.kernel360.brand.dto.BrandDto; | ||
import com.kernel360.brand.entity.Brand; | ||
import com.kernel360.brand.repository.BrandRepository; | ||
import com.kernel360.exception.BusinessException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class BrandServiceImpl implements BrandService { | ||
|
||
private final BrandRepository brandRepository; | ||
|
||
@Override | ||
public List<BrandDto> findAllBrand() { | ||
List<Brand> brandList = brandRepository.findAll(); | ||
if (brandList.isEmpty()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_CANNOT_FOUND_ANY_BRAND); | ||
} | ||
|
||
return brandList.stream() | ||
.map(BrandDto::fromEntity) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public BrandDto findBrandByBrandId(Long brandNo) { | ||
Optional<Brand> brand = brandRepository.findBrandByBrandNo(brandNo); | ||
if (brand.isEmpty()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_CANNOT_FOUND_EXACT_BRAND); | ||
} | ||
|
||
return BrandDto.fromEntity(brand.get()); | ||
} | ||
|
||
@Override | ||
public BrandDto findBrandByBrandName(String brandName) { | ||
Brand brand = brandRepository.findBrandByBrandName(brandName) | ||
.orElseThrow(() -> new BusinessException( | ||
BrandErrorCode.FAILED_CANNOT_FOUND_EXACT_BRAND)); | ||
|
||
return BrandDto.fromEntity(brand); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void createBrand(BrandDto brandDto) { | ||
Optional<Brand> brand = brandRepository.findBrandByBrandName(brandDto.brandName()); | ||
if (brand.isPresent()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_ALREADY_EXISTS_BRAND); | ||
} | ||
|
||
brandRepository.save(Brand.toEntity(brandDto.brandName(), brandDto.companyName(), brandDto.description(), brandDto.nationName())); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void deleteBrand(Long brandNo) { | ||
Optional<Brand> brand = brandRepository.findBrandByBrandNo(brandNo); | ||
if (brand.isEmpty()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_CANNOT_FOUND_EXACT_BRAND); | ||
} | ||
|
||
brandRepository.delete(brand.get()); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void updateBrand(BrandDto brandDto) { | ||
Optional<Brand> brand = brandRepository.findBrandByBrandNo(brandDto.brandNo()); | ||
if (brand.isEmpty()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_CANNOT_FOUND_EXACT_BRAND); | ||
} | ||
|
||
brand.get() | ||
.updateAll(brandDto.brandName(), brandDto.companyName(), brandDto.description(), brandDto.nationName()); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void updateBrandDescription(Long brandNo,String description) { | ||
Optional<Brand> brand = brandRepository.findBrandByBrandNo(brandNo); | ||
if (brand.isEmpty()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_CANNOT_FOUND_EXACT_BRAND); | ||
} | ||
|
||
brand.get().updateDescription(description); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void updateBrandName(Long brandNo, String brandName) { | ||
Optional<Brand> brand = brandRepository.findBrandByBrandNo(brandNo); | ||
if (brand.isEmpty()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_CANNOT_FOUND_EXACT_BRAND); | ||
} | ||
|
||
brand.get().updateBrandName(brandName); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void updateBrandCompanyName(Long brandNo, String companyName) { | ||
Optional<Brand> brand = brandRepository.findBrandByBrandNo(brandNo); | ||
if (brand.isEmpty()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_CANNOT_FOUND_EXACT_BRAND); | ||
} | ||
|
||
brand.get().updateBrandCompanyName(companyName); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void updateBrandNationName(Long brandNo, String nationName) { | ||
Optional<Brand> brand = brandRepository.findBrandByBrandNo(brandNo); | ||
if (brand.isEmpty()) { | ||
throw new BusinessException(BrandErrorCode.FAILED_CANNOT_FOUND_EXACT_BRAND); | ||
} | ||
|
||
brand.get().updateBrandNationName(nationName); | ||
} | ||
|
||
|
||
} |
18 changes: 18 additions & 0 deletions
18
module-admin/src/main/java/com/kernel360/config/AdminAuditConfig.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,18 @@ | ||
package com.kernel360.config; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.util.Optional; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
@Configuration | ||
public class AdminAuditConfig implements AuditorAware<String> { | ||
@Override | ||
public Optional<String> getCurrentAuditor() { | ||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); | ||
String createId = Optional.ofNullable(request.getParameter("id")).orElse("module-admin"); | ||
|
||
return Optional.of(createId); | ||
} | ||
} |
Oops, something went wrong.