Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

item register #24

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public static ItemDetailResponseDto.ItemDetailDto toDto(Item item, List<Gradient
.itemId(item.getItemId())
.zeroSugar(item.isZeroSugar())
.zeroKcal(item.isZeroKcal())
.itemUrl(defaultUrl+item.getUrl())
.itemUrl(defaultUrl + "/"+item.getUrl())
.company(item.getCompany())
.store(item.getStore())
.createdAt(item.getCreatedAt())
.updatedAt(item.getUpdatedAt())
.name(item.getName())
.price(item.getPrice())
.nutritionUrl(defaultUrl+item.getNutritionUrl())
.nutritionUrl(defaultUrl + "/"+item.getNutritionUrl())
.gradientCnt(item.getGradientList().size())
.infoUrl(defaultUrl+item.getInfoUrl())
.infoUrl(defaultUrl + "/"+item.getInfoUrl())
.like(like)
.gradientDto(gradientDto)
.build();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/team1/hackerton/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.*;
import org.springframework.stereotype.Service;
import team1.hackerton.domain.common.BaseEntity;

import java.util.ArrayList;
Expand All @@ -11,7 +12,8 @@
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Item extends BaseEntity {

Expand Down
1 change: 1 addition & 0 deletions src/main/java/team1/hackerton/security/JwtAuthFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
|| requestURI.contains("/auth/login")
|| requestURI.contains("/swagger-ui/")
|| requestURI.contains("/v3/api-docs")
|| requestURI.contains("/record")
|| requestURI.contains("/swagger-resources")
|| requestURI.equals("/swagger-ui.html"))
{
Expand Down
42 changes: 31 additions & 11 deletions src/main/java/team1/hackerton/service/TestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.ObjectMetadata;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import team1.hackerton.domain.Item;
import team1.hackerton.repository.ItemRepository;

import java.io.IOException;
import java.util.UUID;
Expand All @@ -22,19 +25,36 @@ public class TestService {

private final AmazonS3Client amazonS3Client;

public void uploadS3(MultipartFile[] files) throws IOException {
if(files != null && files.length > 0) {
for(MultipartFile file : files) {
String originalFilename = file.getOriginalFilename();
String newfileName = UUID.randomUUID()+"_"+originalFilename;

ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(file.getSize());
metadata.setContentType(file.getContentType());
@Autowired
private ItemRepository itemRepository;

//S3에 저장
amazonS3Client.putObject(bucket, newfileName, file.getInputStream(), metadata);
public void uploadS3(MultipartFile[] files) throws IOException {
Item item = new Item();

for(int i = 0; i < files.length; i++) {
MultipartFile file = files[i];
String originalFilename = file.getOriginalFilename();
String newFileName = UUID.randomUUID() + "_" + originalFilename;

ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(file.getSize());
metadata.setContentType(file.getContentType());

// S3에 파일 업로드
amazonS3Client.putObject(bucket, newFileName, file.getInputStream(), metadata);

// 파일 유형에 따라 Item 속성에 저장
if (i == 0) {
item.setUrl(newFileName);
} else if (i == 1) {
item.setInfoUrl(newFileName);
} else if (i == 2) {
item.setNutritionUrl(newFileName);
}
}
itemRepository.save(item);



}
}
Loading