-
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.
[REFACTOR] 전반적 코드 정리
- Loading branch information
Showing
58 changed files
with
272 additions
and
387 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
30 changes: 30 additions & 0 deletions
30
dateroad-api/src/main/java/org/dateroad/advertisement/api/AdvertisementController.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 org.dateroad.advertisement.api; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.dateroad.advertisement.dto.response.AdvGetAllRes; | ||
import org.dateroad.advertisement.dto.response.AdvGetDetailRes; | ||
import org.dateroad.advertisement.service.AdvertisementService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/advertisements") | ||
public class AdvertisementController { | ||
private final AdvertisementService advertisementService; | ||
|
||
@GetMapping | ||
public ResponseEntity<AdvGetAllRes> getAllAdvertisements(){ | ||
return ResponseEntity.ok(advertisementService.getAllAdvertisements()); | ||
} | ||
|
||
@GetMapping("{advId}") | ||
public ResponseEntity<AdvGetDetailRes> getAllAdvertisements( | ||
final @PathVariable Long advId | ||
){ | ||
return ResponseEntity.ok(advertisementService.getAdvertisementsDetail(advId)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
dateroad-api/src/main/java/org/dateroad/advertisement/dto/response/AdvGetAllRes.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,35 @@ | ||
package org.dateroad.advertisement.dto.response; | ||
|
||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import org.dateroad.advertisement.domain.AdTagType; | ||
import org.dateroad.advertisement.domain.Advertisement; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record AdvGetAllRes( | ||
List<AdvertisementDtoRes> advertisementDtoResList | ||
) { | ||
public static AdvGetAllRes of(List<AdvertisementDtoRes> advertisementDtoResList) { | ||
return AdvGetAllRes.builder() | ||
.advertisementDtoResList(advertisementDtoResList) | ||
.build(); | ||
} | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record AdvertisementDtoRes( | ||
Long advertisementId, | ||
String thumbnail, | ||
String title, | ||
AdTagType tag | ||
) { | ||
public static AdvertisementDtoRes of(Advertisement advertisement) { | ||
return AdvertisementDtoRes.builder() | ||
.advertisementId(advertisement.getId()) | ||
.thumbnail(advertisement.getThumbnail()) | ||
.title(advertisement.getTitle()) | ||
.tag(advertisement.getTag()) | ||
.build(); | ||
} | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
...tisment/dto/response/AdvGetDetailRes.java → ...isement/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
55 changes: 55 additions & 0 deletions
55
dateroad-api/src/main/java/org/dateroad/advertisement/service/AdvertisementService.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,55 @@ | ||
package org.dateroad.advertisement.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.dateroad.adImage.domain.AdImage; | ||
import org.dateroad.adImage.repository.AdImageRepository; | ||
import org.dateroad.advertisement.domain.Advertisement; | ||
import org.dateroad.advertisement.dto.response.AdvGetAllRes; | ||
import org.dateroad.advertisement.repository.AdvertisementRepository; | ||
import org.dateroad.advertisement.dto.response.AdvGetAllRes.AdvertisementDtoRes; | ||
import org.dateroad.advertisement.dto.response.AdvGetDetailRes; | ||
import org.dateroad.advertisement.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 AdvertisementService { | ||
private final AdvertisementRepository advertisementRepository; | ||
private final AdImageRepository adImageRepository; | ||
|
||
public AdvGetAllRes getAllAdvertisements() { | ||
Pageable topFive = PageRequest.of(0, 5); | ||
List<Advertisement> advertisements = advertisementRepository.findTop5ByOrderByCreatedDateDesc(topFive); | ||
List<AdvertisementDtoRes> advertisementDtoResList = advertisements.stream() | ||
.map(AdvertisementDtoRes::of).toList(); | ||
return AdvGetAllRes.of(advertisementDtoResList); | ||
} | ||
|
||
public AdvGetDetailRes getAdvertisementsDetail(final Long advId) { | ||
Advertisement advertisement = getAdvertisement(advId); | ||
List<AdImage> adImages = adImageRepository.findAllById(advId); | ||
return AdvGetDetailRes.of( | ||
getImages(adImages), advertisement.getTitle(), advertisement.getCreatedAt().toLocalDate(), | ||
advertisement.getTitle() | ||
); | ||
} | ||
|
||
private Advertisement getAdvertisement(final Long advId) { | ||
return advertisementRepository.findById(advId).orElseThrow( | ||
() -> new EntityNotFoundException(FailureCode.ADVERTISEMENT_NOT_FOUND) | ||
); | ||
} | ||
|
||
private List<AdvImagesRes> getImages(final List<AdImage> adImages) { | ||
return adImages.stream().map( | ||
adImage -> AdvImagesRes.of(adImage.getImageUrl(), adImage.getSequence()) | ||
).toList(); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
dateroad-api/src/main/java/org/dateroad/advertisment/api/AdvertismentController.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
dateroad-api/src/main/java/org/dateroad/advertisment/dto/response/AdvGetAllRes.java
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
dateroad-api/src/main/java/org/dateroad/advertisment/service/AdvertismentService.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
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: 0 additions & 4 deletions
4
dateroad-api/src/main/java/org/dateroad/auth/jwt/refreshtoken/RefreshTokenGenerator.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
3 changes: 0 additions & 3 deletions
3
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
Oops, something went wrong.