Skip to content

Commit

Permalink
feat: recycle modify
Browse files Browse the repository at this point in the history
  • Loading branch information
hyundong-L committed Aug 24, 2024
1 parent 8495447 commit 90eebf2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand All @@ -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())
Expand All @@ -64,7 +71,7 @@ public List<RecycleResponseDto> getAllRecycleSale(String email) throws MemberNot
List<Recycle> 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());
Expand All @@ -77,7 +84,7 @@ public List<RecycleResponseDto> getAllRecyclePurchase(String email) throws Membe
List<Recycle> recycleList = recycleRepository.findAll();

return recycleList.stream().filter(
recycle -> !recycle.getMember().equals(member)
recycle -> !recycle.getMember().equals(member) && !recycle.getType()
).map(
recycle -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDateTime;

@Entity
@Getter
@Builder
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 90eebf2

Please sign in to comment.