-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
174 additions
and
41 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/main/java/com/hackathon/TimeLapse/apiPayload/exception/ArticleNotFoundException.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,7 @@ | ||
package com.hackathon.TimeLapse.apiPayload.exception; | ||
|
||
public class ArticleNotFoundException extends RuntimeException { | ||
public ArticleNotFoundException(String message){ | ||
super(message); | ||
} | ||
} |
7 changes: 4 additions & 3 deletions
7
...m/hackathon/TimeLapse/domain/Article.java → .../hackathon/TimeLapse/article/Article.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
10 changes: 3 additions & 7 deletions
10
src/main/java/com/hackathon/TimeLapse/article/ArticleController.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 |
---|---|---|
@@ -1,27 +1,23 @@ | ||
package com.hackathon.TimeLapse.article; | ||
|
||
import com.hackathon.TimeLapse.apiPayload.ApiResponse; | ||
import com.hackathon.TimeLapse.domain.Article; | ||
import com.hackathon.TimeLapse.s3.S3Service; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Validated | ||
@RequestMapping("/api") | ||
@RequestMapping("/api/article") | ||
public class ArticleController { | ||
private final ArticleService articleService; | ||
|
||
private final S3Service s3Service; | ||
|
||
@PostMapping("/article") | ||
@PostMapping("/") | ||
public ApiResponse<ArticleResponseDTO.createArticleResultDTO> createArticle(@RequestBody @Valid ArticleRequestDTO.createArticleDTO request, | ||
@RequestParam(name = "memberId") Long memberId) { | ||
Article article = articleService.createArticle(memberId, request); | ||
return ApiResponse.onSuccess(ArticleConverter.toCreateReviewResultDTO(article)); | ||
} | ||
|
||
} |
2 changes: 0 additions & 2 deletions
2
src/main/java/com/hackathon/TimeLapse/article/ArticleConverter.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
1 change: 0 additions & 1 deletion
1
src/main/java/com/hackathon/TimeLapse/article/ArticleRepository.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
5 changes: 0 additions & 5 deletions
5
src/main/java/com/hackathon/TimeLapse/article/ArticleService.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
7 changes: 0 additions & 7 deletions
7
src/main/java/com/hackathon/TimeLapse/article/ImageRepository.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...n/TimeLapse/domain/common/BaseEntity.java → ...ackathon/TimeLapse/common/BaseEntity.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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/hackathon/TimeLapse/image/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,25 @@ | ||
package com.hackathon.TimeLapse.image; | ||
|
||
import com.hackathon.TimeLapse.apiPayload.ApiResponse; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Validated | ||
@RequestMapping("/api/images") | ||
public class ImageController { | ||
private final ImageService imageService; | ||
|
||
@PostMapping("/") | ||
public ApiResponse<ImageResponseDTO.addImageResultDTO> addImages(@RequestBody @Valid ImageRequestDTO.addImagesDTO request, | ||
@RequestHeader("articleId") Long articleId) { | ||
List<Image> images = imageService.addImages(articleId, request); | ||
return ApiResponse.onSuccess(ImageConverter.toAddImageResultDTO(images)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/hackathon/TimeLapse/image/ImageConverter.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,15 @@ | ||
package com.hackathon.TimeLapse.image; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ImageConverter { | ||
|
||
public static ImageResponseDTO.addImageResultDTO toAddImageResultDTO(List<Image> images){ | ||
List<String> imageUrlList = images.stream() | ||
.map(Image::getImage_url) | ||
.collect(Collectors.toList()); | ||
return new ImageResponseDTO.addImageResultDTO(imageUrlList); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/hackathon/TimeLapse/image/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hackathon.TimeLapse.image; | ||
|
||
import com.hackathon.TimeLapse.article.Article; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ImageRepository extends JpaRepository<Image, Long> { | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/hackathon/TimeLapse/image/ImageRequestDTO.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.hackathon.TimeLapse.image; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
public class ImageRequestDTO { | ||
@Getter | ||
public static class addImagesDTO { | ||
|
||
private List<String> imageUrlList; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/hackathon/TimeLapse/image/ImageResponseDTO.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.hackathon.TimeLapse.image; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public class ImageResponseDTO { | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class addImageResultDTO{ | ||
private List<String> imageUrlList; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/hackathon/TimeLapse/image/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,37 @@ | ||
package com.hackathon.TimeLapse.image; | ||
import com.hackathon.TimeLapse.apiPayload.exception.ArticleNotFoundException; | ||
import com.hackathon.TimeLapse.article.Article; | ||
import com.hackathon.TimeLapse.article.ArticleRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
public class ImageService { | ||
private final ImageRepository imageRepository; | ||
private final ArticleRepository articleRepository; | ||
|
||
public ImageService(ImageRepository imageRepository, ArticleRepository articleRepository) { | ||
this.imageRepository = imageRepository; | ||
this.articleRepository = articleRepository; | ||
} | ||
|
||
@Transactional | ||
public List<Image> addImages(Long articleId, ImageRequestDTO.addImagesDTO request) { | ||
Article article = articleRepository.findById(articleId) | ||
.orElseThrow(() -> new ArticleNotFoundException("Article not found with id: " + articleId)); | ||
|
||
List<Image> images = new ArrayList<>(); | ||
for (String imageUrl : request.getImageUrlList()) { | ||
Image image = Image.builder() | ||
.image_url(imageUrl) | ||
.article(article) | ||
.build(); | ||
images.add(image); | ||
} | ||
|
||
return imageRepository.saveAll(images); | ||
} | ||
} |
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
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