Skip to content

Commit

Permalink
refactor, feat : 컬럼 추가, 타입변경 및 rename 에 따른 기능 수정 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
donsonioc2010 authored Sep 20, 2023
1 parent ede67b3 commit 3c71800
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
package picasso.server.api.auction.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import picasso.server.api.auction.service.PictureService;
import picasso.server.common.util.NaverObjectStorageUsageType;
import picasso.server.common.util.NaverObjectStorageUtil;
import picasso.server.domain.domains.dto.PictureDTO;
import picasso.server.domain.domains.items.Picture;
import picasso.server.api.auction.service.PictureService;
import picasso.server.domain.domains.items.PictureStatus;

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


@Slf4j
@Controller
@RequestMapping("/pictures")
@RequiredArgsConstructor
public class PictureController {

private final PictureService pictureService;
private final NaverObjectStorageUtil naverObjectStorageUtil;
List<String> imageUrls = new ArrayList<>();


@GetMapping("/new")
public String createForm(Model model) {
model.addAttribute("PictureDTO", new PictureDTO());
Expand All @@ -44,24 +42,20 @@ public String add(PictureDTO dto, MultipartFile imageFile, Model model) {
picture.setDetails(dto.getDetails());
picture.setStartingPrice(dto.getStartingPrice());
picture.setIncrementAmount(dto.getIncrementAmount());
picture.setDateTime(dto.getDateTime());
PictureStatus status = PictureStatus.BEFORE_APPROVE; // Enum값 변경할것
picture.setPictureStatus(status);
if (imageFile != null && !imageFile.isEmpty()) {
try {
String imageUrl = naverObjectStorageUtil.storageFileUpload(NaverObjectStorageUsageType.PAINT, imageFile);
picture.setImgUrl(imageUrl);
imageUrls.add(imageUrl);
model.addAttribute("imageUrls", imageUrls);
model.addAttribute("imgURL", imageUrl);
picture.setBidStartDate(dto.getDateTime());
//희망 경매일자 + 7일
picture.setBidEndDate(dto.getDateTime().plusDays(7));

} catch (Exception e) {
e.printStackTrace();
return "redirect:/error"; // Redirect to an error page
}
List<String> imageUrls = new ArrayList<>();
if (imageFile != null && !imageFile.isEmpty()) {
String imageUrl = naverObjectStorageUtil.storageFileUpload(NaverObjectStorageUsageType.PAINT, imageFile);
picture.setImgUrl(imageUrl);
imageUrls.add(imageUrl);
model.addAttribute("imageUrls", imageUrls);
model.addAttribute("imgURL", imageUrl);
}

pictureService.saveItem(picture); //- 이 부분은 필요에 따라 주석처리
pictureService.saveItem(picture); //- 이 부분은 필요에 따라 주석처리
return "redirect:/";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import picasso.server.domain.domains.items.Picture;
import picasso.server.domain.domains.repository.PictureRepository;

Expand All @@ -21,8 +20,7 @@ public class PictureService {

//아이템등록
public Picture saveItem(Picture picture) {
Picture savedPicture = pictureRepository.save(picture);
return savedPicture;
return pictureRepository.save(picture);
}

public List<Picture> findItem() {
Expand All @@ -49,7 +47,7 @@ public List<String> extractImageUrlsSortedByDateTime() {
}
return imageUrls;*/

return pictureRepository.findAllByPictureStatusOrderByDateTimeAsc(BIDDING)
return pictureRepository.findAllByPictureStatusOrderByBidStartDateAsc(BIDDING)
.stream()
.map(Picture::getImgUrl)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class NaverObjectStorageUtil {
* @return
* @throws FileUploadException
*/
public String storageFileUpload(NaverObjectStorageUsageType usageType, MultipartFile file) throws FileUploadException {
public String storageFileUpload(NaverObjectStorageUsageType usageType, MultipartFile file){
try {
String filePath = getPath(usageType, getFileUUIDNameByMultipartFile(file));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.time.LocalDate;

@Getter @Setter
public class PictureDTO {
Expand All @@ -14,6 +14,6 @@ public class PictureDTO {
private int startingPrice; //시작가격
private int incrementAmount; //최소입찰단위
private String size; //그림 사이즈
private LocalDateTime dateTime;
private LocalDate dateTime;
private String imgUrl; //그림 url
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,59 @@
package picasso.server.domain.domains.items;

import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;
import java.time.LocalDate;

@Getter
@Setter
@Entity
@Getter @Setter
@NoArgsConstructor
public class Picture {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long picture_id;

@NotNull
private String imgUrl; //그림 url

@NotNull
private String pictureName; //그림 이름

@NotNull
private String painterName; //화가 이름

@Column(nullable = false)
@Lob
private String details; //그림 설명


//기본 값을 BEFORE_APPROVE로 사용
@NotNull
@Enumerated(EnumType.STRING)
private PictureStatus pictureStatus;
private PictureStatus pictureStatus = PictureStatus.BEFORE_APPROVE;

private int startingPrice; //시작 가격
//시작 가격, 기본 최소 가격 0원
private int startingPrice = 0;

private int incrementAmount; //최소 입찰 단위
//최소 입찰 단위, 기본 최소값 500 원
private int incrementAmount = 500;

private String size; //그림 사이즈
private LocalDateTime dateTime;

@NotNull // 경매 시작일, 기본 값은 Now(); 를 사용한다.
private LocalDate bidStartDate = LocalDate.now();

@NotNull
private LocalDate bidEndDate; // 경매 종료일

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@Repository
public interface PictureRepository extends JpaRepository<Picture, Long>{

List<Picture> findAllByOrderByDateTimeAsc();
List<Picture> findAllByOrderByBidStartDateAsc();

List<Picture> findAllByPictureStatusOrderByDateTimeAsc(PictureStatus status);
List<Picture> findAllByPictureStatusOrderByBidStartDateAsc(PictureStatus status);

}
16 changes: 8 additions & 8 deletions Domain/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ insert into t_test(name, param1,param2,param3,param4)
values ('ffff', 'a','b','c','d');

-- 테스트용 데이터
insert into picture(increment_amount, starting_price, date_time, picture_id, details, img_url, painter_name, picture_name, picture_status, size)
values (10,1000,'2023-09-22 12:00:00', 1L, 'test1', 'local/paint/d5fdd501-8251-4082-9cc6-f1a65e5ad0a9.jpg', '안유진', '안유진', 'BIDDING' ,'800x600');
insert into picture(increment_amount, starting_price, date_time, picture_id, details, img_url, painter_name, picture_name, picture_status, size)
values (20,2000,'2023-09-21 12:00:00', 2L, 'test2', 'local/paint/6b075c7b-7149-4ecd-8b0a-ac71bb316e4d.jpeg', '은채', '은채', 'SUCCESS_BID','800x600');
insert into picture(increment_amount, starting_price, date_time, picture_id, details, img_url, painter_name, picture_name, picture_status, size)
values (30,3000,'2023-09-20 12:00:00', 3L, 'test3', 'local/paint/b6025492-6291-4ae2-916d-00981db26ed2.jpeg', '카리나', '카리나','BIDDING' ,'800x600');
insert into picture(increment_amount, starting_price, date_time, picture_id, details, img_url, painter_name, picture_name, picture_status,size)
values (40,4000,'2023-09-19 12:00:00', 4L, 'test4', 'local/paint/bf50117d-e28a-4393-8bc4-2fefa7220718.jpeg', '한소희', '한소희','SUCCESS_BID' ,'800x600');
insert into picture(picture_id, increment_amount, starting_price, bid_start_date, bid_end_date, details, img_url, painter_name, picture_name, picture_status, size)
values (1, 10, 1000, '2023-09-22', '2023-09-29', 'test1', 'local/paint/d5fdd501-8251-4082-9cc6-f1a65e5ad0a9.jpg', '안유진', '안유진', 'BIDDING' ,'800x600');
insert into picture(picture_id, increment_amount, starting_price, bid_start_date, bid_end_date, details, img_url, painter_name, picture_name, picture_status, size)
values (2, 20, 2000, '2023-09-21', '2023-09-28', 'test2', 'local/paint/6b075c7b-7149-4ecd-8b0a-ac71bb316e4d.jpeg', '은채', '은채', 'SUCCESS_BID','800x600');
insert into picture(picture_id, increment_amount, starting_price, bid_start_date, bid_end_date, details, img_url, painter_name, picture_name, picture_status, size)
values (3, 30, 3000, '2023-09-20', '2023-09-27', 'test3', 'local/paint/b6025492-6291-4ae2-916d-00981db26ed2.jpeg', '카리나', '카리나','BIDDING' ,'800x600');
insert into picture(picture_id, increment_amount, starting_price, bid_start_date, bid_end_date, details, img_url, painter_name, picture_name, picture_status, size)
values (4, 40, 4000, '2023-09-19', '2023-09-26', 'test4', 'local/paint/bf50117d-e28a-4393-8bc4-2fefa7220718.jpeg', '한소희', '한소희','SUCCESS_BID' ,'800x600');



0 comments on commit 3c71800

Please sign in to comment.