Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop to main #175

Merged
merged 12 commits into from
Nov 14, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.swmaestro.repl.gifthub.util.Message;
import org.swmaestro.repl.gifthub.util.StatusEnum;
import org.swmaestro.repl.gifthub.util.SuccessMessage;
import org.swmaestro.repl.gifthub.vouchers.service.VoucherService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -38,6 +39,7 @@ public class UserController {
private final UserService userService;
private final OAuthService oAuthService;
private final JwtProvider jwtProvider;
private final VoucherService voucherService;

@DeleteMapping("/{userId}")
@Operation(summary = "User 삭제 메서드", description = "클라이언트에서 요청한 사용자 정보를 삭제(Soft-Delete)하기 위한 메서드입니다.")
Expand All @@ -48,6 +50,7 @@ public class UserController {
})
public ResponseEntity<Message> deleteMember(HttpServletRequest request, @PathVariable Long userId) {
UserDeleteResponseDto deletedMember = userService.delete(userId);
voucherService.deleteAll(userId);
return ResponseEntity.ok(
SuccessMessage.builder()
.path(request.getRequestURI())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public class VoucherReadResponseDto {
private boolean accessible;
@JsonProperty("is_shared")
private boolean shared;
@JsonProperty("is_checked")
private boolean checked;

@Builder
public VoucherReadResponseDto(Long id, Long productId, String barcode, String expiresAt, Integer price,
Integer balance, String imageUrl, boolean accessible, boolean shared) {
Integer balance, String imageUrl, boolean accessible, boolean shared, boolean checked) {
this.id = id;
this.productId = productId;
this.barcode = barcode;
Expand All @@ -39,5 +41,6 @@ public VoucherReadResponseDto(Long id, Long productId, String barcode, String ex
this.imageUrl = imageUrl;
this.accessible = accessible;
this.shared = shared;
this.checked = checked;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public class VoucherUpdateRequestDto {
private String productName;
private String brandName;
private Integer balance;
private Boolean isChecked;

@Builder
public VoucherUpdateRequestDto(String barcode, String expiresAt, String productName, String brandName, int balance) {
public VoucherUpdateRequestDto(String barcode, String expiresAt, String productName, String brandName, int balance, boolean isChecked) {
this.barcode = barcode;
this.expiresAt = expiresAt;
this.productName = productName;
this.brandName = brandName;
this.balance = balance;
this.isChecked = isChecked;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;

import org.hibernate.annotations.ColumnDefault;
import org.swmaestro.repl.gifthub.auth.entity.User;
import org.swmaestro.repl.gifthub.util.BaseTimeEntity;

Expand Down Expand Up @@ -55,6 +56,10 @@ public class Voucher extends BaseTimeEntity {
@Column
private LocalDateTime deletedAt;

@Column(name = "is_checked", columnDefinition = "TINYINT", nullable = false)
@ColumnDefault("0")
private boolean checked;

@Builder
public Voucher(Long id, Brand brand, Product product, String barcode, Integer balance, LocalDate expiresAt,
String imageUrl, User user) {
Expand All @@ -71,4 +76,13 @@ public Voucher(Long id, Brand brand, Product product, String barcode, Integer ba
public boolean isDeleted() {
return deletedAt != null;
}

public boolean isChecked() {
return checked;
}

public Voucher check() {
this.checked = true;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public interface VoucherRepository extends JpaRepository<Voucher, Long> {
List<Voucher> findAllByUserUsername(String username);

List<Voucher> findAllByUserId(Long memberId);
List<Voucher> findAllByUserId(Long userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public VoucherReadResponseDto read(Long id, String username) {
// }

VoucherReadResponseDto voucherReadResponseDto = mapToDto(voucher.get());

return voucherReadResponseDto;
}

Expand Down Expand Up @@ -204,6 +205,10 @@ public VoucherSaveResponseDto update(Long voucherId, VoucherUpdateRequestDto vou
voucher.setBalance(voucherUpdateRequestDto.getBalance() == null ? voucher.getBalance() :
voucherUpdateRequestDto.getBalance());

// isChecked 수정
voucher.setChecked(voucherUpdateRequestDto.getIsChecked() == null ? voucher.isChecked() :
voucherUpdateRequestDto.getIsChecked());

voucherRepository.save(voucher);

return VoucherSaveResponseDto.builder()
Expand Down Expand Up @@ -269,6 +274,7 @@ public VoucherReadResponseDto mapToDto(Voucher voucher) {
.imageUrl(voucher.getImageUrl())
.accessible(voucher.getDeletedAt() == null)
.shared(giftCardService.isExist(voucher.getId()))
.checked(voucher.isChecked())
.build();
return voucherReadResponseDto;
}
Expand Down Expand Up @@ -465,4 +471,15 @@ public String getPresignedUrlForVoucherImage(String username, Long voucherId) {
String filename = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
return storageService.getPresignedUrl(voucherDirName, filename);
}

/**
* 사용자 별 기프티콘 전체 삭제 메서드
* @param userId
*/
public void deleteAll(Long userId) {
voucherRepository.findAllByUserId(userId).stream().forEach(voucher -> {
voucher.setDeletedAt(LocalDateTime.now());
voucherRepository.save(voucher);
});
}
}
Loading