Skip to content

Commit

Permalink
♻️ Feature/117 recipe 관련 api에 timeconverter 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanvp committed Sep 11, 2023
1 parent 70782ea commit 62ed48d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import zipdabang.server.repository.UuidRepository;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

@Slf4j
Expand Down Expand Up @@ -39,6 +40,13 @@ public String getPattern(){
public void deleteFile(String keyname) {
log.info("KEY NAME : " + keyname);
amazonS3.deleteObject(amazonConfig.getBucket(),keyname);

String[] keynameSplit = keyname.split("/");
String getUuid = keynameSplit[keynameSplit.length-1];
log.info(getUuid);

uuidRepository.deleteByUuid(getUuid);
log.info("해당 uuid 삭제: "+ !uuidRepository.existsByUuid(getUuid));
}

public String generateMemberKeyName(Uuid uuid, String originalFilename) {
Expand All @@ -61,6 +69,7 @@ public Uuid createUUID() {
savedUuid = createUUID();
}
savedUuid = uuidRepository.save(Uuid.builder().uuid(candidate).build());

return savedUuid;
}
}
16 changes: 12 additions & 4 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import zipdabang.server.domain.member.Member;
import zipdabang.server.domain.recipe.*;
import zipdabang.server.repository.recipeRepositories.*;
import zipdabang.server.utils.converter.TimeConverter;
import zipdabang.server.web.dto.requestDto.RecipeRequestDto;
import zipdabang.server.web.dto.responseDto.RecipeResponseDto;

Expand All @@ -37,10 +38,12 @@ public class RecipeConverter {
private final RecipeBannerRepository recipeBannerRepository;
private final CommentRepository commentRepository;
private final AmazonS3Manager amazonS3Manager;
private final TimeConverter timeConverter;

private static RecipeRepository staticRecipeRepository;
private static RecipeCategoryMappingRepository staticRecipeCategoryMappingRepository;


private static LikesRepository staticLikesRepository;
private static ScrapRepository staticScrapRepository;

Expand All @@ -49,6 +52,7 @@ public class RecipeConverter {
private static RecipeBannerRepository staticRecipeBannerRepository;
private static CommentRepository staticCommentRepository;
private static AmazonS3Manager staticAmazonS3Manager;
private static TimeConverter staticTimeConverter;


@PostConstruct
Expand All @@ -61,6 +65,7 @@ public void init() {
this.staticAmazonS3Manager = this.amazonS3Manager;
this.staticLikesRepository = this.likesRepository;
this.staticScrapRepository = this.scrapRepository;
this.staticTimeConverter = this.timeConverter;
}

public static RecipeResponseDto.RecipePageListDto toPagingRecipeDtoList(Page<Recipe> recipes, Member member) {
Expand Down Expand Up @@ -113,7 +118,8 @@ private static RecipeResponseDto.RecipeSimpleDto toResponseRecipeSimpleDto(Recip
.recipeName(recipe.getName())
.nickname(recipe.getMember().getNickname())
.thumbnailUrl(recipe.getThumbnailUrl())
.createdAt(recipe.getCreatedAt().toLocalDate())
.createdAt(staticTimeConverter.ConvertTime(recipe.getCreatedAt()))
.updatedAt(staticTimeConverter.ConvertTime(recipe.getUpdatedAt()))
.likes(recipe.getTotalLike())
.scraps(recipe.getTotalScrap())
.isLiked(staticLikesRepository.findByRecipeAndMember(recipe, member).isPresent())
Expand Down Expand Up @@ -148,7 +154,7 @@ public static List<Ingredient> toIngredient(RecipeRequestDto.CreateRecipeDto req
public static RecipeResponseDto.RecipeStatusDto toRecipeStatusDto(Recipe recipe) {
return RecipeResponseDto.RecipeStatusDto.builder()
.recipeId(recipe.getId())
.calledAt(recipe.getCreatedAt())
.calledAt(staticTimeConverter.ConvertTime(recipe.getCreatedAt()))
.build();
}

Expand Down Expand Up @@ -200,7 +206,8 @@ public static RecipeResponseDto.RecipeDto toResponseRecipeDto(Recipe recipe, Boo
.time(recipe.getTime())
.intro(recipe.getIntro())
.recipeTip(recipe.getRecipeTip())
.createdAt(recipe.getCreatedAt().toLocalDate())
.createdAt(staticTimeConverter.ConvertTime(recipe.getCreatedAt()))
.updatedAt(staticTimeConverter.ConvertTime(recipe.getUpdatedAt()))
.likes(recipe.getTotalLike())
.comments(Long.valueOf(recipe.getCommentList().size()))
.scraps(recipe.getTotalScrap())
Expand Down Expand Up @@ -360,7 +367,8 @@ public static RecipeResponseDto.CommentDto toCommentDto(Comment createdComment,
.ownerNickname(createdComment.getMember().getNickname())
.ownerImage(createdComment.getMember().getProfileUrl())
.isOwner(createdComment.getMember() == member)
.createdAt(createdComment.getCreatedAt().toLocalDate())
.createdAt(staticTimeConverter.ConvertTime(createdComment.getCreatedAt()))
.updatedAt(staticTimeConverter.ConvertTime(createdComment.getUpdatedAt()))
.ownerId(createdComment.getMember().getMemberId())
.commentId(createdComment.getId())
.build();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/zipdabang/server/repository/UuidRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

public interface UuidRepository extends JpaRepository<Uuid, Long> {
boolean existsByUuid(String uuid);

void deleteByUuid(String uuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public ResponseDto<RecipeResponseDto.RecipeInfoDto> recipeDetail(@PathVariable(n
})
@DeleteMapping("/members/recipes/{recipeId}")
public ResponseDto<String> deleteRecipe(@PathVariable(name = "recipeId") Long recipeId, @CheckTempMember @AuthMember Member member) {
Boolean reicpeDeleteBoolean = recipeService.deleteRecipe(recipeId, member);
Boolean recipeDeleteBoolean = recipeService.deleteRecipe(recipeId, member);

if (reicpeDeleteBoolean)
if (recipeDeleteBoolean)
return ResponseDto.of(recipeId + " 레시피 삭제 완료");
else
throw new RecipeException(Code.INTERNAL_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RecipeResponseDto {
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class RecipeStatusDto{
private Long recipeId;
private LocalDateTime calledAt;
private String calledAt;
}

@Builder
Expand All @@ -30,7 +30,8 @@ public static class RecipeSimpleDto {
private String recipeName;
private String nickname;
private String thumbnailUrl;
private LocalDate createdAt;
private String createdAt;
private String updatedAt;
private Long likes;
private Long comments;
private Long scraps;
Expand All @@ -52,7 +53,8 @@ public static class RecipeDto {
private String time;
private String intro;
private String recipeTip;
private LocalDate createdAt;
private String createdAt;
private String updatedAt;
private Long likes;
private Long comments;
private Long scraps;
Expand Down Expand Up @@ -139,7 +141,8 @@ public static class CommentDto{
private String ownerImage;
private Boolean isOwner;
private String content;
private LocalDate createdAt;
private String createdAt;
private String updatedAt;
private Long ownerId;
private Long commentId;
}
Expand Down

0 comments on commit 62ed48d

Please sign in to comment.