Skip to content

Commit

Permalink
Merge pull request #144 from ShallWeProject/feat/139-admin-getGift
Browse files Browse the repository at this point in the history
[Feat] 관리자 상품 목록 조회 API구현
  • Loading branch information
leeseunghakhello authored Nov 8, 2023
2 parents 76f3bfa + c1b9f05 commit 6f7abcd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public interface ExperienceGiftService {
List<ExperienceRes> getAllPopularGift(UserPrincipal userPrincipal);

void registerExperienceGift(UserPrincipal userPrincipal, AdminExperienceReq adminExperienceReq);

List<AdminExperienceRes> getExperienceGift(UserPrincipal userPrincipal);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.shallwe.domain.experiencegift.exception.*;
import com.shallwe.domain.shopowner.domain.ShopOwner;
import com.shallwe.domain.shopowner.domain.repository.ShopOwnerRepository;
import com.shallwe.domain.shopowner.exception.InvalidShopOwnerException;
import com.shallwe.domain.user.domain.repository.UserRepository;
import com.shallwe.domain.user.exception.InvalidUserException;
import com.shallwe.global.config.security.token.UserPrincipal;
Expand Down Expand Up @@ -93,6 +94,20 @@ public void registerExperienceGift(UserPrincipal userPrincipal, AdminExperienceR

}

@Override
public List<AdminExperienceRes> getExperienceGift(UserPrincipal userPrincipal) {
Long userId = userPrincipal.getId();

ShopOwner shopOwner = shopOwnerRepository.findById(userId)
.orElseThrow(InvalidShopOwnerException::new);

List<ExperienceGift> experienceGifts = experienceGiftRepository.findByShopOwnerId(shopOwner.getId());

return experienceGifts.stream()
.map(AdminExperienceRes::toDto)
.collect(Collectors.toList());
}

@Override
@Transactional
public ExperienceDetailRes createExperience(UserPrincipal userPrincipal,ExperienceReq experienceReq ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface ExperienceGiftRepository extends JpaRepository<ExperienceGift,
List<ExperienceGift> findByTitleContains(String title);
Optional<ExperienceGift> findByExperienceGiftId(Long experienceGiftId);

List<ExperienceGift> findByShopOwnerId(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.shallwe.domain.experiencegift.dto.response;

import com.shallwe.domain.experiencegift.domain.ExperienceGift;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class AdminExperienceRes {
@Schema(type = "Long", description = "경험선물 Id", example = "1")
private Long experienceGiftId;
@Schema(type = "String", description = "상품명", maxLength = 100)
private String subtitle;
@Schema(type = "String", description = "지역", maxLength = 30)
private String title;

public static AdminExperienceRes toDto(ExperienceGift experienceGift){
return AdminExperienceRes.builder()
.experienceGiftId(experienceGift.getExperienceGiftId())
.subtitle(experienceGift.getSubtitle().getTitle())
.title(experienceGift.getTitle())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.shallwe.domain.experiencegift.application.ExperienceGiftServiceImpl;
import com.shallwe.domain.experiencegift.dto.request.AdminExperienceReq;
import com.shallwe.domain.experiencegift.dto.response.AdminExperienceRes;
import com.shallwe.domain.experiencegift.dto.response.ExperienceDetailRes;
import com.shallwe.global.config.security.token.CurrentUser;
import com.shallwe.global.config.security.token.UserPrincipal;
Expand All @@ -18,6 +19,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Admin ExperienceGifts", description = "ExperienceGifts API")
@RequestMapping("/api/v1/admin/experience/gift")
@RestController
Expand All @@ -38,4 +41,16 @@ public ResponseCustom registerExperienceGift(
this.experienceGiftService.registerExperienceGift(userPrincipal, adminExperienceReq);
return ResponseCustom.OK();
}

@Operation(summary = "관리자 경험 선물 조회", description = "관리자 경험 선물 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "관리자 경험 선물 조회 성공",content = {@Content(mediaType = "application/json", schema = @Schema(implementation = AdminExperienceRes.class))}),
@ApiResponse(responseCode = "400", description = "관리자 경험 선물 조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping("")
public ResponseCustom<List<AdminExperienceRes>> getExperienceGift(
@Parameter(description = "AccessToken 을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal
) {
return ResponseCustom.OK(experienceGiftService.getExperienceGift(userPrincipal));
}
}

0 comments on commit 6f7abcd

Please sign in to comment.