Skip to content

Commit

Permalink
Merge pull request #78 from 2024-startup/BE/feat/#77
Browse files Browse the repository at this point in the history
feat : 업체 등록 구현 및 도커 수정
  • Loading branch information
fallkim authored May 20, 2024
2 parents 4044957 + b899155 commit 6e9e127
Show file tree
Hide file tree
Showing 35 changed files with 252 additions and 91 deletions.
4 changes: 0 additions & 4 deletions backend/Dockerfile

This file was deleted.

21 changes: 21 additions & 0 deletions backend/ready/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion backend/ready/build/resources/main/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 10 additions & 15 deletions backend/ready/src/main/java/project/one/OneApplication.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package project.one.auctionbids.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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());
Expand All @@ -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) {
Expand All @@ -132,4 +115,24 @@ public List<AuctionBidResponse> 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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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<BusinessResponse> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

Loading

0 comments on commit 6e9e127

Please sign in to comment.