Skip to content

Commit

Permalink
Merge pull request #15 from 2023-CMC-Hackerthon/feat/findCards
Browse files Browse the repository at this point in the history
feat:imageurl들 리스트 반환
  • Loading branch information
AlmondBreez3 authored Nov 25, 2023
2 parents 668880a + 0885f71 commit a0ce596
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public ResponseEntity<?> getCardInfo(@PathVariable Long cardId) {
}

@Operation(description = "명함")
@PostMapping(value = "/image", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE})
public SuccessResponse<Object> uploadImage(@RequestParam("file") MultipartFile file) throws IOException {
@PostMapping(value = "/image/{walletId}", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE})
public SuccessResponse<Object> uploadImage(@RequestParam("file") MultipartFile file, Long walletId) throws IOException {
try {
String imageUrl = cardService.uploadImage(file);
String imageUrl = cardService.uploadImage(file, walletId);
SuccessResponse<Object> successResponse = SuccessResponse.onSuccess(200,imageUrl);
return successResponse;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.hackathon.hackathon.domain.card.dto.response.CardDeleteResponseDto;
import com.hackathon.hackathon.domain.card.entity.Card;
import com.hackathon.hackathon.domain.card.repository.CardRepository;
import com.hackathon.hackathon.domain.wallet.entity.Wallet;
import com.hackathon.hackathon.domain.wallet.repository.WalletRepository;
import com.hackathon.hackathon.domain.wallet.service.WalletService;
import com.hackathon.hackathon.global.S3.S3Service;
import com.hackathon.hackathon.global.response.SuccessResponse;
import java.io.IOException;
Expand All @@ -26,6 +28,7 @@ public class CardService {

private final CardRepository cardRepository;
private final WalletRepository walletRepository;
private final WalletService walletService;
private final S3Service s3Service;

@Transactional
Expand Down Expand Up @@ -109,8 +112,11 @@ public ResponseEntity<?> getCardInfo(Long cardId) {
return ResponseEntity.ok(apiResponse);
}

public String uploadImage(MultipartFile file) throws IOException {
@Transactional
public String uploadImage(MultipartFile file, Long walletId) throws IOException {
String imageUrl = s3Service.upload(file);
Wallet wallet = walletRepository.findById(walletId).get();
wallet.addImageUrl(imageUrl);
return imageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/wallets")
Expand Down Expand Up @@ -47,6 +49,19 @@ public SuccessResponse<Object> deleteWallet(@RequestParam Long walletId){
return walletService.deleteWallet(user, walletId);
}

@Operation(description = "내가 만든 카드들(이미지) 지갑별로 보기")
@GetMapping("/cards/{walletId}")
public SuccessResponse<Object> getCardUrls(@RequestParam Long walletId){
User user = authentiatedUserUtils.getCurrentUser();
return walletService.getAllCardLinks(walletId);
}

// @Operation(description = "지갑에 여러 이미지 url 올리기")
// @PostMapping("/{walletId}")
// public List<String> uploadCard(@RequestParam Long walletId) {
//
// }




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Entity
@Builder
@AllArgsConstructor
Expand All @@ -24,6 +26,10 @@ public class Wallet extends BaseTimeEntity {
private User user;
@Enumerated(EnumType.STRING)
protected WalletStatus status;

@ElementCollection
private List<String> imageUrls;

public Wallet() {
// 기본 생성자
this.status = WalletStatus.ACTIVE; // 생성자에서도 ACTIVE로 초기화
Expand All @@ -35,4 +41,8 @@ public void updateStatus(WalletStatus newStatus) {
this.status = newStatus;
}

@Transactional
public void addImageUrl(String imageUrl) {
this.imageUrls.add(imageUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hackathon.hackathon.domain.wallet.dto.request.WalletRequestDTO;
import com.hackathon.hackathon.domain.wallet.dto.response.WalletResponseDTO;
import com.hackathon.hackathon.domain.wallet.entity.Wallet;
import com.hackathon.hackathon.domain.wallet.enums.WalletStatus;
import com.hackathon.hackathon.domain.wallet.repository.WalletRepository;
import com.hackathon.hackathon.global.response.SuccessResponse;
import com.hackathon.hackathon.global.utils.AuthentiatedUserUtils;
Expand All @@ -16,6 +17,7 @@

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.hackathon.hackathon.domain.wallet.enums.WalletStatus.ACTIVE;
import static com.hackathon.hackathon.domain.wallet.enums.WalletStatus.DEACTIVE;
Expand Down Expand Up @@ -60,7 +62,11 @@ public SuccessResponse<Object> getWallet(User user, Long walletId) {

public SuccessResponse<Object> getWallets(User user) {
List<Wallet> wallets = walletRepository.findAllByUserId(user.getId());
return SuccessResponse.onSuccess(200,wallets);
// status가 ACTIVE인 Wallet만 필터링
List<Wallet> activeWallets = wallets.stream()
.filter(wallet -> WalletStatus.ACTIVE.equals(wallet.getStatus()))
.collect(Collectors.toList());
return SuccessResponse.onSuccess(200,activeWallets);
}


Expand All @@ -78,4 +84,11 @@ private Wallet updateWalletStatus(Wallet wallet){
walletRepository.save(wallet);
return wallet;
}

public SuccessResponse<Object> getAllCardLinks(Long walletId) {
Wallet wallet = walletRepository.findById(walletId).get();
List<String> wallets = wallet.getImageUrls();
return SuccessResponse.onSuccess(200,wallets);
}

}

0 comments on commit a0ce596

Please sign in to comment.