-
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.
Browse files
Browse the repository at this point in the history
Feature/#4 face
- Loading branch information
Showing
19 changed files
with
498 additions
and
27 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
6 changes: 6 additions & 0 deletions
6
src/main/java/fairytale/tbd/domain/faceSwap/converter/FaceDetectConverter.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,6 @@ | ||
package fairytale.tbd.domain.faceSwap.converter; | ||
|
||
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectRequestDto; | ||
|
||
public class FaceDetectConverter { | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/fairytale/tbd/domain/faceSwap/entity/CustomCharacter.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,40 @@ | ||
package fairytale.tbd.domain.faceSwap.entity; | ||
|
||
import fairytale.tbd.domain.fairytale.entity.Fairytale; | ||
import fairytale.tbd.domain.user.entity.User; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CustomCharacter { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long customId; | ||
|
||
private String customURL; | ||
|
||
@OneToOne | ||
@JoinColumn(name = "userId") | ||
private User userId; | ||
|
||
|
||
@ManyToOne | ||
@JoinColumn(name = "fairytale_id") | ||
private Fairytale fairytaleId; | ||
|
||
public void setUserId(User userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public void setFairytaleId(Fairytale fairytaleId) { | ||
this.fairytaleId = fairytaleId; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/fairytale/tbd/domain/faceSwap/entity/OriginalCharacter.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,40 @@ | ||
package fairytale.tbd.domain.faceSwap.entity; | ||
|
||
import fairytale.tbd.domain.fairytale.entity.Fairytale; | ||
import fairytale.tbd.domain.user.entity.User; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class OriginalCharacter { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long originId; | ||
|
||
private String originalURL; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "fairytale_id") | ||
private Fairytale fairytaleId; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "userId") | ||
private User user; | ||
|
||
public void setUser(User user){ | ||
this.user = user; | ||
} | ||
|
||
public void setFairytaleId(Fairytale fairytaleId) { | ||
this.fairytaleId = fairytaleId; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/fairytale/tbd/domain/faceSwap/entity/Uuid.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,18 @@ | ||
package fairytale.tbd.domain.faceSwap.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
|
||
public class Uuid { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long uuidId; | ||
|
||
@Column(unique = true) | ||
private String uuid; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/fairytale/tbd/domain/faceSwap/repository/CustomCharacterRepository.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,7 @@ | ||
package fairytale.tbd.domain.faceSwap.repository; | ||
|
||
import fairytale.tbd.domain.faceSwap.entity.CustomCharacter; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CustomCharacterRepository extends JpaRepository<CustomCharacter, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/fairytale/tbd/domain/faceSwap/repository/OriginalCharacterRepository.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,7 @@ | ||
package fairytale.tbd.domain.faceSwap.repository; | ||
|
||
import fairytale.tbd.domain.faceSwap.entity.OriginalCharacter; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface OriginalCharacterRepository extends JpaRepository<OriginalCharacter, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/fairytale/tbd/domain/faceSwap/repository/UuidRepository.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,7 @@ | ||
package fairytale.tbd.domain.faceSwap.repository; | ||
|
||
import fairytale.tbd.domain.faceSwap.entity.Uuid; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UuidRepository extends JpaRepository<Uuid, Long> { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/fairytale/tbd/domain/faceSwap/service/FaceDetectApiService.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,10 @@ | ||
package fairytale.tbd.domain.faceSwap.service; | ||
|
||
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectRequestDto; | ||
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectResponseDto; | ||
|
||
import java.io.IOException; | ||
|
||
public interface FaceDetectApiService { | ||
FaceDetectResponseDto getOptFromFaceDetectApi(FaceDetectRequestDto faceDetectRequestDto) throws IOException; | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/fairytale/tbd/domain/faceSwap/service/FaceDetectApiServiceImpl.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,85 @@ | ||
package fairytale.tbd.domain.faceSwap.service; | ||
|
||
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectRequestDto; | ||
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectResponseDto; | ||
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapRequestDto; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import okhttp3.*; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.LogManager; | ||
import java.util.logging.Logger; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class FaceDetectApiServiceImpl implements FaceDetectApiService{ | ||
|
||
@Value("${face.akool.apikey}") | ||
private static String apiKey; | ||
|
||
|
||
@Override | ||
public FaceDetectResponseDto getOptFromFaceDetectApi(FaceDetectRequestDto faceDetectRequestDto) throws IOException { | ||
|
||
|
||
String landmarkStr = ""; | ||
|
||
OkHttpClient client = new OkHttpClient(); | ||
|
||
MediaType mediaType = MediaType.parse("application/json"); | ||
|
||
String requestBodyJson = "{\n" + | ||
" \"single_face\": true, \n" + | ||
" \"image_url\": \"" + faceDetectRequestDto.getImgURL() + "\"\n" + | ||
"}"; | ||
|
||
RequestBody body = RequestBody.create(mediaType, requestBodyJson); | ||
|
||
Request request = new Request.Builder() | ||
.url("https://sg3.akool.com/detect") | ||
.method("POST", body) | ||
.addHeader("Authorization", "Bearer " + apiKey) | ||
.addHeader("Content-Type", "application/json") | ||
.build(); | ||
|
||
try (Response response = client.newCall(request).execute()){ | ||
|
||
if(!response.isSuccessful()){ | ||
throw new IOException("Unexpected code " + response); | ||
} | ||
|
||
String responseData = response.body().string(); | ||
|
||
JSONObject jsonObject = new JSONObject(responseData); | ||
|
||
int errCode = jsonObject.getInt("error_code"); | ||
String errorMsg = jsonObject.getString("error_msg"); | ||
|
||
if(errCode!=0 || !errorMsg.equals("SUCCESS")){ | ||
throw new IOException("Error! \n" + | ||
"error code : " + | ||
errCode + "\n" + | ||
"error massage : " + | ||
errorMsg + "\n"); | ||
} | ||
|
||
landmarkStr = jsonObject.getString("landmarks_str"); | ||
} catch (IOException e) { | ||
|
||
e.printStackTrace(); | ||
|
||
} | ||
|
||
return FaceDetectResponseDto.builder() | ||
.photoUrl(faceDetectRequestDto.getImgURL()) | ||
.opt(landmarkStr) | ||
.build(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/fairytale/tbd/domain/faceSwap/service/FaceSwapApiService.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,8 @@ | ||
package fairytale.tbd.domain.faceSwap.service; | ||
|
||
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectResponseDto; | ||
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapResponseDto; | ||
|
||
public interface FaceSwapApiService { | ||
/*FaceSwapResponseDto*/void getFaceSwapImg(FaceDetectResponseDto faceDetectResponseDto); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/fairytale/tbd/domain/faceSwap/service/FaceSwapApiServiceImpl.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,24 @@ | ||
package fairytale.tbd.domain.faceSwap.service; | ||
|
||
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectResponseDto; | ||
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapRequestDto; | ||
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class FaceSwapApiServiceImpl implements FaceSwapApiService{ | ||
|
||
// 여기에서 originalCharacter, customCharacter 둘 다에 사용할 수 있게끔 한다. | ||
@Override | ||
@Transactional | ||
public void getFaceSwapImg(FaceDetectResponseDto faceDetectResponseDto){ | ||
FaceSwapRequestDto.FaceSwapRequest faceSwapRequest = new FaceSwapRequestDto.FaceSwapRequest(); | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/fairytale/tbd/domain/faceSwap/service/PhotoUploadService.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,11 @@ | ||
package fairytale.tbd.domain.faceSwap.service; | ||
|
||
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectRequestDto; | ||
import fairytale.tbd.domain.user.entity.User; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
|
||
public interface PhotoUploadService { | ||
FaceDetectRequestDto savePhotos(User userId, MultipartFile photoUploadRequestDto) throws IOException; | ||
} |
Oops, something went wrong.