Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -32,6 +35,7 @@
import org.fontory.fontorybe.font.controller.port.FontService;
import org.fontory.fontorybe.font.domain.Font;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -300,12 +304,13 @@ public ResponseEntity<?> downloadFont(
Long memberId = userPrincipal.getId();
log.info("Request received: Get font download for font ID : {}, requesting memberId : {}", fontId, memberId);

FontResponse res = fontService.fontDownload(memberId, fontId);
Font font = fontService.fontDownload(memberId, fontId);
log.info("Response sent: Font downloaded with ID: {}", fontId);

return ResponseEntity
.status(HttpStatus.OK)
.body(res);
.location(URI.create(font.getTtf()))
.build();
}

@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class FontPageResponse {
private Long downloadCount;
private Long bookmarkCount;
private boolean isBookmarked;
private String woff;

public static FontPageResponse from(Font font, String writerName, boolean isBookmarked) {
return FontPageResponse.builder()
Expand All @@ -24,6 +25,7 @@ public static FontPageResponse from(Font font, String writerName, boolean isBook
.downloadCount(font.getDownloadCount())
.bookmarkCount(font.getBookmarkCount())
.isBookmarked(isBookmarked)
.woff(font.getWoff())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class FontResponse {
private Long bookmarkCount;
private boolean isBookmarked;
private String writerName;
private String woff;

public static FontResponse from(Font font, boolean isBookmarked, String writerName) {
return FontResponse.builder()
Expand All @@ -24,6 +25,7 @@ public static FontResponse from(Font font, boolean isBookmarked, String writerNa
.bookmarkCount(font.getBookmarkCount())
.isBookmarked(isBookmarked)
.writerName(writerName)
.woff(font.getWoff())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class FontUpdateResponse {
private String example;
private Long memberId;
private LocalDateTime createdAt;
private String woff;

public static FontUpdateResponse from(Font font) {
return FontUpdateResponse.builder()
Expand All @@ -24,6 +25,7 @@ public static FontUpdateResponse from(Font font) {
.example(font.getExample())
.memberId(font.getMemberId())
.createdAt(font.getCreatedAt())
.woff(font.getWoff())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public interface FontService {
List<FontResponse> getMyPopularFonts(Long memberId);
List<FontResponse> getPopularFonts(Long memberId);
Font updateProgress(Long fontId, FontProgressUpdateDTO fontProgressUpdateDTO);
FontResponse fontDownload(Long memberId, Long fontId);
Font fontDownload(Long memberId, Long fontId);
Boolean isDuplicateNameExists(Long memberId, String fontName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,16 @@ public Font updateProgress(Long fontId, FontProgressUpdateDTO fontProgressUpdate

@Override
@Transactional
public FontResponse fontDownload(Long memberId, Long fontId) {
public Font fontDownload(Long memberId, Long fontId) {
log.info("Service executing: Download font ID: {}", fontId);
Font targetFont = getOrThrowById(fontId);
targetFont.increaseDownloadCount();

// TODO : 폰트 다운로드

boolean isBookmarked = bookmarkRepository.existsByMemberIdAndFontId(memberId, fontId);

fontRepository.save(targetFont);

Member writer = memberService.getOrThrowById(targetFont.getMemberId());

log.info("Service completed: Font ID: {} download successfully", fontId);

return FontResponse.from(targetFont, isBookmarked, writer.getNickname());
return targetFont;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,7 @@ void updateFontProgressSuccess() throws Exception {
void downloadFontSuccess() throws Exception {
mockMvc.perform(get("/fonts/{fontId}/download", 999L)
.header("Authorization", validAccessToken))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(999)))
.andExpect(jsonPath("$.downloadCount").isNumber());
.andExpect(status().isOk());
}

@Test
Expand Down
Loading