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

Add is_checked column #173

Merged
merged 8 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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