Skip to content

Commit

Permalink
개발중..
Browse files Browse the repository at this point in the history
  • Loading branch information
DevJunsik committed Sep 19, 2024
1 parent 7c3d178 commit 25ae1e6
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 37 deletions.
50 changes: 49 additions & 1 deletion src/main/java/site/balpyo/auth/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand All @@ -12,6 +12,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import site.balpyo.auth.EmailConfig;
import site.balpyo.auth.dto.request.LoginRequest;
import site.balpyo.auth.dto.request.SignupRequest;
Expand Down Expand Up @@ -156,6 +157,53 @@ public ResponseEntity<CommonResponse> checkUserVerify(@RequestParam("uid") Strin
}
}

@GetMapping("/kakao")
public ResponseEntity<?> kakaoLogin(@RequestParam String accessToken) {
String userInfoUrl = "https://kapi.kakao.com/v2/user/me";

// HTTP 요청을 통해 사용자 정보를 조회
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + accessToken);

HttpEntity<String> entity = new HttpEntity<>(headers);

ResponseEntity<String> response = restTemplate.exchange(userInfoUrl, HttpMethod.GET, entity, String.class);


if (response.getStatusCode() == HttpStatus.OK) {
String userInfo = response.getBody();
return ResponseEntity.ok(userInfo);
} else {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
}

@GetMapping("/google")
public ResponseEntity<?> googleLogin(@RequestParam String accessToken) {
// 구글 사용자 정보 API URL
String userInfoUrl = "https://www.googleapis.com/oauth2/v3/userinfo";

// 액세스 토큰을 헤더에 포함하여 요청
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + accessToken);

HttpEntity<String> entity = new HttpEntity<>(headers);

// 사용자 정보 요청
ResponseEntity<String> response = restTemplate.exchange(userInfoUrl, HttpMethod.GET, entity, String.class);

// 사용자 정보 처리
if (response.getStatusCode() == HttpStatus.OK) {
String userInfo = response.getBody();
// 응답을 처리하거나 사용자를 등록
return ResponseEntity.ok(userInfo); // 사용자 정보를 반환하거나, 응답 처리
} else {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
}




Expand Down
11 changes: 11 additions & 0 deletions src/main/java/site/balpyo/script/dto/ScriptResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package site.balpyo.script.dto;

import jakarta.persistence.Column;
import lombok.*;
import site.balpyo.script.entity.Tag;

Expand All @@ -25,4 +26,14 @@ public class ScriptResponse {
private boolean useAi;
private Set<String> tag;



private String filePath;
private Integer playTime;
private String speechMark;
private String originalScript;//원본대본
private Integer speed;



}
17 changes: 17 additions & 0 deletions src/main/java/site/balpyo/script/entity/ScriptEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,21 @@ public class ScriptEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Column
private String filePath;

@Column
private Integer playTime;

@Column
private String speechMark;

@Column
private String originalScript;//원본대본

@Column
private Integer speed;


}
6 changes: 6 additions & 0 deletions src/main/java/site/balpyo/script/service/ScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public ResponseEntity<CommonResponse> saveEmptyScript(ScriptRequest scriptReques
.tag(insertedScriptEntity.getTags().stream()
.map(tag -> tag.getTag().toString())
.collect(Collectors.toSet()))

.build();

System.out.println(insertedScriptEntity.getTags().toString());
Expand Down Expand Up @@ -116,6 +117,11 @@ public ResponseEntity<CommonResponse> getAllScript(String uid) {
.map(tag -> tag.getTag().toString())
.collect(Collectors.toSet())
)
.originalScript(scriptEntity.getOriginalScript())
.speechMark(scriptEntity.getSpeechMark())
.filePath(scriptEntity.getFilePath())
.speed(scriptEntity.getSpeed())
.playTime(scriptEntity.getPlayTime())
.build();

scriptResponses.add(scriptResponse);
Expand Down
72 changes: 36 additions & 36 deletions src/test/java/site/balpyo/ai/service/AIGenerateServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ public void testJwtExist() {
public void testVerifyCodeExist() {
assertNotNull(userVerifyUid);
}

@Test
@Order(3)
public void testVerify() {

HttpHeaders headers = new HttpHeaders();
HttpEntity<Void> entity = new HttpEntity<>(headers);

ResponseEntity<CommonResponse> response = restTemplate.exchange("/api/auth/verify?uid="+userVerifyUid, HttpMethod.GET, entity, CommonResponse.class);

assertEquals(HttpStatus.OK, response.getStatusCode());

}
//
// @Test
// @Order(3)
// public void testVerify() {
//
// HttpHeaders headers = new HttpHeaders();
// HttpEntity<Void> entity = new HttpEntity<>(headers);
//
// ResponseEntity<CommonResponse> response = restTemplate.exchange("/api/auth/verify?uid="+userVerifyUid, HttpMethod.GET, entity, CommonResponse.class);
//
// assertEquals(HttpStatus.OK, response.getStatusCode());
//
// }

@Test
@Order(4)
Expand Down Expand Up @@ -126,29 +126,29 @@ public void testSaveScript() {
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNotNull(response.getBody());
}
@Test
@Order(5)
public void generateAi() {
AIGenerateRequest request = new AIGenerateRequest();
request.setTopic("발표준비");
request.setTest(true);
request.setKeywords("발표에서 최적화하는 방법");
request.setSecTime(100);
request.setScriptId(scriptId);
request.setBalpyoAPIKey("1234");

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Authorization", "Bearer " + jwtToken);

HttpEntity<AIGenerateRequest> entity = new HttpEntity<>(request, headers);

ResponseEntity<CommonResponse> response = restTemplate.exchange("/user/ai/script", HttpMethod.POST, entity, CommonResponse.class);
System.out.println(response.toString());
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNotNull(response.getBody());

}
// @Test
// @Order(5)
// public void generateAi() {
// AIGenerateRequest request = new AIGenerateRequest();
// request.setTopic("발표준비");
// request.setTest(true);
// request.setKeywords("발표에서 최적화하는 방법");
// request.setSecTime(100);
// request.setScriptId(scriptId);
// request.setBalpyoAPIKey("1234");
//
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.APPLICATION_JSON);
// headers.set("Authorization", "Bearer " + jwtToken);
//
// HttpEntity<AIGenerateRequest> entity = new HttpEntity<>(request, headers);
//
// ResponseEntity<CommonResponse> response = restTemplate.exchange("/user/ai/script", HttpMethod.POST, entity, CommonResponse.class);
// System.out.println(response.toString());
// assertEquals(HttpStatus.OK, response.getStatusCode());
// assertNotNull(response.getBody());
//
// }


@Test
Expand Down

0 comments on commit 25ae1e6

Please sign in to comment.