-
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
[2주차 기본/심화 과제 제출] #2
Open
unanchoi
wants to merge
2
commits into
main
Choose a base branch
from
week2
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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,16 @@ | ||
package com.seminar.gosopt; | ||
|
||
import lombok.Getter; | ||
|
||
public class Athletes extends Person { | ||
|
||
private SportsType type; | ||
|
||
public SportsType getType() { | ||
return type; | ||
} | ||
|
||
public Athletes(SportsType type) { | ||
this.type = type; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
week1/src/main/java/com/seminar/gosopt/FootballPlayer.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,15 @@ | ||
package com.seminar.gosopt; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class FootballPlayer extends Athletes{ | ||
|
||
public FootballPlayer(SportsType type) { | ||
super(type); | ||
} | ||
|
||
protected void introduce() { | ||
System.out.println("저는 " + this.getType().getValue() + "선수 입니다."); | ||
} | ||
} |
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
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,17 @@ | ||
package com.seminar.gosopt; | ||
|
||
import lombok.Getter; | ||
|
||
public abstract class Person { | ||
|
||
private String name; | ||
private int age; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
} |
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,51 @@ | ||
package com.seminar.gosopt; | ||
|
||
public class Poketmon { | ||
|
||
private String name; | ||
private String type; | ||
private String skill; | ||
|
||
public Poketmon(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Poketmon(String name, String type) { | ||
this.name = name; | ||
this.type = type; | ||
} | ||
|
||
public Poketmon() { | ||
|
||
} | ||
|
||
public Poketmon(String name, String type, String skill) { | ||
this.name = name; | ||
this.type = type; | ||
this.skill = skill; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getSkill() { | ||
return skill; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public void setSkill(String skill) { | ||
this.skill = skill; | ||
} | ||
} |
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,17 @@ | ||
package com.seminar.gosopt; | ||
|
||
public enum SportsType { | ||
FOOTBALL("축구"), | ||
BASKETBALL("농구"), | ||
TENNIS("테니스"); | ||
|
||
private final String value; | ||
|
||
SportsType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
week1/src/main/java/com/seminar/gosopt/interfacepractice/Pikachu.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,13 @@ | ||
package com.seminar.gosopt.interfacepractice; | ||
|
||
public class Pikachu implements Poketmon{ | ||
|
||
@Override | ||
public void 몸통박치기() { | ||
System.out.println("몸통 박치기"); | ||
} | ||
|
||
public void 백만볼트() { | ||
System.out.println("피카피카"); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
week1/src/main/java/com/seminar/gosopt/interfacepractice/Poketmon.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 com.seminar.gosopt.interfacepractice; | ||
|
||
public interface Poketmon { | ||
|
||
public abstract void 몸통박치기(); | ||
} |
43 changes: 43 additions & 0 deletions
43
week2/src/main/java/com/seminar/week2/api/user/UserController.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,43 @@ | ||
package com.seminar.week2.api.user; | ||
|
||
import com.seminar.week2.api.user.dto.*; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api") | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
@PostMapping("/user") | ||
public String register(@RequestBody final RegisterRequestDto request) { | ||
System.out.println("나이 : " + request.getAge()); | ||
System.out.println("이름 " + request.getName()); | ||
System.out.println("번호 " + request.getContact()); | ||
return "SAVE OK"; | ||
} | ||
|
||
@PostMapping("/v2/user") | ||
public RegisterResponseDto registerV2(@RequestBody final RegisterRequestDto requestDto) { | ||
RegisterResponseDto dto = userService.register(requestDto); | ||
return dto; | ||
} | ||
|
||
@GetMapping("/user/{userId}") | ||
public GetResponseDto get(@PathVariable Long userId) { | ||
return userService.get(userId); | ||
} | ||
|
||
@PutMapping("/user/{userId}") | ||
public UpdateResponseDto update(@PathVariable Long userId, | ||
@RequestBody final UpdateRequestDto updateRequestDto) { | ||
return userService.update(userId, updateRequestDto); | ||
} | ||
|
||
@DeleteMapping("/user/{userId}") | ||
public String delete(@PathVariable Long userId) { | ||
return userService.delete(userId); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
week2/src/main/java/com/seminar/week2/api/user/UserService.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,73 @@ | ||
package com.seminar.week2.api.user; | ||
|
||
import com.seminar.week2.api.user.dto.*; | ||
import com.seminar.week2.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
|
||
public RegisterResponseDto register(RegisterRequestDto requestDto) { | ||
User user = User.builder() | ||
.id(1L) | ||
.age(requestDto.getAge()) | ||
.contact(requestDto.getContact()) | ||
.gender("man") | ||
.isStudent(true) | ||
.name(requestDto.getName()) | ||
.build(); | ||
|
||
return new RegisterResponseDto(user.getName(),user.getContact(), user.getAge()); | ||
} | ||
|
||
public GetResponseDto get(Long userId) { | ||
User user = User.builder() | ||
.id(1L) | ||
.age(20) | ||
.contact("010-1123-1234") | ||
.gender("man") | ||
.isStudent(true) | ||
.name("unan") | ||
.build(); | ||
|
||
if (userId != user.getId()) { | ||
throw new RuntimeException("유저 존재하지 않습니다."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자바로 예외처리를 하는 경우 throw new와 같이 직접 예외처리를 하는 이유가 궁금했었는데, 이해가 되는 코드인것 같습니다. 이부분은 다른 예제에서도 많이 사용할 수 있어서 도움이 된것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니당 |
||
} | ||
return new GetResponseDto( | ||
user.getName(), user.getContact(), user.getAge()); | ||
} | ||
|
||
public UpdateResponseDto update(Long userId, UpdateRequestDto requestDto) { | ||
User user = User.builder() | ||
.id(1L) | ||
.age(20) | ||
.contact("010-1123-1234") | ||
.gender("man") | ||
.isStudent(true) | ||
.name("unan") | ||
.build(); | ||
|
||
user.setAge(requestDto.getAge()); | ||
user.setContact(requestDto.getContact()); | ||
user.setName(requestDto.getName()); | ||
|
||
return new UpdateResponseDto(user.getName(), user.getContact(), user.getAge()); | ||
} | ||
|
||
public String delete(Long userId) { | ||
User user = User.builder() | ||
.id(1L) | ||
.age(20) | ||
.contact("010-1123-1234") | ||
.gender("man") | ||
.isStudent(true) | ||
.name("unan") | ||
.build(); | ||
|
||
user = null; | ||
return "OK"; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
week2/src/main/java/com/seminar/week2/api/user/dto/GetResponseDto.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 com.seminar.week2.api.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public class GetResponseDto { | ||
private String name; | ||
private String contact; | ||
private int age; | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
week2/src/main/java/com/seminar/week2/api/user/dto/RegisterRequestDto.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,15 @@ | ||
package com.seminar.week2.api.user.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class RegisterRequestDto { | ||
|
||
private String name; | ||
private String contact; | ||
private int age; | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
week2/src/main/java/com/seminar/week2/api/user/dto/RegisterResponseDto.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,14 @@ | ||
package com.seminar.week2.api.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class RegisterResponseDto { | ||
|
||
private String name; | ||
private String contact; | ||
private int age; | ||
} |
13 changes: 13 additions & 0 deletions
13
week2/src/main/java/com/seminar/week2/api/user/dto/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,13 @@ | ||
package com.seminar.week2.api.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class UpdateRequestDto { | ||
private String name; | ||
private String contact; | ||
private int age; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
week2/src/main/java/com/seminar/week2/api/user/dto/UpdateResponseDto.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 com.seminar.week2.api.user.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public class UpdateResponseDto { | ||
private String name; | ||
private String contact; | ||
private int age; | ||
} |
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.
Builder Pattern을 어떻게 적용할 수 있는지 잘 보여주는 코드 같습니다 역시 갓유난님.. 👍
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.
저도 builder patter이 신기해서 찾아보게 됐네요.... 군더더기 없이 깔끔해서 최고네요.....역시 최윤한남자가있어널너무사랑한 답습니다....(아주 대단하다는 뜻.)