-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Week3] 기본과제 & 심화과제 제출 #6
Open
jinchiim
wants to merge
12
commits into
main
Choose a base branch
from
third_seminar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b911ba0
second-Seminar basic Assignment
jinchiim aeca861
PostService [fix]
jinchiim 9fefb90
Second-Seminar moreAssignment
jinchiim 6c1cabe
Second-Seminar moreAssignment
jinchiim 0ff8908
Second-Seminar moreAssignment
jinchiim 3976135
second-seminar more Assignment
jinchiim 6ef989e
no message
jinchiim 02061c2
Revert "no message"
jinchiim cae767e
Revert "Revert "no message""
jinchiim 410ed13
Revert "Revert "Revert "no message"""
jinchiim 4974a48
Third-Seminar basicAssignment init-commit
jinchiim 9e1fcba
[ADD] third-seminar more-Assignment init-commit
jinchiim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...ss/SecondSeminar/src/main/java/sopt/org/SecondSeminar/controller/post/PostController.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,56 @@ | ||
package sopt.org.SecondSeminar.controller.post; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
import sopt.org.SecondSeminar.controller.post.dto.request.SaveRequestDto; | ||
import sopt.org.SecondSeminar.controller.post.dto.request.UpdateRequestDto; | ||
import sopt.org.SecondSeminar.service.PostService; | ||
import static sopt.org.SecondSeminar.SecondSeminarApplication.postList; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") // api 버전 처리 | ||
|
||
public class PostController { | ||
private final PostService postService; | ||
|
||
@PostMapping("/posts") | ||
public String register(@RequestBody final SaveRequestDto request) { | ||
|
||
Long userId = postService.save(request); // 컨트롤러가 service한테 요청. 일을 대신 시킴 | ||
System.out.println(postList); // // servics는 글에 대한 서비스 컨트롤러는 어디로 향하는지 중간다리 | ||
|
||
return userId + "번 글 등록이 완료됐습니다."; | ||
} | ||
|
||
@GetMapping("/posts/{userId}") // 아이디로 게시물을 찾는 메서드 | ||
public String getOne(@PathVariable final Long userId) { | ||
System.out.println(userId + "의 게시물 조회" + postList.get(userId.intValue()-1)); // 최고 | ||
|
||
|
||
return postService.getPostInfo(userId); // 보내주기만 한다. | ||
} | ||
|
||
@GetMapping("/posts") // 제목으로 글을 찾는 메서드 | ||
|
||
public String search(@RequestParam final String title) { | ||
System.out.println("글 제목으로 검색: " + title); | ||
|
||
return postService.getByTitle(title); | ||
} | ||
|
||
@PutMapping("/posts/{userId}") // 글을 수정하는 메서드 | ||
public String update(@PathVariable final Long userId, @RequestBody UpdateRequestDto update) { | ||
System.out.println(userId + " 님의 글을 수정했습니다."); | ||
|
||
return postService.updatePost(userId, update); | ||
} | ||
|
||
@DeleteMapping("/posts/{userId}") // API에 행위가 들어가면 안된다는 피드백으로 변경 | ||
public String delete(@PathVariable final Long userId){ | ||
System.out.println(userId + " 님의 글을 삭제했습니다."); | ||
|
||
return postService.deletePost(userId); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...inar/src/main/java/sopt/org/SecondSeminar/controller/post/dto/request/SaveRequestDto.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,12 @@ | ||
package sopt.org.SecondSeminar.controller.post.dto.request; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class SaveRequestDto { | ||
private String title; | ||
private String content; | ||
} |
11 changes: 11 additions & 0 deletions
11
...ar/src/main/java/sopt/org/SecondSeminar/controller/post/dto/request/UpdateRequestDto.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 sopt.org.SecondSeminar.controller.post.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class UpdateRequestDto { | ||
private String title; | ||
private String content; | ||
} |
37 changes: 37 additions & 0 deletions
37
SecondClass/SecondSeminar/src/main/java/sopt/org/SecondSeminar/domain/post/Post.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,37 @@ | ||
package sopt.org.SecondSeminar.domain.post; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter // 객체에 맞는 클래스 정의 | ||
public class Post { // 하나의 엔티티 Post 라는 테이블에서 세가지 속성을 가지겠다. | ||
|
||
private long id; | ||
private String title; | ||
private String content; | ||
|
||
public Post(String title, String content) { // 게시물을 불러올 메서드 | ||
this.title = title; | ||
this.content = content; | ||
} | ||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public void setTitle(String title) {this.title = title;} | ||
|
||
public void setContent(String content) {this.content = content;} | ||
|
||
|
||
@Override | ||
public String toString(){ | ||
return "id: " + this.id + "\n" + | ||
"title: " + this.title + "\n" + | ||
"content: " + this.content + "\n"; | ||
|
||
} | ||
public String idToString(){ // 제목과 글 내용만 불러오고 싶어서 따로 만들어 줬습니다. | ||
return "제목: " + this.title + "\n" + | ||
"글내용: " + this.content + "\n"; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
SecondClass/SecondSeminar/src/main/java/sopt/org/SecondSeminar/service/PostService.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,64 @@ | ||
package sopt.org.SecondSeminar.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import sopt.org.SecondSeminar.controller.post.dto.request.SaveRequestDto; | ||
import sopt.org.SecondSeminar.controller.post.dto.request.UpdateRequestDto; | ||
import sopt.org.SecondSeminar.domain.post.Post; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static sopt.org.SecondSeminar.SecondSeminarApplication.postList; | ||
|
||
|
||
|
||
@Service // 요청 처리 find, save 이런식으로 행위는 서비스 | ||
public class PostService { | ||
public Long save(SaveRequestDto requestDto){ // 저장해주는 메서드 | ||
Post newPost = new Post( | ||
requestDto.getTitle(), | ||
requestDto.getContent() | ||
); | ||
|
||
postList.add(newPost); | ||
newPost.setId((long) postList.size()); | ||
|
||
//저장한 유저 아이디 값 반환 | ||
return newPost.getId(); | ||
} | ||
|
||
public String getPostInfo(Long UserId) { // 아이디로 글을 찾는 메서드 | ||
Post post = postList.get(UserId.intValue() - 1); | ||
Post postInfo = new Post( // title과 content만 불러오고 싶어서 따로 만들었습니다. | ||
post.getTitle(), | ||
post.getContent() | ||
); | ||
|
||
return postInfo.idToString(); | ||
} | ||
|
||
public String getByTitle(String title) { // 찾는 제목을 포함하는 게시물을 찾는 메서드 | ||
ArrayList<String> titlePost = new ArrayList<>(); // 일회성 Array를 만들어주고 싶었습니다. | ||
for(Post post: postList) { | ||
if (post.getTitle().contains(title)){ | ||
titlePost.add(post.toString()); | ||
} | ||
} | ||
return "해당 제목을 포함하는 게시물: " + titlePost; | ||
} | ||
public String updatePost(Long UserId, UpdateRequestDto requestDto) { | ||
Post post = postList.get(UserId.intValue() - 1); | ||
post.setContent(requestDto.getContent()); // UpdateRequestDto에서 받은것을 post에서 할당 | ||
post.setTitle(requestDto.getTitle()); | ||
|
||
return "게시물 수정 완료: " + post; | ||
} | ||
|
||
public String deletePost(Long UserId) { | ||
if (UserId -1 >= postList.size()) { // 유저 아이디가 postList안에 존재하지 않을때 | ||
return "삭제할 글이 존재하지 않습니다"; | ||
} | ||
postList.remove(UserId.intValue() - 1); // 해당 post 삭제 | ||
return "게시물 삭제 완료"; | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,22 @@ | ||
# Getting Started | ||
|
||
### Reference Documentation | ||
For further reference, please consider the following sections: | ||
|
||
* [Official Gradle documentation](https://docs.gradle.org) | ||
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.7.11/gradle-plugin/reference/html/) | ||
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.7.11/gradle-plugin/reference/html/#build-image) | ||
* [Spring Web](https://docs.spring.io/spring-boot/docs/2.7.11/reference/htmlsingle/#web) | ||
|
||
### Guides | ||
The following guides illustrate how to use some features concretely: | ||
|
||
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) | ||
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) | ||
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) | ||
|
||
### Additional Links | ||
These additional references should also help you: | ||
|
||
* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) | ||
|
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,34 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '2.7.11' | ||
id 'io.spring.dependency-management' version '1.0.15.RELEASE' | ||
} | ||
|
||
group = 'sopt.org' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '11' | ||
|
||
configurations { | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'mysql:mysql-connector-java:8.0.32' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} | ||
|
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
ThirdClass/ThirdSeminar/gradle/wrapper/gradle-wrapper.properties
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 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p5: 이거 전에 제가 공부했던 내용인데 어떤 순서로 동작하는지 이해할 때 참고하시면 좋을 것 같아 남겨둡니다 ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
미쳤다 ㄷㄷ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와 저 지금 봤어요
진짜...대박이예요...저...진짜 감동받았어요.........