Skip to content

Commit

Permalink
Merge pull request #67 from 2024-startup/BE/feat/#62
Browse files Browse the repository at this point in the history
[Be/feat/#62] 민기의 api 1차 테스트 완료
  • Loading branch information
heondong9265 authored May 15, 2024
2 parents 80e1119 + 4b2659d commit 4c3c5b2
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 39 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,60 +1,67 @@
package project.one.auction.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import project.one.auction.domain.Auction;
import project.one.auction.domain.AuctionModifyRequest;
import project.one.auction.service.AuctionService;
import project.one.global.Response.MakeResponse;
import project.one.global.Response.ResponseMessage;

import java.io.IOException;
import java.util.List;

import static project.one.global.Response.MakeResponse.getResponseMessage;

@RestController
@RequestMapping("/auctions")
@RequiredArgsConstructor
public class AuctionController {

private final AuctionService auctionService;

@PostMapping
public ResponseEntity<Auction> createAuction(@RequestBody AuctionModifyRequest request) {
Auction createdAuction = auctionService.createAuction(request);
return ResponseEntity.status(HttpStatus.CREATED).body(createdAuction);
@Operation(summary = "견적 의뢰서 생성", description = "견적 의뢰서 생성 API")
@PostMapping(value = "/{categoryId}")
public ResponseEntity<ResponseMessage<Object>> createAuction(@PathVariable(value = "categoryId") Long categoryId,
@RequestBody AuctionModifyRequest request)
{
Auction createdAuction = auctionService.createAuction(categoryId, request);
return MakeResponse.getResponseMessage(HttpStatus.OK,"경매 생성 성공",createdAuction);
}

@PostMapping("/{auctionId}/images")
public ResponseEntity<Auction> addImageToAuction(
@PathVariable Long auctionId,
@RequestParam String imageUrl) {
Auction updatedAuction = auctionService.addImageToAuction(auctionId, imageUrl);
return ResponseEntity.ok(updatedAuction);
}

@Operation(summary = "경매 전체 조회", description = "경매 전체 조회 API")
@GetMapping
public ResponseEntity<List<Auction>> getAllAuctions() {
public ResponseEntity<ResponseMessage<List<Auction>>> getAllAuctions() {
List<Auction> auctions = auctionService.getAllAuctions();
return ResponseEntity.ok(auctions);
return MakeResponse.getResponseMessage(HttpStatus.OK,"경매 전체 조회 성공",auctions);
}

@Operation(summary = "경매 ID로 조회", description = "경매 ID로 조회 API")
@GetMapping("/{auctionId}")
public ResponseEntity<Auction> getAuctionById(@PathVariable Long auctionId) {
public ResponseEntity<ResponseMessage<Auction>> getAuctionById(@PathVariable(value = "auctionId") Long auctionId) {
Auction auction = auctionService.getAuctionById(auctionId);
return ResponseEntity.ok(auction);
return MakeResponse.getResponseMessage(HttpStatus.OK,"경매 ID로 조회 성공",auction);
}

@Operation(summary = "경매 수정", description = "경매 수정 API")
@PutMapping("/{auctionId}")
public ResponseEntity<Auction> modifyAuction(
@PathVariable Long auctionId,
public ResponseEntity<ResponseMessage<Auction>> modifyAuction(
@PathVariable(value = "auctionId") Long auctionId,
@RequestBody AuctionModifyRequest request) {
Auction modifiedAuction = auctionService.modifyAuction(auctionId, request);
return ResponseEntity.ok(modifiedAuction);
return MakeResponse.getResponseMessage(HttpStatus.OK,"경매 수정 완료",modifiedAuction);
}

@Operation(summary = "경매 삭제", description = "경매 삭제 API")
@DeleteMapping("/{auctionId}")
public ResponseEntity<Void> deleteAuction(@PathVariable Long auctionId) {
public ResponseEntity<ResponseMessage<Object>> deleteAuction(@PathVariable(value = "auctionId") Long auctionId) {
auctionService.deleteAuction(auctionId);
return ResponseEntity.noContent().build();
return MakeResponse.getResponseMessage(HttpStatus.OK,"경매 삭제 완료");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package project.one.auction.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -13,15 +11,15 @@
@Entity
public class Auction {

@Id
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "user_id")
private String userId;

@Column(name = "category_id")
private String categoryId;
private Long categoryId;

@Column(name = "place")
private String place;
Expand Down Expand Up @@ -50,4 +48,10 @@ public class Auction {
@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@PrePersist // 생성 시간 자동 저장
public void prePersist() {
LocalDateTime now = LocalDateTime.now();
createdAt = now;
updatedAt = now;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,11 @@
@NoArgsConstructor
@AllArgsConstructor
public class AuctionModifyRequest {
private Long id;
private String userId;
private String categoryId;
//private String categoryId;
private String place;
private String photoUrl;
//private String photoUrl;
private String title;
private LocalDateTime scheduleDate;
private String content;
private String budget;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private LocalDateTime deletedAt;


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import project.one.auction.domain.Auction;
import project.one.auction.domain.AuctionModifyRequest;
import project.one.auction.domain.AuctionRepository;
Expand All @@ -17,10 +18,10 @@ public class AuctionService {
private final AuctionRepository auctionRepository;

// 사용자 견적 의뢰서 생성
public Auction createAuction(AuctionModifyRequest request) {
public Auction createAuction(Long categoryId, AuctionModifyRequest request) {
Auction auction = new Auction();
auction.setCategoryId(request.getCategoryId());
auction.setUserId(request.getUserId());
auction.setCategoryId(categoryId);
//auction.setUserId(request.getUserId());
auction.setTitle(request.getTitle());
auction.setContent(request.getContent());
auction.setBudget(request.getBudget());
Expand Down Expand Up @@ -63,8 +64,8 @@ public Auction modifyAuction(Long auctionId, AuctionModifyRequest request) {
Optional<Auction> optionalAuction = auctionRepository.findById(auctionId);
if (optionalAuction.isPresent()) {
Auction auction = optionalAuction.get();
auction.setCategoryId(request.getCategoryId());
auction.setUserId(request.getUserId());
//auction.setCategoryId(categoryId);
//auction.setUserId(request.getUserId());
auction.setTitle(request.getTitle());
auction.setContent(request.getContent());
auction.setBudget(request.getBudget());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package project.one.global.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

import java.lang.reflect.Type;

@Component
public class MultipartConverter extends AbstractJackson2HttpMessageConverter {
public MultipartConverter(ObjectMapper objectMapper) {
super(objectMapper, MediaType.APPLICATION_OCTET_STREAM);
}

@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
protected boolean canWrite(MediaType mediaType) {
return false;
}
}

0 comments on commit 4c3c5b2

Please sign in to comment.