Skip to content

Commit

Permalink
Merge pull request #29 from Repick-official/feature/clothing-sales
Browse files Browse the repository at this point in the history
feature: 리픽백 신청/수거신청, 박스 수거신청 분리
  • Loading branch information
sky980221 authored Apr 3, 2024
2 parents af7814d + 68d5b16 commit 446a94d
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.example.repick.domain.clothingSales.api;

import com.example.repick.domain.clothingSales.dto.PostRequestDto;
import com.example.repick.domain.clothingSales.service.ClothingSalesService;
import com.example.repick.domain.clothingSales.dto.PostRequestDto;
import com.example.repick.domain.clothingSales.service.BoxService;
import com.example.repick.domain.clothingSales.service.RepickBagService;
import com.example.repick.global.aws.S3UploadService;
import com.example.repick.global.error.exception.CustomException;
import com.example.repick.global.error.exception.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import com.example.repick.domain.user.entity.User;
Expand All @@ -20,25 +21,51 @@
@RequestMapping("/clothing-sales")
public class ClothingSalesController {

private final ClothingSalesService clothingSalesService;
private final BoxService boxService;
private final RepickBagService repickBagService;
private final S3UploadService s3UploadService;
private final UserRepository userRepository;
private PostRequestDto postRequestDto;

@Autowired
public ClothingSalesController(ClothingSalesService clothingSalesService,
public ClothingSalesController(BoxService boxService,
RepickBagService repickBagService,
S3UploadService s3UploadService,
UserRepository userRepository) {
this.userRepository = userRepository;
this.clothingSalesService = clothingSalesService;
this.boxService = boxService;
this.repickBagService = repickBagService;
this.s3UploadService = s3UploadService;
}

@PostMapping(value = "/details", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public void post(@ModelAttribute PostRequestDto postRequestDto) throws IOException {
//리픽백_신청 (리픽백 신청은 박스 수거신청과 동일한 항목을 저장함, 그러나 다른 )
@PostMapping(value = "/repick-bags/requests", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> handleRepickBagRequest(@ModelAttribute PostRequestDto postRequestDto) throws IOException {
User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName())
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
String url = s3UploadService.saveFile(postRequestDto.getFile(), "clothingSales/" + user.getId());
repickBagService.save(postRequestDto, url, user.getId());
return ResponseEntity.ok().build(); // 성공 응답 반환
}

//리픽백_수거신청 (리픽백 수거신청은 리픽백 신청시 저장된 id를 불러오고, 새롭게 address, bagQuantity, imageUrl을 받아서 저장한다)
@PostMapping(value = "/repick-bags/collection-requests", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> handleRepickBagCollectionRequest(@ModelAttribute PostRequestDto postRequestDto) throws IOException {
User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName())
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
String url = s3UploadService.saveFile(postRequestDto.getFile(), "clothingSales/" + user.getId());
repickBagService.save(postRequestDto, url, user.getId());
return ResponseEntity.ok().build(); // 성공 응답 반환
}


@PostMapping(value = "/box/collection-requests", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> handleBoxCollectionRequest(@ModelAttribute PostRequestDto postRequestDto) throws IOException {
User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName())
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
String url = s3UploadService.saveFile(postRequestDto.getFile(), "clothingSales/" + user.getId());
clothingSalesService.save(postRequestDto, url, user.getId());
boxService.save(postRequestDto, url, user.getId());
return ResponseEntity.ok().build(); // 성공 응답 반환
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public class PostRequestDto implements Serializable {
private ClothingSalesType clothingSalesType;
private Address address;
private Integer bagQuantity;
private String collectionDate;
private MultipartFile file;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.repick.domain.clothingSales.dto;

import com.example.repick.domain.clothingSales.entity.ClothingSalesType;
import com.example.repick.global.entity.Address;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;

@Getter
@Setter
@NoArgsConstructor
public class RepickBagCollectDto implements Serializable {
private ClothingSalesType clothingSalesType;
private Address address;
private Integer bagQuantity;
private String collectionDate;
private MultipartFile file;
private Long repickBagApplyId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.example.repick.domain.clothingSales.entity;

import com.example.repick.domain.clothingSales.dto.PostRequestDto;
import com.example.repick.domain.user.entity.User;
import com.example.repick.global.entity.Address;
import jakarta.persistence.*;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BoxCollect {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Enumerated(EnumType.STRING)
@Column(name = "clothing_sales_type")
private ClothingSalesType clothingSalesType;

@Embedded
private Address address;

@Column(name = "bag_quantity")
private Integer bagQuantity;

@Column(name = "image_url")
private String imageUrl;

@Column(name = "collection_date")
private String collectionDate;

@OneToMany(mappedBy = "boxCollect", cascade = CascadeType.ALL)
private final List<BoxState> boxStates = new ArrayList<>();

public BoxCollect(PostRequestDto postRequestDto, String url) {
this.clothingSalesType = postRequestDto.getClothingSalesType();
this.address = postRequestDto.getAddress();
this.bagQuantity = postRequestDto.getBagQuantity();
this.imageUrl = url;
this.collectionDate = postRequestDto.getCollectionDate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.repick.domain.clothingSales.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
public class BoxState {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "box_state_id")
private Long id; // BoxState의 id

@Enumerated(EnumType.STRING)
@Column(name = "sales_status")
private SalesStatus salesStatus;

@ManyToOne
@JoinColumn(name = "box_collect_id")
private BoxCollect boxCollect;
}






Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ClothingSales {
public class RepickBagApply {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -39,10 +39,10 @@ public class ClothingSales {
@Column(name = "image_url")
private String imageUrl;

@OneToMany(mappedBy = "clothingSales", cascade = CascadeType.ALL)
private final List<ClothingSalesState> clothingSalesStates = new ArrayList<>();
@OneToMany(mappedBy = "repickBagApply", cascade = CascadeType.ALL)
private final List<RepickBagState> repickBagStates = new ArrayList<>();

public ClothingSales(PostRequestDto postRequestDto, String url) {
public RepickBagApply(PostRequestDto postRequestDto, String url) {
this.clothingSalesType = postRequestDto.getClothingSalesType();
this.address = postRequestDto.getAddress();
this.bagQuantity = postRequestDto.getBagQuantity();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.example.repick.domain.clothingSales.entity;

import com.example.repick.domain.clothingSales.dto.PostRequestDto;
import com.example.repick.domain.clothingSales.dto.RepickBagCollectDto;
import com.example.repick.domain.user.entity.User;
import com.example.repick.global.entity.Address;
import jakarta.persistence.*;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RepickBagCollect {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Enumerated(EnumType.STRING)
@Column(name = "clothing_sales_type")
private ClothingSalesType clothingSalesType;

@Embedded
private Address address;

@Column(name = "bag_quantity")
private Integer bagQuantity;

@Column(name = "image_url")
private String imageUrl;

@Column(name = "collection_date")
private String collectionDate;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "repick_bag_apply_id")
private RepickBagApply repickBagApply;

public RepickBagCollect(RepickBagCollectDto repickBagCollectDto, RepickBagApply repickBagApply) {
this.clothingSalesType = repickBagCollectDto.getClothingSalesType();
this.address = repickBagCollectDto.getAddress();
this.bagQuantity = repickBagCollectDto.getBagQuantity();
this.collectionDate = repickBagCollectDto.getCollectionDate();
this.repickBagApply = repickBagApply;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
@Entity
@Getter
@Setter
public class ClothingSalesState {
public class RepickBagState {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "clothing_sales_state_id")
@Column(name = "repick_bag_state_id")
private Long id;

@Enumerated(EnumType.STRING)
@Column(name = "sales_status")
private SalesStatus salesStatus;

// 여러 ClothingSalesState가 하나의 ClothingSales를 참조
@ManyToOne
@JoinColumn(name = "clothing_sales_id")
private ClothingSales clothingSales;
@JoinColumn(name = "repick_bag_apply_id")
private RepickBagApply repickBagApply;

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.repick.domain.clothingSales.repository;

import com.example.repick.domain.clothingSales.entity.BoxCollect;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BoxRepository extends JpaRepository<BoxCollect, Long> {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.repick.domain.clothingSales.repository;

import com.example.repick.domain.clothingSales.entity.RepickBagCollect;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RepickBagCollectRepository extends JpaRepository<RepickBagCollect, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.repick.domain.clothingSales.repository;

import com.example.repick.domain.clothingSales.entity.RepickBagApply;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RepickBagRepository extends JpaRepository<RepickBagApply, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.repick.domain.clothingSales.service;

import com.example.repick.domain.clothingSales.dto.PostRequestDto;
import com.example.repick.domain.clothingSales.entity.BoxCollect;
import com.example.repick.domain.clothingSales.repository.BoxRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BoxService {

private final BoxRepository boxRepository;

@Autowired
public BoxService(BoxRepository boxRepository) {
this.boxRepository = boxRepository;
}

//user_id를 3번째 parameter로 save 하고 싶다
public void save(PostRequestDto postRequestDto, String url, Long userId) {
BoxCollect boxCollect = new BoxCollect(postRequestDto, url);
boxRepository.save(boxCollect);
}
}

This file was deleted.

Loading

0 comments on commit 446a94d

Please sign in to comment.