diff --git a/backend/Dockerfile b/backend/Dockerfile deleted file mode 100644 index 60a6416..0000000 --- a/backend/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM openjdk:17 -ARG JAR_FILE=ready/build/libs/server.jar -COPY ${JAR_FILE} /home/server.jar -ENTRYPOINT ["java","-jar","/home/server.jar"] diff --git a/backend/ready/Dockerfile b/backend/ready/Dockerfile new file mode 100644 index 0000000..a020094 --- /dev/null +++ b/backend/ready/Dockerfile @@ -0,0 +1,21 @@ + + +FROM openjdk:17 AS builder + +# 패키지를 설치해야, bootJAR 를 실행할 수 있다 +RUN microdnf install findutils + +COPY gradlew . +COPY gradle gradle +COPY build.gradle . +COPY settings.gradle . +COPY src src + +RUN chmod +x ./gradlew +RUN ./gradlew bootJAR + + +FROM openjdk:17 + +# 위 builder에서 만든 .jar파일을 컨테이너 내부로 복사 +COPY --from=builder build/libs/*.jar app/app.jar \ No newline at end of file diff --git a/backend/ready/build/classes/java/main/project/one/OneApplication.class b/backend/ready/build/classes/java/main/project/one/OneApplication.class index 694ae53..7e5240b 100644 Binary files a/backend/ready/build/classes/java/main/project/one/OneApplication.class and b/backend/ready/build/classes/java/main/project/one/OneApplication.class differ diff --git a/backend/ready/build/classes/java/main/project/one/auctionbids/dto/AuctionBidRequest.class b/backend/ready/build/classes/java/main/project/one/auctionbids/dto/AuctionBidRequest.class index c5d66c9..f0f0d34 100644 Binary files a/backend/ready/build/classes/java/main/project/one/auctionbids/dto/AuctionBidRequest.class and b/backend/ready/build/classes/java/main/project/one/auctionbids/dto/AuctionBidRequest.class differ diff --git a/backend/ready/build/classes/java/main/project/one/auctionbids/dto/AuctionBidResponse.class b/backend/ready/build/classes/java/main/project/one/auctionbids/dto/AuctionBidResponse.class index e6c3f59..dece006 100644 Binary files a/backend/ready/build/classes/java/main/project/one/auctionbids/dto/AuctionBidResponse.class and b/backend/ready/build/classes/java/main/project/one/auctionbids/dto/AuctionBidResponse.class differ diff --git a/backend/ready/build/classes/java/main/project/one/auctionbids/service/AuctionBidService.class b/backend/ready/build/classes/java/main/project/one/auctionbids/service/AuctionBidService.class index 36f387a..c567ccf 100644 Binary files a/backend/ready/build/classes/java/main/project/one/auctionbids/service/AuctionBidService.class and b/backend/ready/build/classes/java/main/project/one/auctionbids/service/AuctionBidService.class differ diff --git a/backend/ready/build/classes/java/main/project/one/business/controller/BusinessController.class b/backend/ready/build/classes/java/main/project/one/business/controller/BusinessController.class index 49ca811..ce22f58 100644 Binary files a/backend/ready/build/classes/java/main/project/one/business/controller/BusinessController.class and b/backend/ready/build/classes/java/main/project/one/business/controller/BusinessController.class differ diff --git a/backend/ready/build/classes/java/main/project/one/business/domain/Business.class b/backend/ready/build/classes/java/main/project/one/business/domain/Business.class index e771dcd..b14a445 100644 Binary files a/backend/ready/build/classes/java/main/project/one/business/domain/Business.class and b/backend/ready/build/classes/java/main/project/one/business/domain/Business.class differ diff --git a/backend/ready/build/classes/java/main/project/one/business/dto/BusinessRequest.class b/backend/ready/build/classes/java/main/project/one/business/dto/BusinessRequest.class new file mode 100644 index 0000000..94d426f Binary files /dev/null and b/backend/ready/build/classes/java/main/project/one/business/dto/BusinessRequest.class differ diff --git a/backend/ready/build/classes/java/main/project/one/business/dto/BusinessResponse.class b/backend/ready/build/classes/java/main/project/one/business/dto/BusinessResponse.class new file mode 100644 index 0000000..a7867b2 Binary files /dev/null and b/backend/ready/build/classes/java/main/project/one/business/dto/BusinessResponse.class differ diff --git a/backend/ready/build/classes/java/main/project/one/business/service/BusinessService.class b/backend/ready/build/classes/java/main/project/one/business/service/BusinessService.class index 7d41b44..56d8287 100644 Binary files a/backend/ready/build/classes/java/main/project/one/business/service/BusinessService.class and b/backend/ready/build/classes/java/main/project/one/business/service/BusinessService.class differ diff --git a/backend/ready/build/classes/java/main/project/one/category/domain/Category.class b/backend/ready/build/classes/java/main/project/one/category/domain/Category.class new file mode 100644 index 0000000..0a134ca Binary files /dev/null and b/backend/ready/build/classes/java/main/project/one/category/domain/Category.class differ diff --git a/backend/ready/build/classes/java/main/project/one/category/domain/CategoryEnum.class b/backend/ready/build/classes/java/main/project/one/category/domain/CategoryEnum.class deleted file mode 100644 index 052e176..0000000 Binary files a/backend/ready/build/classes/java/main/project/one/category/domain/CategoryEnum.class and /dev/null differ diff --git a/backend/ready/build/classes/java/main/project/one/category/domain/CategoryRepository.class b/backend/ready/build/classes/java/main/project/one/category/domain/CategoryRepository.class new file mode 100644 index 0000000..accac2a Binary files /dev/null and b/backend/ready/build/classes/java/main/project/one/category/domain/CategoryRepository.class differ diff --git a/backend/ready/build/resources/main/application.properties b/backend/ready/build/resources/main/application.properties index 3522668..b9f3098 100644 --- a/backend/ready/build/resources/main/application.properties +++ b/backend/ready/build/resources/main/application.properties @@ -3,7 +3,8 @@ spring.datasource.password= ${SPRING_DATASOURCE_PASSWORD} spring.datasource.username= ${SPRING_DATASOURCE_USERNAME} spring.datasource.driver.class.name= ${SPRING_DATASOURCE_DRIVER_CLASS_NAME} spring.jpa.database=${SPRING_JPA_DATABASE} -spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=create + s3.bucket.url=${S3_BUCKET_URL} s3.bucket.name=${S3_BUCKET_NAME} diff --git a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionBidController.class.uniqueId0 b/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionBidController.class.uniqueId0 deleted file mode 100644 index 14b2a56..0000000 Binary files a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionBidController.class.uniqueId0 and /dev/null differ diff --git a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionBidService.class.uniqueId1 b/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionBidService.class.uniqueId1 deleted file mode 100644 index 36f387a..0000000 Binary files a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionBidService.class.uniqueId1 and /dev/null differ diff --git a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionController.class.uniqueId3 b/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionController.class.uniqueId3 deleted file mode 100644 index 522fdd5..0000000 Binary files a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionController.class.uniqueId3 and /dev/null differ diff --git a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionService.class.uniqueId4 b/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionService.class.uniqueId4 deleted file mode 100644 index d5eabec..0000000 Binary files a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/AuctionService.class.uniqueId4 and /dev/null differ diff --git a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/OneApplication.class.uniqueId0 b/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/OneApplication.class.uniqueId0 new file mode 100644 index 0000000..01fd248 Binary files /dev/null and b/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/OneApplication.class.uniqueId0 differ diff --git a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/S3Service.class.uniqueId2 b/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/S3Service.class.uniqueId2 deleted file mode 100644 index 615b435..0000000 Binary files a/backend/ready/build/tmp/compileJava/compileTransaction/stash-dir/S3Service.class.uniqueId2 and /dev/null differ diff --git a/backend/ready/build/tmp/compileJava/previous-compilation-data.bin b/backend/ready/build/tmp/compileJava/previous-compilation-data.bin index db19c0c..ce01e3d 100644 Binary files a/backend/ready/build/tmp/compileJava/previous-compilation-data.bin and b/backend/ready/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/backend/ready/src/main/java/project/one/OneApplication.java b/backend/ready/src/main/java/project/one/OneApplication.java index 66287d8..81780ca 100644 --- a/backend/ready/src/main/java/project/one/OneApplication.java +++ b/backend/ready/src/main/java/project/one/OneApplication.java @@ -1,31 +1,26 @@ package project.one; -import io.github.cdimascio.dotenv.Dotenv; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.servers.Server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -import java.util.TimeZone; - @OpenAPIDefinition(servers = {@Server(url = "/", description = "Default Server URL")}) @SpringBootApplication(exclude = SecurityAutoConfiguration.class) public class OneApplication { public static void main(String[] args) { - Dotenv dotenv = Dotenv.load(); - System.setProperty("spring.datasource.url", dotenv.get("SPRING_DATASOURCE_URL")); - System.setProperty("spring.datasource.password", dotenv.get("SPRING_DATASOURCE_PASSWORD")); - System.setProperty("spring.datasource.username", dotenv.get("SPRING_DATASOURCE_USERNAME")); - System.setProperty("spring.datasource.driver.class.name", dotenv.get("SPRING_DATASOURCE_DRIVER_CLASS_NAME")); - System.setProperty("spring.jpa.database", dotenv.get("SPRING_JPA_DATABASE")); - System.setProperty("s3.access.key", dotenv.get("S3_ACCESS_KEY")); - System.setProperty("s3.secret.key", dotenv.get("S3_SECRET_KEY")); - System.setProperty("s3.bucket.url", dotenv.get("S3_BUCKET_URL")); - System.setProperty("s3.bucket.name", dotenv.get("S3_BUCKET_NAME")); + System.setProperty("spring.datasource.url", System.getenv("SPRING_DATASOURCE_URL")); + System.setProperty("spring.datasource.password", System.getenv("SPRING_DATASOURCE_PASSWORD")); + System.setProperty("spring.datasource.username", System.getenv("SPRING_DATASOURCE_USERNAME")); + System.setProperty("spring.datasource.driver.class.name", System.getenv("SPRING_DATASOURCE_DRIVER_CLASS_NAME")); + System.setProperty("spring.jpa.database", System.getenv("SPRING_JPA_DATABASE")); + System.setProperty("s3.access.key", System.getenv("S3_ACCESS_KEY")); + System.setProperty("s3.secret.key", System.getenv("S3_SECRET_KEY")); + System.setProperty("s3.bucket.url", System.getenv("S3_BUCKET_URL")); + System.setProperty("s3.bucket.name", System.getenv("S3_BUCKET_NAME")); SpringApplication.run(OneApplication.class, args); } - -} \ No newline at end of file +} diff --git a/backend/ready/src/main/java/project/one/auctionbids/dto/AuctionBidRequest.java b/backend/ready/src/main/java/project/one/auctionbids/dto/AuctionBidRequest.java index 69e2939..7d7c071 100644 --- a/backend/ready/src/main/java/project/one/auctionbids/dto/AuctionBidRequest.java +++ b/backend/ready/src/main/java/project/one/auctionbids/dto/AuctionBidRequest.java @@ -9,11 +9,10 @@ @Setter public class AuctionBidRequest { private Long auctionId; -// private Long businessId; + private Long businessId; private String content; private String materialName; private String materialDescription; - private String materialPhoto; private Long materialCost; private Long laborCost; private Long saleCost; diff --git a/backend/ready/src/main/java/project/one/auctionbids/dto/AuctionBidResponse.java b/backend/ready/src/main/java/project/one/auctionbids/dto/AuctionBidResponse.java index b1f5c90..5852def 100644 --- a/backend/ready/src/main/java/project/one/auctionbids/dto/AuctionBidResponse.java +++ b/backend/ready/src/main/java/project/one/auctionbids/dto/AuctionBidResponse.java @@ -1,6 +1,5 @@ package project.one.auctionbids.dto; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Getter; import lombok.Setter; @@ -12,7 +11,7 @@ public class AuctionBidResponse { private Long auctionBidId; private Long auctionId; -// private Long businessId; + private Long businessId; private String content; private String materialName; private String materialDescription; @@ -26,12 +25,13 @@ public class AuctionBidResponse { private LocalDate startDate; private LocalDate endDate; - public AuctionBidResponse(Long auctionBidId, Long auctionId, String content, String materialName, + public AuctionBidResponse(Long auctionBidId, Long auctionId, Long businessId, String content, String materialName, String materialDescription, String materialPhoto, Long materialCost, Long laborCost, Long saleCost, Long totalCost, String additionalContent, String status, LocalDate startDate, LocalDate endDate) { this.auctionBidId = auctionBidId; this.auctionId = auctionId; + this.businessId = businessId; this.content = content; this.materialName = materialName; this.materialDescription = materialDescription; diff --git a/backend/ready/src/main/java/project/one/auctionbids/service/AuctionBidService.java b/backend/ready/src/main/java/project/one/auctionbids/service/AuctionBidService.java index d1cebb8..ebf8d19 100644 --- a/backend/ready/src/main/java/project/one/auctionbids/service/AuctionBidService.java +++ b/backend/ready/src/main/java/project/one/auctionbids/service/AuctionBidService.java @@ -11,6 +11,7 @@ import project.one.auctionbids.dto.AuctionBidRequest; import project.one.auctionbids.dto.AuctionBidResponse; import project.one.auctionbids.exception.AuctionBidNotFoundException; +import project.one.business.domain.Business; import project.one.business.domain.BusinessRepository; import java.io.IOException; @@ -40,20 +41,21 @@ public AuctionBidService(AuctionBidRepository auctionBidRepository, public AuctionBidResponse createAuctionBid(AuctionBidRequest auctionBidRequest, MultipartFile file) throws IOException { Auction auction = auctionRepository.findById(auctionBidRequest.getAuctionId()) .orElseThrow(() -> new IllegalStateException("해당 경매가 존재하지 않습니다.")); -// Business business = businessRepository.findById(auctionBidCreateRequest.getBusinessId()) -// .orElseThrow(() -> new IllegalStateException("해당 사업자가 존재하지 않습니다.")); + Business business = businessRepository.findById(auctionBidRequest.getBusinessId()) + .orElseThrow(() -> new IllegalStateException("해당 사업자가 존재하지 않습니다.")); // S3에 파일 업로드 - String photoUrl = s3Service.photoUploadToS3(file, auction.getId(), auction.getId()); + String photoUrl = s3Service.photoUploadToS3(file, business.getId(), auction.getId()); - AuctionBid auctionBid = buildAuctionBid(auctionBidRequest, auction, photoUrl); + AuctionBid auctionBid = buildAuctionBid(auctionBidRequest, auction, business, photoUrl); AuctionBid savedBid = auctionBidRepository.save(auctionBid); return toDto(savedBid); } - private AuctionBid buildAuctionBid(AuctionBidRequest auctionBidRequest, Auction auction, String photoUrl) { + private AuctionBid buildAuctionBid(AuctionBidRequest auctionBidRequest, Auction auction, Business business, String photoUrl) { return AuctionBid.builder() .auction(auction) + .business(business) .content(auctionBidRequest.getContent()) .materialName(auctionBidRequest.getMaterialName()) .materialDescription(auctionBidRequest.getMaterialDescription()) @@ -73,14 +75,14 @@ public AuctionBidResponse updateAuctionBid(Long id, AuctionBidRequest request, M AuctionBid auctionBid = auctionBidRepository.findById(id) .orElseThrow(AuctionBidNotFoundException::new); - String photoUrl = s3Service.photoUploadToS3(file, auctionBid.getAuction().getId(), auctionBid.getAuction().getId()); + String photoUrl = s3Service.photoUploadToS3(file, auctionBid.getBusiness().getId(), auctionBid.getAuction().getId()); updateAuctionBids(auctionBid, request, photoUrl); auctionBidRepository.save(auctionBid); return toDto(auctionBid); } - private AuctionBid updateAuctionBids(AuctionBid auctionBid, AuctionBidRequest request, String photoUrl) { + private void updateAuctionBids(AuctionBid auctionBid, AuctionBidRequest request, String photoUrl) { auctionBid.setContent(request.getContent()); auctionBid.setMaterialName(request.getMaterialName()); auctionBid.setMaterialDescription(request.getMaterialDescription()); @@ -92,25 +94,6 @@ private AuctionBid updateAuctionBids(AuctionBid auctionBid, AuctionBidRequest re auctionBid.setAdditionalContent(request.getAdditionalContent()); auctionBid.setStartDate(request.getStartDate()); auctionBid.setEndDate(request.getEndDate()); - return auctionBid; - } - private AuctionBidResponse toDto(AuctionBid auctionBid) { - return new AuctionBidResponse( - auctionBid.getId(), - auctionBid.getAuction().getId(), - auctionBid.getContent(), - auctionBid.getMaterialName(), - auctionBid.getMaterialDescription(), - auctionBid.getMaterialPhoto(), - auctionBid.getMaterialCost(), - auctionBid.getLaborCost(), - auctionBid.getSaleCost(), - auctionBid.getTotalCost(), - auctionBid.getAdditionalContent(), - auctionBid.getStatus(), - auctionBid.getStartDate(), - auctionBid.getEndDate() - ); } public void deleteAuctionBid(Long id) { @@ -132,4 +115,24 @@ public List findAllAuctionBids() { .map(this::toDto) .toList(); } + + private AuctionBidResponse toDto(AuctionBid auctionBid) { + return new AuctionBidResponse( + auctionBid.getId(), + auctionBid.getAuction().getId(), + auctionBid.getBusiness().getId(), + auctionBid.getContent(), + auctionBid.getMaterialName(), + auctionBid.getMaterialDescription(), + auctionBid.getMaterialPhoto(), + auctionBid.getMaterialCost(), + auctionBid.getLaborCost(), + auctionBid.getSaleCost(), + auctionBid.getTotalCost(), + auctionBid.getAdditionalContent(), + auctionBid.getStatus(), + auctionBid.getStartDate(), + auctionBid.getEndDate() + ); + } } \ No newline at end of file diff --git a/backend/ready/src/main/java/project/one/business/controller/BusinessController.java b/backend/ready/src/main/java/project/one/business/controller/BusinessController.java index faca801..24d6c5f 100644 --- a/backend/ready/src/main/java/project/one/business/controller/BusinessController.java +++ b/backend/ready/src/main/java/project/one/business/controller/BusinessController.java @@ -1,6 +1,40 @@ package project.one.business.controller; + +import io.swagger.v3.oas.annotations.Operation; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.server.ResponseStatusException; +import project.one.business.dto.BusinessRequest; +import project.one.business.dto.BusinessResponse; +import project.one.business.service.BusinessService; + + + +@RestController +@RequestMapping("/business") public class BusinessController { + private final BusinessService businessService; + public BusinessController(BusinessService businessService) { + this.businessService = businessService; + } + @Operation(summary = "업체 등록", description = "업체 정보와 관련 파일을 등록합니다.") + @PostMapping(value = "/register", consumes = "multipart/form-data") + public ResponseEntity registerBusiness( + @RequestPart("request") BusinessRequest request, + @RequestPart("businessLicense") MultipartFile businessLicense, + @RequestPart("businessIdentification") MultipartFile businessIdentification, + @RequestPart("businessImage") MultipartFile businessImage) { + try { + BusinessResponse response = businessService.registerBusiness(request, businessLicense, businessIdentification, businessImage); + return ResponseEntity.ok(response); + } catch (Exception e) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Error registering business", e); + } + } } diff --git a/backend/ready/src/main/java/project/one/business/domain/Business.java b/backend/ready/src/main/java/project/one/business/domain/Business.java index 87daa90..8b7a318 100644 --- a/backend/ready/src/main/java/project/one/business/domain/Business.java +++ b/backend/ready/src/main/java/project/one/business/domain/Business.java @@ -2,10 +2,13 @@ import jakarta.persistence.*; import lombok.Getter; +import lombok.Setter; +import project.one.category.domain.Category; import project.one.user.domain.User; @Entity @Getter +@Setter public class Business { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -15,11 +18,19 @@ public class Business { @JoinColumn(name = "user_id") private User user; - private String businessType; - private String businessLicense; - private String businessIdentification; - private String businessNumber; - private String businessImage; + @ManyToOne + @JoinColumn(name = "category_id") + private Category category; + private String businessType; //개인 or 사업자 + private String businessLicense; //사업자등록증 + private String businessIdentification; //신분증 + private String businessNumber; //사업자번호 + private String businessImage; //대표 이미지 + private boolean isVerified = false; + + private String businessName; + private String businessAddress; + private String businessDetailAddress; } diff --git a/backend/ready/src/main/java/project/one/business/dto/BusinessRequest.java b/backend/ready/src/main/java/project/one/business/dto/BusinessRequest.java new file mode 100644 index 0000000..56b4454 --- /dev/null +++ b/backend/ready/src/main/java/project/one/business/dto/BusinessRequest.java @@ -0,0 +1,17 @@ +package project.one.business.dto; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.web.multipart.MultipartFile; + +@Getter +@Setter +public class BusinessRequest { + private Long userId; + private Long categoryId; + private String businessType; + private String businessNumber; + private String businessName; + private String businessAddress; + private String businessDetailAddress; +} diff --git a/backend/ready/src/main/java/project/one/business/dto/BusinessResponse.java b/backend/ready/src/main/java/project/one/business/dto/BusinessResponse.java new file mode 100644 index 0000000..3f4efab --- /dev/null +++ b/backend/ready/src/main/java/project/one/business/dto/BusinessResponse.java @@ -0,0 +1,39 @@ +package project.one.business.dto; + + +import lombok.Getter; +import lombok.Setter; +import project.one.business.domain.Business; + +@Getter +@Setter +public class BusinessResponse { + private Long businessId; + private Long userId; + private Long categoryId; + private String businessType; + private String businessLicense; + private String businessIdentification; + private String businessNumber; + private String businessImage; + private String businessName; + private String businessAddress; + private String businessDetailAddress; + private boolean isVerified; + + public BusinessResponse(Business business) { + this.businessId = business.getId(); + this.userId = business.getUser().getId(); + this.categoryId = business.getCategory().getId(); + this.businessType = business.getBusinessType(); + this.businessLicense = business.getBusinessLicense(); + this.businessIdentification = business.getBusinessIdentification(); + this.businessNumber = business.getBusinessNumber(); + this.businessImage = business.getBusinessImage(); + this.businessName = business.getBusinessName(); + this.businessAddress = business.getBusinessAddress(); + this.businessDetailAddress = business.getBusinessDetailAddress(); + this.isVerified = business.isVerified(); + } +} + diff --git a/backend/ready/src/main/java/project/one/business/service/BusinessService.java b/backend/ready/src/main/java/project/one/business/service/BusinessService.java index 323757e..b4835b8 100644 --- a/backend/ready/src/main/java/project/one/business/service/BusinessService.java +++ b/backend/ready/src/main/java/project/one/business/service/BusinessService.java @@ -1,4 +1,63 @@ package project.one.business.service; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import project.one.S3.S3Service; +import project.one.business.domain.Business; +import project.one.business.domain.BusinessRepository; +import project.one.business.dto.BusinessRequest; +import project.one.business.dto.BusinessResponse; +import project.one.category.domain.Category; +import project.one.category.domain.CategoryRepository; +import project.one.user.domain.User; +import project.one.user.domain.UserRepository; + +import java.io.IOException; + +@Service +@Transactional public class BusinessService { + private final BusinessRepository businessRepository; + private final S3Service s3Service; + private final UserRepository userRepository; + private final CategoryRepository categoryRepository; + + public BusinessService(BusinessRepository businessRepository, S3Service s3Service, UserRepository userRepository, CategoryRepository categoryRepository) { + this.businessRepository = businessRepository; + this.s3Service = s3Service; + this.userRepository = userRepository; + this.categoryRepository = categoryRepository; + } + + public BusinessResponse registerBusiness(BusinessRequest businessRequest, MultipartFile businessLicenseFile, MultipartFile businessIdentificationFile, MultipartFile businessImageFile) throws IOException { + User user = userRepository.findById(businessRequest.getUserId()) + .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 사용자입니다.")); + Category category = categoryRepository.findById(businessRequest.getCategoryId()) + .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 카테고리입니다.")); + + String businessLicense = s3Service.photoUploadToS3(businessLicenseFile, user.getId(), null); + String businessIdentification = s3Service.photoUploadToS3(businessIdentificationFile, user.getId(), null); + String businessImage = s3Service.photoUploadToS3(businessImageFile, user.getId(), null); + + Business business = new Business(); + business.setUser(user); + business.setCategory(category); + business.setBusinessType(businessRequest.getBusinessType()); + business.setBusinessLicense(businessLicense); + business.setBusinessIdentification(businessIdentification); + business.setBusinessNumber(businessRequest.getBusinessNumber()); + business.setBusinessImage(businessImage); + business.setBusinessName(businessRequest.getBusinessName()); + business.setBusinessAddress(businessRequest.getBusinessAddress()); + business.setBusinessDetailAddress(businessRequest.getBusinessDetailAddress()); + business.setVerified(true); // 바로 인증 상태로 설정 + + businessRepository.save(business); + return convertToBusinessResponse(business); + } + + private BusinessResponse convertToBusinessResponse(Business business) { + return new BusinessResponse(business); + } } diff --git a/backend/ready/src/main/java/project/one/category/domain/Category.java b/backend/ready/src/main/java/project/one/category/domain/Category.java new file mode 100644 index 0000000..fa85645 --- /dev/null +++ b/backend/ready/src/main/java/project/one/category/domain/Category.java @@ -0,0 +1,14 @@ +package project.one.category.domain; + +import jakarta.persistence.*; +import lombok.Getter; + +@Entity +@Getter +public class Category { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "category_id") + private Long id; + private String name; +} diff --git a/backend/ready/src/main/java/project/one/category/domain/CategoryEnum.java b/backend/ready/src/main/java/project/one/category/domain/CategoryEnum.java deleted file mode 100644 index 9d34fce..0000000 --- a/backend/ready/src/main/java/project/one/category/domain/CategoryEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package project.one.category.domain; - -import lombok.Getter; - -@Getter -public enum CategoryEnum { - WALLPAPER("도배/벽지"), - FILM("필름"), - PAINT("페인트"), - TILE("타일"), - WOODEN_FLOORING("마루"), - LINOLEUM("장판"), - BATHROOM("욕실"), - SINK("싱크대"), - BUILT_IN_WARDROBE("붙박이장"), - CURTAIN("커튼"), - SLIDING_DOOR("중문"), - WINDOW("창호/샷시"); - - private final String categoryName; - - CategoryEnum(String categoryName) { - this.categoryName = categoryName; - } - - public static CategoryEnum fromString(String input) { - for (CategoryEnum category : CategoryEnum.values()) { - if (category.name().equalsIgnoreCase(input) || category.getCategoryName().equalsIgnoreCase(input)) { - return category; - } - } - throw new IllegalArgumentException("카테고리를 찾을 수 없습니다 : " + input); - } - -} diff --git a/backend/ready/src/main/java/project/one/category/domain/CategoryRepository.java b/backend/ready/src/main/java/project/one/category/domain/CategoryRepository.java new file mode 100644 index 0000000..692fa65 --- /dev/null +++ b/backend/ready/src/main/java/project/one/category/domain/CategoryRepository.java @@ -0,0 +1,6 @@ +package project.one.category.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CategoryRepository extends JpaRepository{ +} diff --git a/backend/ready/src/main/resources/application.properties b/backend/ready/src/main/resources/application.properties index f5bce63..b9f3098 100644 --- a/backend/ready/src/main/resources/application.properties +++ b/backend/ready/src/main/resources/application.properties @@ -3,6 +3,7 @@ spring.datasource.password= ${SPRING_DATASOURCE_PASSWORD} spring.datasource.username= ${SPRING_DATASOURCE_USERNAME} spring.datasource.driver.class.name= ${SPRING_DATASOURCE_DRIVER_CLASS_NAME} spring.jpa.database=${SPRING_JPA_DATABASE} +spring.jpa.hibernate.ddl-auto=create s3.bucket.url=${S3_BUCKET_URL}