Skip to content

Commit

Permalink
Merge pull request #234 from KJBig/feature/S2D-18
Browse files Browse the repository at this point in the history
Feature/s2 d 18
  • Loading branch information
KJBig authored Jul 26, 2023
2 parents e7810c2 + ee37be3 commit d453599
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 58 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'com.google.api-client:google-api-client:2.2.0'
implementation 'com.google.auth:google-auth-library-oauth2-http:1.16.0'
// implementation 'com.fasterxml.jackson.core:jackson-core:2.14.2'
// implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'

// QueryDsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
Expand All @@ -61,6 +59,10 @@ dependencies {

// AWS S3
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.232'

// DtoMapper
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
}


Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/sluv/server/domain/brand/mapper/BrandMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sluv.server.domain.brand.mapper;

import com.sluv.server.domain.brand.dto.BrandSearchResDto;
import com.sluv.server.domain.brand.entity.Brand;
import org.mapstruct.Mapper;

@Mapper(componentModel = "spring")
public interface BrandMapper {

BrandSearchResDto toBrandSearchResDto(Brand brand);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sluv.server.domain.brand.mapper;

import com.sluv.server.domain.brand.dto.NewBrandPostReqDto;
import com.sluv.server.domain.brand.dto.NewBrandPostResDto;
import com.sluv.server.domain.brand.entity.NewBrand;
import com.sluv.server.domain.brand.enums.NewBrandStatus;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface NewBrandMapper {

@Mapping(target = "id", ignore = true)
@Mapping(target = "brandName", source = "newBrandPostReqDto.newBrandName")
@Mapping(target = "newBrandStatus", source = "newBrandStatus", defaultValue = "ACTIVE")
NewBrand toEntity(NewBrandPostReqDto newBrandPostReqDto, NewBrandStatus newBrandStatus);

@Mapping(target = "newBrandId", source = "newBrand.id")
@Mapping(target = "newBrandName", source = "newBrand.brandName")
NewBrandPostResDto toNewBrandPostResDto(NewBrand newBrand);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.sluv.server.domain.brand.mapper;

import com.sluv.server.domain.brand.dto.RecentSelectBrandResDto;
import com.sluv.server.domain.brand.entity.Brand;
import com.sluv.server.domain.brand.entity.NewBrand;
import com.sluv.server.domain.brand.entity.RecentSelectBrand;
import com.sluv.server.domain.user.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

@Mapper(componentModel = "spring")
public interface RecentSelectBrandMapper {

@Mapping(target = "id", ignore = true)
@Mapping(target = "brand", source = "brand")
@Mapping(target = "newBrand", source = "newBrand")
@Mapping(target = "user", source = "user")
RecentSelectBrand toEntity(Brand brand, NewBrand newBrand, User user);

@Mapping(target = "id", source = "recentSelectBrand", qualifiedByName = "mapId")
@Mapping(target = "brandName", source = "recentSelectBrand", qualifiedByName = "mapBrandName")
@Mapping(target = "brandImgUrl", source = "recentSelectBrand", qualifiedByName = "mapBrandUrl")
@Mapping(target = "flag", source = "recentSelectBrand", qualifiedByName = "mapFlag")
RecentSelectBrandResDto toRecentSelectBrandResDto(RecentSelectBrand recentSelectBrand);

@Named("mapId")
default Long mapId(RecentSelectBrand recentSelectBrand) {
Long brandId;
String flag = recentSelectBrand.getBrand() != null ? "Y" :"N";
if(flag.equals("Y")){
brandId = recentSelectBrand.getBrand().getId();
}else{
brandId = recentSelectBrand.getNewBrand().getId();
}
return brandId;
}

@Named("mapBrandName")
static String mapBrandName(RecentSelectBrand recentSelectBrand) {
String brandName;
String flag = recentSelectBrand.getBrand() != null ? "Y" :"N";
if(flag.equals("Y")){
brandName = recentSelectBrand.getBrand().getBrandKr();
}else{
brandName = recentSelectBrand.getNewBrand().getBrandName();
}
return brandName;
}

@Named("mapBrandUrl")
static String mapBrandUrl(RecentSelectBrand recentSelectBrand) {
String brandImgUrl;
String flag = recentSelectBrand.getBrand() != null ? "Y" :"N";
if(flag.equals("Y")){
brandImgUrl = recentSelectBrand.getBrand().getBrandImgUrl();
}else{
brandImgUrl = null;
}
return brandImgUrl;
}

@Named("mapFlag")
static String mapFlag(RecentSelectBrand recentSelectBrand) {
String flag = recentSelectBrand.getBrand() != null ? "Y" :"N";
return flag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.sluv.server.domain.brand.dto.RecentSelectBrandResDto;
import com.sluv.server.domain.brand.entity.Brand;
import com.sluv.server.domain.brand.entity.RecentSelectBrand;
import com.sluv.server.domain.brand.mapper.BrandMapper;
import com.sluv.server.domain.brand.mapper.RecentSelectBrandMapper;
import com.sluv.server.domain.brand.repository.BrandRepository;
import com.sluv.server.domain.brand.repository.RecentSelectBrandRepository;
import com.sluv.server.domain.user.entity.User;
Expand All @@ -23,19 +25,22 @@ public class BrandService {
private final BrandRepository brandRepository;
private final RecentSelectBrandRepository recentSelectBrandRepository;
private final UserRepository userRepository;
private final BrandMapper brandMapper;
private final RecentSelectBrandMapper recentSelectBrandMapper;


public PaginationResDto<BrandSearchResDto> findAllBrand(String brandName, Pageable pageable){

Page<Brand> brandPage = brandRepository.findByAllBrandKrOrBrandEnStartingWith(brandName, pageable);

List<BrandSearchResDto> dtoList = brandPage.stream()
.map(data -> BrandSearchResDto.builder()
.id(data.getId())
.brandKr(data.getBrandKr())
.brandEn(data.getBrandEn())
.brandImgUrl(data.getBrandImgUrl())
.build()
.map(brandMapper::toBrandSearchResDto
// .map(data -> BrandSearchResDto.builder()
// .id(data.getId())
// .brandKr(data.getBrandKr())
// .brandEn(data.getBrandEn())
// .brandImgUrl(data.getBrandImgUrl())
// .build()
).toList();

return PaginationResDto.<BrandSearchResDto>builder()
Expand All @@ -49,40 +54,17 @@ public PaginationResDto<BrandSearchResDto> findAllBrand(String brandName, Pageab

public List<BrandSearchResDto> findTopBrand() {
return brandRepository.findTop10By().stream()
.map(data -> BrandSearchResDto.builder()
.id(data.getId())
.brandKr(data.getBrandKr())
.brandEn(data.getBrandEn())
.brandImgUrl(data.getBrandImgUrl())
.build()
.map(brandMapper::toBrandSearchResDto
).collect(Collectors.toList());
}

public List<RecentSelectBrandResDto> findRecentSelectBrand(User user) {

List<RecentSelectBrand> recentSelectBrandList = recentSelectBrandRepository.getRecentSelectBrandTop20(user);

return recentSelectBrandList.stream().map(recentSelectBrand -> {
Long brandId;
String brandName;
String brandImgUrl;
String flag = recentSelectBrand.getBrand() != null ? "Y" :"N";
if(flag.equals("Y")){
brandId = recentSelectBrand.getBrand().getId();
brandName = recentSelectBrand.getBrand().getBrandKr();
brandImgUrl = recentSelectBrand.getBrand().getBrandImgUrl();
}else{
brandId = recentSelectBrand.getNewBrand().getId();
brandName = recentSelectBrand.getNewBrand().getBrandName();
brandImgUrl = null;
}
return RecentSelectBrandResDto.builder()
.id(brandId)
.brandName(brandName)
.brandImgUrl(brandImgUrl)
.flag(flag)
.build();
}).toList();
return recentSelectBrandList.stream()
.map(recentSelectBrandMapper::toRecentSelectBrandResDto)
.toList();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sluv.server.domain.brand.dto.NewBrandPostResDto;
import com.sluv.server.domain.brand.entity.NewBrand;
import com.sluv.server.domain.brand.enums.NewBrandStatus;
import com.sluv.server.domain.brand.mapper.NewBrandMapper;
import com.sluv.server.domain.brand.repository.NewBrandRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -12,20 +13,15 @@
@RequiredArgsConstructor
public class NewBrandService {
private final NewBrandRepository newBrandRepository;
private final NewBrandMapper newBrandMapper;

public NewBrandPostResDto postNewBrand(NewBrandPostReqDto dto){

NewBrand newBrand = newBrandRepository.save(
NewBrand.builder()
.brandName(dto.getNewBrandName())
.newBrandStatus(NewBrandStatus.ACTIVE)
.build()
newBrandMapper.toEntity(dto, null)
);

return NewBrandPostResDto.builder()
.newBrandId(newBrand.getId())
.newBrandName(newBrand.getBrandName())
.build();
return newBrandMapper.toNewBrandPostResDto(newBrand);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.sluv.server.domain.brand.entity.RecentSelectBrand;
import com.sluv.server.domain.brand.exception.BrandNotFoundException;
import com.sluv.server.domain.brand.exception.NewBrandNotFoundException;
import com.sluv.server.domain.brand.mapper.RecentSelectBrandMapper;
import com.sluv.server.domain.brand.repository.BrandRepository;
import com.sluv.server.domain.brand.repository.NewBrandRepository;
import com.sluv.server.domain.brand.repository.RecentSelectBrandRepository;
Expand All @@ -21,6 +22,8 @@ public class RecentSelectBrandService {
private final NewBrandRepository newBrandRepository;
private final RecentSelectBrandRepository recentSelectBrandRepository;

private final RecentSelectBrandMapper recentSelectBrandMapper;

public void postRecentSelectBrand(User user, RecentSelectBrandReqDto dto){
Brand brand = dto.getBrandId() != null
? brandRepository.findById(dto.getBrandId())
Expand All @@ -33,11 +36,7 @@ public void postRecentSelectBrand(User user, RecentSelectBrandReqDto dto){
: null;

recentSelectBrandRepository.save(
RecentSelectBrand.builder()
.brand(brand)
.newBrand(newBrand)
.user(user)
.build()
recentSelectBrandMapper.toEntity(brand, newBrand, user)
);
}

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/sluv/server/domain/item/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sluv.server.domain.brand.entity.NewBrand;
import com.sluv.server.domain.brand.exception.BrandNotFoundException;
import com.sluv.server.domain.brand.exception.NewBrandNotFoundException;
import com.sluv.server.domain.brand.mapper.BrandMapper;
import com.sluv.server.domain.brand.repository.BrandRepository;
import com.sluv.server.domain.brand.repository.NewBrandRepository;
import com.sluv.server.domain.celeb.dto.CelebSearchResDto;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class ItemService {
private final ClosetRepository closetRepository;
private final ItemScrapRepository itemScrapRepository;

private final BrandMapper brandMapper;

@Transactional
public ItemPostResDto postItem(User user, ItemPostReqDto reqDto) {

Expand Down Expand Up @@ -262,12 +265,13 @@ public ItemDetailResDto getItemDetail(User user, Long itemId) {

// 4. Brand
BrandSearchResDto brand = item.getBrand() != null ?
BrandSearchResDto.builder()
.id(item.getBrand().getId())
.brandKr(item.getBrand().getBrandKr())
.brandEn(item.getBrand().getBrandEn())
.brandImgUrl(item.getBrand().getBrandImgUrl())
.build()
brandMapper.toBrandSearchResDto(item.getBrand())
// BrandSearchResDto.builder()
// .id(item.getBrand().getId())
// .brandKr(item.getBrand().getBrandKr())
// .brandEn(item.getBrand().getBrandEn())
// .brandImgUrl(item.getBrand().getBrandImgUrl())
// .build()
: null;

String newBrand = item.getNewBrand() != null ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sluv.server.domain.brand.entity.NewBrand;
import com.sluv.server.domain.brand.exception.BrandNotFoundException;
import com.sluv.server.domain.brand.exception.NewBrandNotFoundException;
import com.sluv.server.domain.brand.mapper.NewBrandMapper;
import com.sluv.server.domain.brand.repository.BrandRepository;
import com.sluv.server.domain.brand.repository.NewBrandRepository;
import com.sluv.server.domain.celeb.dto.CelebDto;
Expand Down Expand Up @@ -55,6 +56,9 @@ public class TempItemService {
private final NewCelebRepository newCelebRepository;


private final NewBrandMapper newBrandMapper;


@Transactional
public Long postTempItem(User user, TempItemPostReqDto reqDto) {
Celeb celeb = reqDto.getCelebId() != null ? celebRepository.findById(reqDto.getCelebId())
Expand Down Expand Up @@ -223,10 +227,7 @@ public PaginationCountResDto<TempItemResDto> getTempItemList(User user, Pageable
)
.newBrand(
tempItem.getNewBrand() != null
? NewBrandPostResDto.builder()
.newBrandId(tempItem.getNewBrand().getId())
.newBrandName(tempItem.getNewBrand().getBrandName())
.build()
? newBrandMapper.toNewBrandPostResDto(tempItem.getNewBrand())
:null
)
.updatedAt(tempItem.getUpdatedAt())
Expand Down

0 comments on commit d453599

Please sign in to comment.