-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/h-jjang/bauction into fe…
…ature/#34-매물-검색-기능-구현 � Conflicts: � backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java
- Loading branch information
Showing
64 changed files
with
984 additions
and
696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
backend/src/main/java/com/hjjang/backend/domain/image/controller/ImageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.hjjang.backend.domain.image.controller; | ||
|
||
import com.hjjang.backend.domain.image.domain.entity.Image; | ||
import com.hjjang.backend.domain.image.dto.ImagePathResponse; | ||
import com.hjjang.backend.domain.image.service.ImageService; | ||
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 java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.hjjang.backend.global.util.HttpStatusResponseEntity.RESPONSE_OK; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/images") | ||
public class ImageController { | ||
|
||
private final ImageService imageService; | ||
|
||
@GetMapping() | ||
public ResponseEntity<List<ImagePathResponse>> findAllImage() { | ||
return ResponseEntity.ok(imageService | ||
.findAll() | ||
.stream() | ||
.map(ImagePathResponse::of) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
|
||
@PostMapping() | ||
public ResponseEntity<ImagePathResponse> uploadImage(@RequestParam("images") MultipartFile multipartFile) throws IOException { | ||
return ResponseEntity.ok(ImagePathResponse | ||
.of(imageService | ||
.uploadNewImage(multipartFile) | ||
) | ||
); | ||
} | ||
|
||
@GetMapping("/{imageId}") | ||
public ResponseEntity<ImagePathResponse> findImage(@PathVariable Long imageId) { | ||
return ResponseEntity.ok(ImagePathResponse | ||
.of(imageService | ||
.findImageById(imageId) | ||
) | ||
); | ||
} | ||
|
||
@DeleteMapping("/{imageId}") | ||
public ResponseEntity<HttpStatus> deleteImage(@PathVariable Long imageId) { | ||
Image image = imageService.findImageById(imageId); | ||
imageService.removeImage(image); | ||
|
||
return RESPONSE_OK; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...kend/infra/image/domain/entity/Image.java → ...end/domain/image/domain/entity/Image.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ge/domain/repository/ImageRepository.java → ...ge/domain/repository/ImageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/hjjang/backend/domain/image/dto/ImagePathResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.hjjang.backend.domain.image.dto; | ||
|
||
import com.hjjang.backend.domain.image.domain.entity.Image; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class ImagePathResponse { | ||
|
||
private Long id; | ||
private String path; | ||
|
||
public static ImagePathResponse of(Image image) { | ||
return ImagePathResponse.builder() | ||
.id(image.getId()) | ||
.path(image.getPath()) | ||
.build(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...age/exception/ImageNotFoundException.java → ...age/exception/ImageNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/com/hjjang/backend/domain/image/service/ImageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.hjjang.backend.domain.image.service; | ||
|
||
import com.hjjang.backend.domain.image.domain.repository.ImageRepository; | ||
import com.hjjang.backend.domain.image.domain.entity.Image; | ||
import com.hjjang.backend.domain.image.exception.ImageNotFoundException; | ||
import com.hjjang.backend.infra.aws.service.S3ImageUploader; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import javax.transaction.Transactional; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ImageService { | ||
private final ImageRepository imageRepository; | ||
|
||
private final S3ImageUploader imageUploader; | ||
|
||
public List<Image> findAll() { | ||
return imageRepository.findAll(); | ||
} | ||
|
||
public Image findImageById(Long imageId) { | ||
return imageRepository.findById(imageId).orElseThrow(ImageNotFoundException::new); | ||
} | ||
|
||
public Image uploadNewImage(MultipartFile multipartFile) throws IOException { | ||
return imageRepository.save(new Image(imageUploader.upload(multipartFile))); | ||
} | ||
|
||
public void removeImage(Image image) { | ||
image.removeImage(); | ||
imageRepository.save(image); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/com/hjjang/backend/domain/image/service/LocalImageUploader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.hjjang.backend.domain.image.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class LocalImageUploader extends ImageUploader{ | ||
|
||
@Override | ||
public String upload(MultipartFile multipartFile) throws IOException { | ||
File uploadFile = | ||
this.localUpload(multipartFile) // 파일 변환할 수 없으면 에러 | ||
.orElseThrow( | ||
() -> new IllegalArgumentException("error: MultipartFile -> File convert fail")); | ||
return uploadFile.getName(); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/com/hjjang/backend/domain/image/service/Path.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.hjjang.backend.domain.image.service; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum Path { | ||
imageSavePath(System.getProperty("user.dir") + "/backend/src/main/resources/images/"); | ||
|
||
private final String path; | ||
Path(String path) { | ||
this.path = path; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 16 additions & 10 deletions
26
backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.