-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # dateroad-api/src/main/java/org/dateroad/user/api/UserController.java # dateroad-api/src/main/java/org/dateroad/user/service/UserService.java # dateroad-domain/src/main/java/org/dateroad/tag/repository/UserTagRepository.java
- Loading branch information
Showing
64 changed files
with
1,559 additions
and
157 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
54 changes: 54 additions & 0 deletions
54
dateroad-api/src/main/java/org/dateroad/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,54 @@ | ||
package org.dateroad.Image.service; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import lombok.RequiredArgsConstructor; | ||
import org.dateroad.code.FailureCode; | ||
import org.dateroad.date.domain.Course; | ||
import org.dateroad.exception.DateRoadException; | ||
import org.dateroad.image.domain.Image; | ||
import org.dateroad.image.repository.ImageRepository; | ||
import org.dateroad.s3.S3Service; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ImageService { | ||
private final ImageRepository imageRepository; | ||
private final S3Service s3Service; | ||
@Value("${aws-property.s3-bucket-name}") | ||
private String path; | ||
@Value("${cloudfront.domain}") | ||
private String cachePath; | ||
|
||
public List<Image> saveImages(final List<MultipartFile> images, final Course course) { | ||
AtomicInteger sequence = new AtomicInteger(); | ||
List<Image> courseimages = images.stream() | ||
.map(img -> { | ||
try { | ||
return Image.create( | ||
course, | ||
cachePath + s3Service.uploadImage(path, img).get(), | ||
sequence.getAndIncrement() | ||
); | ||
} catch (IOException | ExecutionException | InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}) | ||
.toList(); | ||
return imageRepository.saveAll(courseimages); | ||
} | ||
|
||
public Image findFirstByCourseOrderBySequenceAsc(Course course) { | ||
return imageRepository.findFirstByCourseOrderBySequenceAsc(course) | ||
.orElseThrow( | ||
() -> new DateRoadException(FailureCode.COURSE_THUMBNAIL_NOT_FOUND) | ||
); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
dateroad-api/src/main/java/org/dateroad/advertisment/dto/response/AdvGetDetailRes.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,39 @@ | ||
package org.dateroad.advertisment.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
|
||
@Builder(access = AccessLevel.PROTECTED) | ||
public record AdvGetDetailRes( | ||
List<AdvImagesRes> images, | ||
String title, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd", timezone = "Asia/Seoul") | ||
LocalDate createAt, | ||
String description | ||
) { | ||
public static AdvGetDetailRes of(List<AdvImagesRes> images, String title, LocalDate createAt, String description) { | ||
return AdvGetDetailRes.builder() | ||
.images(images) | ||
.title(title) | ||
.createAt(createAt) | ||
.description(description) | ||
.build(); | ||
} | ||
|
||
@Builder(access = AccessLevel.PROTECTED) | ||
public record AdvImagesRes( | ||
String imagesUrl, | ||
int sequence | ||
) { | ||
public static AdvImagesRes of(String imagesUrl, int sequence) { | ||
return AdvImagesRes.builder() | ||
.imagesUrl(imagesUrl) | ||
.sequence(sequence) | ||
.build(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
dateroad-api/src/main/java/org/dateroad/advertisment/service/AdvertismentService.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,23 +1,57 @@ | ||
package org.dateroad.advertisment.service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.dateroad.adImage.domain.AdImage; | ||
import org.dateroad.adImage.repository.AdImageRepository; | ||
import org.dateroad.advertisement.domain.Advertisment; | ||
import org.dateroad.advertisement.repository.AdvertismentRepository; | ||
import org.dateroad.advertisment.dto.response.AdvGetAllRes; | ||
import org.dateroad.advertisment.dto.response.AdvGetAllRes.AdvertismentDtoRes; | ||
import org.dateroad.advertisment.dto.response.AdvGetDetailRes; | ||
import org.dateroad.advertisment.dto.response.AdvGetDetailRes.AdvImagesRes; | ||
import org.dateroad.code.FailureCode; | ||
import org.dateroad.exception.EntityNotFoundException; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AdvertismentService { | ||
private final AdvertismentRepository advertismentRepository; | ||
private final AdImageRepository adImageRepository; | ||
|
||
private static List<AdvImagesRes> getImages(final List<AdImage> adImages) { | ||
return adImages.stream().map( | ||
adImage -> AdvImagesRes.of(adImage.getImageUrl(), adImage.getSequence()) | ||
).toList(); | ||
} | ||
|
||
public AdvGetAllRes getAllAdvertisments() { | ||
Pageable topFive = PageRequest.of(0, 5); | ||
return AdvGetAllRes.of(advertismentRepository.findTop5ByOrderByCreatedDateDesc(topFive). | ||
stream() | ||
.map(AdvertismentDtoRes::of) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
public AdvGetDetailRes getAdvertismentsDetail(final Long advId) { | ||
Advertisment advertisment = getAdvertisment(advId); | ||
List<AdImage> adImages = adImageRepository.findAllById(advId); | ||
return AdvGetDetailRes.of( | ||
getImages(adImages), advertisment.getTitle(), advertisment.getCreatedAt().toLocalDate(), | ||
advertisment.getTitle() | ||
); | ||
} | ||
|
||
private Advertisment getAdvertisment(final Long advId) { | ||
return advertismentRepository.findById(advId).orElseThrow( | ||
() -> new EntityNotFoundException(FailureCode.ADVERTISMENT_NOT_FOUND) | ||
); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
dateroad-api/src/main/java/org/dateroad/config/AsyncConfig.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,12 @@ | ||
package org.dateroad.config; | ||
|
||
import java.util.concurrent.Executor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
@Configuration | ||
@EnableAsync | ||
public class AsyncConfig { | ||
} |
Oops, something went wrong.