Skip to content

Commit 74ef447

Browse files
author
Choibho
committed
충돌 해결 및 로컬레포지토리 업데이트
2 parents e9c7594 + 9dc8f20 commit 74ef447

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4386
-1146
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ out/
3535

3636
### VS Code ###
3737
.vscode/
38+
39+
.DS_store

Diff for: build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ dependencies {
2525
implementation 'org.springframework.boot:spring-boot-starter-security'
2626
testImplementation 'org.springframework.boot:spring-boot-starter-test'
2727
implementation 'org.springframework.boot:spring-boot-starter-mail'
28+
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
2829

2930
}
3031

3132
tasks.named('test') {
3233
useJUnitPlatform()
3334
}
35+
tasks.withType(JavaCompile) {
36+
options.compilerArgs << "-Xlint:unchecked"
37+
}

Diff for: src/main/java/com/example/networker_test/NetworkerTestApplication.java

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ public static void main(String[] args) {
1111
SpringApplication.run(NetworkerTestApplication.class, args);
1212
}
1313

14+
1415
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.example.networker_test.controller.comment;
2+
3+
import com.example.networker_test.domain.post.PostLaw;
4+
import com.example.networker_test.service.comment.CommentLawService;
5+
import com.example.networker_test.service.comment.CommentService;
6+
import com.example.networker_test.service.post.PostLawService;
7+
import org.springframework.stereotype.Controller;
8+
import org.springframework.ui.Model;
9+
import org.springframework.web.bind.annotation.PathVariable;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RequestParam;
13+
14+
import com.example.networker_test.domain.post.Post;
15+
import com.example.networker_test.service.post.PostService;
16+
17+
import lombok.RequiredArgsConstructor;
18+
19+
@Controller
20+
@RequestMapping("/commentlaw")
21+
@RequiredArgsConstructor
22+
public class CommentLawController {
23+
24+
private final PostLawService postLawService;//의존성 주입
25+
private final CommentLawService commentLawService;//의존성 주입
26+
27+
@PostMapping("/create/{id}")//댓글 등록 처리
28+
public String createComment(Model model, @PathVariable("id") Integer id, @RequestParam(value="content")String content) {
29+
PostLaw postLaw = this.postLawService.getPost(id);
30+
this.commentLawService.create(postLaw,content);
31+
return String.format("redirect:/lawsupport/detail/%s", id);//댓글 등록 후 등록 확인을 위한 reload
32+
}
33+
34+
35+
}

Diff for: src/main/java/com/example/networker_test/controller/lawsupport/LawSupportController.java

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.example.networker_test.controller.order;
2+
3+
import org.json.simple.JSONObject;
4+
import org.json.simple.parser.JSONParser;
5+
import org.json.simple.parser.ParseException;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
import org.springframework.stereotype.Controller;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.RequestBody;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
13+
import java.io.*;
14+
import java.net.HttpURLConnection;
15+
import java.net.URL;
16+
import java.nio.charset.StandardCharsets;
17+
import java.util.Base64;
18+
19+
@Controller
20+
public class OrderController {
21+
22+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
23+
24+
@RequestMapping(value = "/confirm")
25+
public ResponseEntity<JSONObject> confirmPayment(@RequestBody String jsonBody) throws Exception {
26+
27+
JSONParser parser = new JSONParser();
28+
String orderId;
29+
String amount;
30+
String paymentKey;
31+
try {
32+
// 클라이언트에서 받은 JSON 요청 바디입니다.
33+
JSONObject requestData = (JSONObject) parser.parse(jsonBody);
34+
paymentKey = (String) requestData.get("paymentKey");
35+
orderId = (String) requestData.get("orderId");
36+
amount = (String) requestData.get("amount");
37+
} catch (ParseException e) {
38+
throw new RuntimeException(e);
39+
}
40+
;
41+
JSONObject obj = new JSONObject();
42+
obj.put("orderId", orderId);
43+
obj.put("amount", amount);
44+
obj.put("paymentKey", paymentKey);
45+
46+
// 토스페이먼츠 API는 시크릿 키를 사용자 ID로 사용하고, 비밀번호는 사용하지 않습니다.
47+
// 비밀번호가 없다는 것을 알리기 위해 시크릿 키 뒤에 콜론을 추가합니다.
48+
String widgetSecretKey = "test_gsk_docs_OaPz8L5KdmQXkzRz3y47BMw6";
49+
Base64.Encoder encoder = Base64.getEncoder();
50+
byte[] encodedBytes = encoder.encode((widgetSecretKey + ":").getBytes(StandardCharsets.UTF_8));
51+
String authorizations = "Basic " + new String(encodedBytes);
52+
53+
// 결제를 승인하면 결제수단에서 금액이 차감돼요.
54+
URL url = new URL("https://api.tosspayments.com/v1/payments/confirm");
55+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
56+
connection.setRequestProperty("Authorization", authorizations);
57+
connection.setRequestProperty("Content-Type", "application/json");
58+
connection.setRequestMethod("POST");
59+
connection.setDoOutput(true);
60+
61+
OutputStream outputStream = connection.getOutputStream();
62+
outputStream.write(obj.toString().getBytes("UTF-8"));
63+
64+
int code = connection.getResponseCode();
65+
boolean isSuccess = code == 200;
66+
67+
InputStream responseStream = isSuccess ? connection.getInputStream() : connection.getErrorStream();
68+
69+
// 결제 성공 및 실패 비즈니스 로직을 구현하세요.
70+
Reader reader = new InputStreamReader(responseStream, StandardCharsets.UTF_8);
71+
JSONObject jsonObject = (JSONObject) parser.parse(reader);
72+
responseStream.close();
73+
74+
return ResponseEntity.status(code).body(jsonObject);
75+
}
76+
}

