diff --git a/src/main/java/com/hackathon/ecocycle/domain/Recycle/application/RecycleService.java b/src/main/java/com/hackathon/ecocycle/domain/Recycle/application/RecycleService.java index 79a96c2..5976c6d 100644 --- a/src/main/java/com/hackathon/ecocycle/domain/Recycle/application/RecycleService.java +++ b/src/main/java/com/hackathon/ecocycle/domain/Recycle/application/RecycleService.java @@ -17,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @@ -34,11 +35,15 @@ public void createRecycle(String email, MultipartFile image, RecycleRequestDto r String imageUrl = imageService.uploadImage(image); Recycle recycle = Recycle.builder() + .title(recycleRequestDto.title()) + .location(recycleRequestDto.location()) .member(member) - .type(recycleRequestDto.type()) + .type(false) .price(recycleRequestDto.price()) + .createdAt(LocalDateTime.now()) .imageUrl(imageUrl) .build(); + recycleRepository.save(recycle); } @@ -49,8 +54,10 @@ public RecycleResponseDto getRecycle(Long id) throws RecycleNotFoundException, M return RecycleResponseDto.builder() .id(recycle.getRecycleId()) + .title(recycle.getTitle()) + .location(recycle.getLocation()) .price(recycle.getPrice()) - .type(recycle.getType()) + .createdAt(recycle.getCreatedAt()) .imageUrl(recycle.getImageUrl()) .nickname(member.getNickname()) .location(member.getLocation()) @@ -64,7 +71,7 @@ public List getAllRecycleSale(String email) throws MemberNot List recycleList = recycleRepository.findAll(); return recycleList.stream().filter( - recycle -> recycle.getMember().equals(member) + recycle -> recycle.getMember().equals(member) && !recycle.getType() ).map( recycle -> RecycleResponseDto.from(recycle, member) ).collect(Collectors.toList()); @@ -77,7 +84,7 @@ public List getAllRecyclePurchase(String email) throws Membe List recycleList = recycleRepository.findAll(); return recycleList.stream().filter( - recycle -> !recycle.getMember().equals(member) + recycle -> !recycle.getMember().equals(member) && !recycle.getType() ).map( recycle -> { try { diff --git a/src/main/java/com/hackathon/ecocycle/domain/Recycle/domain/entity/Recycle.java b/src/main/java/com/hackathon/ecocycle/domain/Recycle/domain/entity/Recycle.java index 5355813..13e21c0 100644 --- a/src/main/java/com/hackathon/ecocycle/domain/Recycle/domain/entity/Recycle.java +++ b/src/main/java/com/hackathon/ecocycle/domain/Recycle/domain/entity/Recycle.java @@ -4,6 +4,8 @@ import jakarta.persistence.*; import lombok.*; +import java.time.LocalDateTime; + @Entity @Getter @Builder @@ -16,9 +18,15 @@ public class Recycle { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long recycleId; + private String title; + + private String location; + private Long price; - private String type; + private LocalDateTime createdAt; + + private Boolean type; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") diff --git a/src/main/java/com/hackathon/ecocycle/domain/Recycle/dto/request/RecycleRequestDto.java b/src/main/java/com/hackathon/ecocycle/domain/Recycle/dto/request/RecycleRequestDto.java index ac6c353..d0576b5 100644 --- a/src/main/java/com/hackathon/ecocycle/domain/Recycle/dto/request/RecycleRequestDto.java +++ b/src/main/java/com/hackathon/ecocycle/domain/Recycle/dto/request/RecycleRequestDto.java @@ -1,7 +1,8 @@ package com.hackathon.ecocycle.domain.Recycle.dto.request; public record RecycleRequestDto( - Long price, - String type + String title, + String location, + Long price ) { } diff --git a/src/main/java/com/hackathon/ecocycle/domain/Recycle/dto/response/RecycleResponseDto.java b/src/main/java/com/hackathon/ecocycle/domain/Recycle/dto/response/RecycleResponseDto.java index c6c2f59..0034fa3 100644 --- a/src/main/java/com/hackathon/ecocycle/domain/Recycle/dto/response/RecycleResponseDto.java +++ b/src/main/java/com/hackathon/ecocycle/domain/Recycle/dto/response/RecycleResponseDto.java @@ -4,19 +4,24 @@ import com.hackathon.ecocycle.domain.member.domain.entity.Member; import lombok.Builder; +import java.time.LocalDateTime; + @Builder public record RecycleResponseDto( Long id, + String title, + String location, Long price, - String type, + LocalDateTime createdAt, String imageUrl, - String nickname, - String location) { + String nickname) { public static RecycleResponseDto from(Recycle recycle, Member member) { return RecycleResponseDto.builder() .id(recycle.getRecycleId()) + .title(recycle.getTitle()) + .location(recycle.getLocation()) .price(recycle.getPrice()) - .type(recycle.getType()) + .createdAt(recycle.getCreatedAt()) .imageUrl(recycle.getImageUrl()) .nickname(member.getNickname()) .location(member.getLocation())