diff --git a/be/issue-tracker/src/main/java/com/issuetracker/file/util/CustomMultipartFile.java b/be/issue-tracker/src/main/java/com/issuetracker/file/util/CustomMultipartFile.java index 21c78167c..544088bb2 100644 --- a/be/issue-tracker/src/main/java/com/issuetracker/file/util/CustomMultipartFile.java +++ b/be/issue-tracker/src/main/java/com/issuetracker/file/util/CustomMultipartFile.java @@ -5,12 +5,15 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import org.apache.tika.Tika; import org.springframework.web.multipart.MultipartFile; /** * byte 배열을 MultipartFile 객체로 변환하기 위한 클래스 */ public class CustomMultipartFile implements MultipartFile { + private final Tika tika = new Tika(); + private byte[] input; private String filename; @@ -21,7 +24,7 @@ public CustomMultipartFile(byte[] input, String filename) { @Override public String getName() { - return null; + return filename; } @Override @@ -31,7 +34,11 @@ public String getOriginalFilename() { @Override public String getContentType() { - return null; + try { + return tika.detect(getInputStream()); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override diff --git a/be/issue-tracker/src/main/java/com/issuetracker/member/util/MemberMapper.java b/be/issue-tracker/src/main/java/com/issuetracker/member/util/MemberMapper.java index d082ee382..675f96c6d 100644 --- a/be/issue-tracker/src/main/java/com/issuetracker/member/util/MemberMapper.java +++ b/be/issue-tracker/src/main/java/com/issuetracker/member/util/MemberMapper.java @@ -13,9 +13,9 @@ public static Member toMember(MemberCreateDto memberCreateDto) { memberCreateDto.getNickname(), memberCreateDto.getEmail(), null); } - public static MemberCreateDto toMemberCreateDto(GithubProfile profile) { + public static Member toMember(GithubProfile profile, Long fileId) { String uuidPw = UUID.randomUUID().toString().substring(0, 12); // 깃허브로 가입한 사용자는 비밀번호를 UUID로 설정 - return new MemberCreateDto(profile.getId(), uuidPw, profile.getNickname(), profile.getEmail()); + return new Member(profile.getId(), uuidPw, profile.getNickname(), profile.getEmail(), fileId); } public static SimpleMemberDto toSimpleMemberDto(Member member, String imgUrl) { diff --git a/be/issue-tracker/src/main/java/com/issuetracker/oauth/controller/GithubLoginController.java b/be/issue-tracker/src/main/java/com/issuetracker/oauth/controller/GithubLoginController.java index 005e75bfc..92bb4f228 100644 --- a/be/issue-tracker/src/main/java/com/issuetracker/oauth/controller/GithubLoginController.java +++ b/be/issue-tracker/src/main/java/com/issuetracker/oauth/controller/GithubLoginController.java @@ -1,5 +1,6 @@ package com.issuetracker.oauth.controller; +import com.issuetracker.file.dto.UploadedFileDto; import com.issuetracker.file.service.FileService; import com.issuetracker.file.util.ImgUrlConverter; import com.issuetracker.member.dto.LoginResponse; @@ -32,8 +33,8 @@ public ResponseEntity login(@RequestParam String code) throws IOE // 처음 사용자가 깃허브 로그인을 하는 것이라면 회원가입 로직을 수행한다. if (memberService.isNewUser(profile.getId())) { - memberService.create(MemberMapper.toMemberCreateDto(profile)); - fileService.uploadFile(ImgUrlConverter.toMultipartFile(profile.getImgUrl())); + UploadedFileDto file = fileService.uploadFile(ImgUrlConverter.toMultipartFile(profile.getImgUrl())); + memberService.create(MemberMapper.toMember(profile, file.getId())); } LoginResponse loginResponse = loginService.githubLogin(profile); return ResponseEntity.ok().body(loginResponse);