Diff for: src/main/java/com/example/networker_test/controller/post/PostController.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.example.networker_test.domain.post.Post;
66
import com.example.networker_test.service.post.PostService;
7+
import org.springframework.data.domain.Page;
78
import org.springframework.stereotype.Controller;
89
import org.springframework.ui.Model;
910
import org.springframework.web.bind.annotation.GetMapping;
@@ -22,9 +23,12 @@ public class PostController {
2223
private final PostService postService;//의존성 주입
2324

2425
@GetMapping("/list")//게시물 리스트 페이지 연결
25-
public String list(Model model) {
26-
List<Post> postList = this.postService.getList();
27-
model.addAttribute("postList", postList);
26+
public String list(Model model, @RequestParam(value="page",defaultValue = "0")int page) {
27+
if (page < 0) {
28+
page = 0; // 페이지 번호가 음수일 경우 0으로 설정
29+
}
30+
Page<Post> paging = this.postService.getList(page);
31+
model.addAttribute("paging", paging);
2832
return "board";
2933
}
3034

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.example.networker_test.controller.post;
2+
3+
4+
import java.util.List;
5+
6+
import com.example.networker_test.domain.post.Post;
7+
import com.example.networker_test.domain.post.PostLaw;
8+
import com.example.networker_test.service.post.PostLawService;
9+
import com.example.networker_test.service.post.PostService;
10+
import org.springframework.data.domain.Page;
11+
import org.springframework.stereotype.Controller;
12+
import org.springframework.ui.Model;
13+
import org.springframework.web.bind.annotation.GetMapping;
14+
import org.springframework.web.bind.annotation.PathVariable;
15+
import org.springframework.web.bind.annotation.PostMapping;
16+
import org.springframework.web.bind.annotation.RequestMapping;
17+
import org.springframework.web.bind.annotation.RequestParam;
18+
19+
import lombok.RequiredArgsConstructor;
20+
21+
@Controller
22+
@RequestMapping("/lawsupport")
23+
@RequiredArgsConstructor
24+
public class PostLawController {
25+
26+
private final PostLawService postLawService;//의존성 주입
27+
28+
@GetMapping("/main")//게시물 리스트 페이지 연결
29+
public String list(Model model, @RequestParam(value="page",defaultValue = "0")int page) {
30+
if (page < 0) {
31+
page = 0; // 페이지 번호가 음수일 경우 0으로 설정
32+
}
33+
Page<PostLaw> paging = this.postLawService.getList(page);
34+
model.addAttribute("paging", paging);
35+
return "lawsupport";
36+
}
37+
38+
@GetMapping(value="/detail/{id}")//특정 게시물의 페이지 연결
39+
public String detail(Model model, @PathVariable("id") Integer id) {
40+
PostLaw postLaw = this.postLawService.getPost(id);
41+
model.addAttribute("postLaw", postLaw);
42+
return "post_law";
43+
}
44+
45+
@GetMapping("/create")//게시물 등록 요청 페이지 연결
46+
public String postCreate() {
47+
return "createpost_law";
48+
}
49+
50+
@PostMapping("/create")//게시물 등록 처리
51+
public String questionCreate(@RequestParam(value="subject")String subject, @RequestParam(value="content")String content) {
52+
this.postLawService.create(subject, content);
53+
return "redirect:/lawsupport/main";//저장 후 목록으로
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.example.networker_test.domain.comment;
2+
3+
import java.time.LocalDateTime;
4+
5+
import com.example.networker_test.domain.post.Post;
6+
7+
import com.example.networker_test.domain.post.PostLaw;
8+
import jakarta.persistence.Column;
9+
import jakarta.persistence.Entity;
10+
import jakarta.persistence.GeneratedValue;
11+
import jakarta.persistence.GenerationType;
12+
import jakarta.persistence.Id;
13+
import jakarta.persistence.ManyToOne;
14+
import lombok.Getter;
15+
import lombok.Setter;
16+
17+
@Entity
18+
@Getter
19+
@Setter
20+
public class CommentLaw {
21+
@Id
22+
@GeneratedValue(strategy=GenerationType.IDENTITY)
23+
private Integer id;//댓글 고유번호
24+
25+
@Column(columnDefinition = "TEXT")//댓글의 내용
26+
private String content;
27+
28+
private LocalDateTime createDate;//댓글 작성일
29+
30+
@ManyToOne
31+
private PostLaw postLaw;//하나의 게시물, 여러 댓글
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.example.networker_test.domain.post;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.List;
5+
6+
import com.example.networker_test.domain.comment.Comment;
7+
8+
import com.example.networker_test.domain.comment.CommentLaw;
9+
import jakarta.persistence.CascadeType;
10+
import jakarta.persistence.Column;
11+
import jakarta.persistence.Entity;
12+
import jakarta.persistence.GeneratedValue;
13+
import jakarta.persistence.GenerationType;
14+
import jakarta.persistence.Id;
15+
import jakarta.persistence.OneToMany;
16+
import lombok.Getter;
17+
import lombok.Setter;
18+
19+
@Entity
20+
@Getter
21+
@Setter
22+
public class PostLaw {
23+
@Id
24+
@GeneratedValue(strategy=GenerationType.IDENTITY)
25+
private Integer id;
26+
27+
@Column(length=100)
28+
private String subject;
29+
30+
@Column(columnDefinition = "TEXT")
31+
private String content;
32+
33+
private LocalDateTime createDate;
34+
35+
@OneToMany(mappedBy = "postLaw", cascade = CascadeType.REMOVE)
36+
private List<CommentLaw> commentLawList;
37+
38+
39+
}
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.example.networker_test.repository.comment;
2+
3+
import com.example.networker_test.domain.comment.Comment;
4+
import com.example.networker_test.domain.comment.CommentLaw;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
7+
public interface CommentLawRepository extends JpaRepository<CommentLaw, Integer>{
8+
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.networker_test.repository.post;
2+
3+
import com.example.networker_test.domain.post.Post;
4+
import com.example.networker_test.domain.post.PostLaw;
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
7+
import org.springframework.data.jpa.repository.JpaRepository;
8+
9+
import java.util.List;
10+
11+
public interface PostLawRepository extends JpaRepository<PostLaw, Integer> {
12+
PostLaw findBySubject(String subject);
13+
PostLaw findBySubjectAndContent(String subject, String content);
14+
List<PostLaw> findBySubjectLike(String subject);
15+
Page<PostLaw> findAll(Pageable pageable);
16+
17+
}
18+
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package com.example.networker_test.repository.post;
22

33
import com.example.networker_test.domain.post.Post;
4+
import org.springframework.data.domain.Page;
5+
import org.springframework.data.domain.Pageable;
46
import org.springframework.data.jpa.repository.JpaRepository;
57

8+
import java.util.List;
9+
610
public interface PostRepository extends JpaRepository<Post, Integer> {
7-
11+
Post findBySubject(String subject);
12+
Post findBySubjectAndContent(String subject, String content);
13+
List<Post> findBySubjectLike(String subject);
14+
Page<Post> findAll(Pageable pageable);
815

916
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.example.networker_test.service.comment;
2+
3+
import java.time.LocalDateTime;
4+
5+
import com.example.networker_test.domain.comment.Comment;
6+
import com.example.networker_test.domain.comment.CommentLaw;
7+
import com.example.networker_test.domain.post.PostLaw;
8+
import com.example.networker_test.repository.comment.CommentLawRepository;
9+
import com.example.networker_test.repository.comment.CommentRepository;
10+
import org.springframework.stereotype.Service;
11+
12+
import com.example.networker_test.domain.post.Post;
13+
14+
import lombok.RequiredArgsConstructor;
15+
16+
@Service
17+
@RequiredArgsConstructor
18+
public class CommentLawService {
19+
20+
private final CommentLawRepository commentLawRepository;
21+
22+
public void create(PostLaw postLaw, String content) {
23+
CommentLaw commentLaw = new CommentLaw();
24+
commentLaw.setContent(content);
25+
commentLaw.setCreateDate(LocalDateTime.now());
26+
commentLaw.setPostLaw(postLaw);
27+
this.commentLawRepository.save(commentLaw);
28+
}//댓글 생성 처리 연결(controller - entity)
29+
30+
}

0 commit comments

Comments
 (0)