forked from KNU-HAEDAL/Birthday_Funding_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KNU-HAEDAL#1 feat: response dto 생성 및 그에 맞게 컨트롤러 수정
- Loading branch information
Showing
4 changed files
with
146 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/team/haedal/gifticionfunding/dto/gifticon/response/GifticonDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package team.haedal.gifticionfunding.dto.gifticon.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import team.haedal.gifticionfunding.entity.gifticon.Category; | ||
import team.haedal.gifticionfunding.entity.gifticon.Gifticon; | ||
|
||
import java.time.LocalDate; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class GifticonDetailResponse { | ||
private Long id; | ||
private Long price; | ||
private String name; | ||
private Category category; | ||
private Long stock; | ||
private String imageUrl; | ||
private String description; | ||
private String brand; | ||
private LocalDate expirationPeriod; | ||
|
||
@Builder | ||
private GifticonDetailResponse(final Long id, final Long price, final String name, final Category category, final Long stock, final String imageUrl, final String description, final String brand, final LocalDate expirationPeriod) { | ||
this.id = id; | ||
this.price = price; | ||
this.name = name; | ||
this.category = category; | ||
this.stock = stock; | ||
this.imageUrl = imageUrl; | ||
this.description = description; | ||
this.brand = brand; | ||
this.expirationPeriod = expirationPeriod; | ||
} | ||
|
||
public static GifticonDetailResponse from(final Gifticon gifticon){ | ||
return GifticonDetailResponse.builder() | ||
.id(gifticon.getId()) | ||
.price(gifticon.getPrice()) | ||
.name(gifticon.getName()) | ||
.category(gifticon.getCategory()) | ||
.stock(gifticon.getStock()) | ||
.imageUrl(gifticon.getImageUrl()) | ||
.description(gifticon.getDescription()) | ||
.brand(gifticon.getBrand()) | ||
.expirationPeriod(gifticon.getExpirationPeriod()) | ||
.build(); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/team/haedal/gifticionfunding/dto/gifticon/response/GifticonResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package team.haedal.gifticionfunding.dto.gifticon.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.cglib.core.Local; | ||
import team.haedal.gifticionfunding.entity.gifticon.Category; | ||
import team.haedal.gifticionfunding.entity.gifticon.Gifticon; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class GifticonResponse { | ||
private Long id; | ||
private Long price; | ||
private String name; | ||
private Category category; | ||
private Long stock; | ||
private String imageUrl; | ||
private String description; | ||
private String brand; | ||
private LocalDate expirationPeriod; | ||
|
||
|
||
@Builder | ||
private GifticonResponse(final Long id, final Long price, final String name, final Category category, final Long stock, final String imageUrl, final String description, final String brand, final LocalDate expirationPeriod) { | ||
this.id = id; | ||
this.price = price; | ||
this.name = name; | ||
this.category = category; | ||
this.stock = stock; | ||
this.imageUrl = imageUrl; | ||
this.description = description; | ||
this.brand = brand; | ||
this.expirationPeriod = expirationPeriod; | ||
} | ||
|
||
public static GifticonResponse from(final Gifticon gifticon){ | ||
return GifticonResponse.builder() | ||
.id(gifticon.getId()) | ||
.price(gifticon.getPrice()) | ||
.name(gifticon.getName()) | ||
.category(gifticon.getCategory()) | ||
.stock(gifticon.getStock()) | ||
.imageUrl(gifticon.getImageUrl()) | ||
.description(gifticon.getDescription()) | ||
.brand(gifticon.getBrand()) | ||
.expirationPeriod(gifticon.getExpirationPeriod()) | ||
.build(); | ||
} | ||
|
||
public static List<GifticonResponse> fromList(final List<Gifticon> gifticons){ | ||
return gifticons.stream() | ||
.map(GifticonResponse::from) | ||
.collect(Collectors.toUnmodifiableList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters