-
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.
Browse files
Browse the repository at this point in the history
Feature/#5
- Loading branch information
Showing
25 changed files
with
268 additions
and
80 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
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
60 changes: 47 additions & 13 deletions
60
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,61 @@ | ||
package com.hackathon.TimeLapse.article; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.http.MediaType; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.hackathon.TimeLapse.apiPayload.ApiResponse; | ||
import com.hackathon.TimeLapse.domain.Article; | ||
import com.hackathon.TimeLapse.image.Image; | ||
import com.hackathon.TimeLapse.image.ImageRequestDTO; | ||
import com.hackathon.TimeLapse.image.ImageService; | ||
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.*; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Validated | ||
@RequestMapping("/api") | ||
@Slf4j | ||
@RequestMapping("/api/article") | ||
public class ArticleController { | ||
private final ArticleService articleService; | ||
|
||
private final S3Service s3Service; | ||
private final ArticleService articleService; | ||
private final S3Service s3Service; | ||
private final ImageService imageService; | ||
|
||
@PostMapping(value = "", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) | ||
public ApiResponse<ArticleResponseDTO.createArticleResultDTO> createArticle( | ||
@RequestPart @Valid ArticleRequestDTO.createArticleDTO request, | ||
@RequestPart List<MultipartFile> files | ||
) throws IOException { | ||
long memberId = Long.parseLong(SecurityContextHolder.getContext().getAuthentication().getName()); | ||
log.info("[*] memberId: " + memberId); | ||
System.out.println(files.get(0)); | ||
List<String> uploadedFilesLinks = s3Service.uploadMultipleFiles(files); | ||
Article article = articleService.createArticle(memberId, request, uploadedFilesLinks); | ||
|
||
List<Image> images = new ArrayList<>(); | ||
for (String url : uploadedFilesLinks) { | ||
Image image = Image.builder() | ||
.image_url(url) | ||
.article(article) | ||
.build(); | ||
images.add(image); | ||
} | ||
imageService.addImages(article.getId(), new ImageRequestDTO.addImagesDTO(uploadedFilesLinks)); | ||
|
||
return ApiResponse.onSuccess(ArticleConverter.toCreateReviewResultDTO(article)); | ||
} | ||
|
||
@PostMapping("/article") | ||
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
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.
30 changes: 30 additions & 0 deletions
30
src/main/java/com/hackathon/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.hackathon.TimeLapse.common; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
|
||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseEntity { | ||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
@LastModifiedDate | ||
private LocalDateTime updatedAt; | ||
|
||
public BaseEntity() { | ||
} | ||
|
||
public LocalDateTime getCreatedAt() { | ||
return this.createdAt; | ||
} | ||
|
||
public LocalDateTime getUpdatedAt() { | ||
return this.updatedAt; | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
src/main/java/com/hackathon/TimeLapse/domain/common/BaseEntity.java
This file was deleted.
Oops, something went wrong.
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> { | ||
} |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
package com.hackathon.TimeLapse.image; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
public class ImageRequestDTO { | ||
@Getter | ||
@AllArgsConstructor | ||
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; | ||
} | ||
|
||
} |
Oops, something went wrong.