Skip to content

Commit

Permalink
[feat]판매 등록폼 수정 완료 #137
Browse files Browse the repository at this point in the history
  • Loading branch information
yunji118 committed Jan 7, 2024
1 parent 870f415 commit 2ff38d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/main/java/wowmarket/wow_server/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesItemDto;

@Entity
@Getter
Expand Down Expand Up @@ -31,4 +32,11 @@ public void setProject(Project project){
this.project = project;
}

public void modify(MySalesItemDto itemDto){
this.name = itemDto.getItemName();
this.price = itemDto.getPrice();
this.goal = itemDto.getGoal();
this.limits = itemDto.getLimits();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ public class MySalesItemDto {
private Long itemId;
private String itemName;
private Long price;
private int limits;
private int goal;

public MySalesItemDto(Item item){
this.itemId = item.getId();
this.itemName = item.getName();
this.price = item.getPrice();
this.goal = item.getGoal();
this.limits = item.getLimits();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MySalesProjectModifyRequestDto {
private String projectName;
private String description;
private String thumbnail;
private int categoryId;
private Long categoryId;
private String image1;
private String image2;
private String image3;
Expand All @@ -35,7 +35,7 @@ public class MySalesProjectModifyRequestDto {

@Builder
public MySalesProjectModifyRequestDto(String projectName, String description, String sellerName, String phoneNumber, String email, String sellerEtc,
int categoryId, String thumbnail, String image1, String image2, String image3, LocalDateTime startDate,
Long categoryId, String thumbnail, String image1, String image2, String image3, LocalDateTime startDate,
LocalDateTime endDate, Long receiveType, String receiveAddress, Long deliveryFee, String bank, String account,
String accountHolderName, List<MySalesItemDto> itemList){
this.projectName = projectName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
public class MySalesProjectService {
private final ProjectRepository projectRepository;
private final ItemRepository itemRepository;
private final UserRepository userRepository;
private final CategoryRepository categoryRepository;

@Transactional(readOnly = true)
Expand Down Expand Up @@ -67,8 +66,17 @@ public ResponseEntity modifyMySalesProject(Long projectId, MySalesProjectModifyR
if (user == null || project.getUser().getId() != user.getId()){
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}
Category category = categoryRepository.findById(Long.valueOf(requestDto.getCategoryId())).orElseThrow(() -> new IllegalArgumentException("해당 category id가 없습니다."));
Category category = categoryRepository.findById(requestDto.getCategoryId()).orElseThrow(() -> new IllegalArgumentException("해당 category id가 없습니다."));
project.modify(requestDto, category);


for(int i=0;i<requestDto.getItemList().size();i++){
MySalesItemDto itemDto = requestDto.getItemList().get(i);
Item item = itemRepository.findItemById(itemDto.getItemId());
item.modify(itemDto);
itemRepository.save(item);
}

projectRepository.save(project);
return new ResponseEntity(HttpStatus.OK);
}
Expand Down

0 comments on commit 2ff38d6

Please sign in to comment.