diff --git a/build.gradle b/build.gradle index e79c807..6fc0095 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,8 @@ subprojects { compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation group: 'io.springfox', name: 'springfox-swagger2', version: '3.0.0' + implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' } tasks.named('test') { diff --git a/week1/src/main/java/com/seminar/gosopt/Athletes.java b/week1/src/main/java/com/seminar/gosopt/Athletes.java new file mode 100644 index 0000000..6f44a1d --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/Athletes.java @@ -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; + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/FootballPlayer.java b/week1/src/main/java/com/seminar/gosopt/FootballPlayer.java new file mode 100644 index 0000000..27fd7be --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/FootballPlayer.java @@ -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() + "선수 입니다."); + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/Main.java b/week1/src/main/java/com/seminar/gosopt/Main.java index 2b22bb9..0ee63ac 100644 --- a/week1/src/main/java/com/seminar/gosopt/Main.java +++ b/week1/src/main/java/com/seminar/gosopt/Main.java @@ -2,8 +2,31 @@ import lombok.Getter; +import java.util.ArrayList; +import java.util.List; + public class Main { public static void main(String[] args) { System.out.println("hello world"); + + FootballPlayer footballPlayer = new FootballPlayer(SportsType.FOOTBALL); + System.out.println(footballPlayer.getType()); + footballPlayer.introduce(); + + + Poketmon ggobugi = new Poketmon("ggobugi"); + System.out.println(System.identityHashCode(ggobugi)); + System.out.println(ggobugi.getClass()); + System.out.println(ggobugi.getName()); + System.out.println(ggobugi.getSkill()); + + List foodList = new ArrayList<>(); + foodList.add("apple"); + foodList.add("banana"); + foodList.add("orange"); + + for (String food: foodList) { + System.out.println(food); + } } } \ No newline at end of file diff --git a/week1/src/main/java/com/seminar/gosopt/Person.java b/week1/src/main/java/com/seminar/gosopt/Person.java new file mode 100644 index 0000000..7aeed44 --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/Person.java @@ -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; + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/Poketmon.java b/week1/src/main/java/com/seminar/gosopt/Poketmon.java new file mode 100644 index 0000000..e04a7cd --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/Poketmon.java @@ -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; + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/SportsType.java b/week1/src/main/java/com/seminar/gosopt/SportsType.java new file mode 100644 index 0000000..188cdbd --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/SportsType.java @@ -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; + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/interfacepractice/Pikachu.java b/week1/src/main/java/com/seminar/gosopt/interfacepractice/Pikachu.java new file mode 100644 index 0000000..ce4e868 --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/interfacepractice/Pikachu.java @@ -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("피카피카"); + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/interfacepractice/Poketmon.java b/week1/src/main/java/com/seminar/gosopt/interfacepractice/Poketmon.java new file mode 100644 index 0000000..9c0726a --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/interfacepractice/Poketmon.java @@ -0,0 +1,6 @@ +package com.seminar.gosopt.interfacepractice; + +public interface Poketmon { + + public abstract void 몸통박치기(); +} diff --git a/week2/src/main/java/com/seminar/week2/api/user/UserController.java b/week2/src/main/java/com/seminar/week2/api/user/UserController.java new file mode 100644 index 0000000..28c0ed9 --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/api/user/UserController.java @@ -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); + } +} diff --git a/week2/src/main/java/com/seminar/week2/api/user/UserService.java b/week2/src/main/java/com/seminar/week2/api/user/UserService.java new file mode 100644 index 0000000..ed3653a --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/api/user/UserService.java @@ -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("유저 존재하지 않습니다."); + } + 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"; + } + +} diff --git a/week2/src/main/java/com/seminar/week2/api/user/dto/GetResponseDto.java b/week2/src/main/java/com/seminar/week2/api/user/dto/GetResponseDto.java new file mode 100644 index 0000000..dd0f1df --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/api/user/dto/GetResponseDto.java @@ -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; + + +} diff --git a/week2/src/main/java/com/seminar/week2/api/user/dto/RegisterRequestDto.java b/week2/src/main/java/com/seminar/week2/api/user/dto/RegisterRequestDto.java new file mode 100644 index 0000000..67cf296 --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/api/user/dto/RegisterRequestDto.java @@ -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; + +} diff --git a/week2/src/main/java/com/seminar/week2/api/user/dto/RegisterResponseDto.java b/week2/src/main/java/com/seminar/week2/api/user/dto/RegisterResponseDto.java new file mode 100644 index 0000000..281b834 --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/api/user/dto/RegisterResponseDto.java @@ -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; +} diff --git a/week2/src/main/java/com/seminar/week2/api/user/dto/UpdateRequestDto.java b/week2/src/main/java/com/seminar/week2/api/user/dto/UpdateRequestDto.java new file mode 100644 index 0000000..1eae59e --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/api/user/dto/UpdateRequestDto.java @@ -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; + +} diff --git a/week2/src/main/java/com/seminar/week2/api/user/dto/UpdateResponseDto.java b/week2/src/main/java/com/seminar/week2/api/user/dto/UpdateResponseDto.java new file mode 100644 index 0000000..5c3468d --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/api/user/dto/UpdateResponseDto.java @@ -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; +} diff --git a/week2/src/main/java/com/seminar/week2/config/SwaggerConfig.java b/week2/src/main/java/com/seminar/week2/config/SwaggerConfig.java new file mode 100644 index 0000000..a6e530d --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/config/SwaggerConfig.java @@ -0,0 +1,38 @@ +package com.seminar.week2.config; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.Collections; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(this.apiInfo()) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("demo") + .description("API EXAMPLE") + .build(); + } + +} diff --git a/week2/src/main/java/com/seminar/week2/controller/HealthCheckController.java b/week2/src/main/java/com/seminar/week2/controller/HealthCheckController.java deleted file mode 100644 index 181f476..0000000 --- a/week2/src/main/java/com/seminar/week2/controller/HealthCheckController.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.seminar.week2.controller; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class HealthCheckController { - - - @GetMapping("/health") - public String healthCheck() { - return "OK"; - } -} diff --git a/week2/src/main/java/com/seminar/week2/domain/User.java b/week2/src/main/java/com/seminar/week2/domain/User.java new file mode 100644 index 0000000..3d68c42 --- /dev/null +++ b/week2/src/main/java/com/seminar/week2/domain/User.java @@ -0,0 +1,53 @@ +package com.seminar.week2.domain; + + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class User { + + private Long id; + private String gender; + private String name; + private String contact; + private int age; + private boolean isStudent; + + @Builder + public User(Long id, String gender, String name, String contact, int age, boolean isStudent) { + this.id = id; + this.gender = gender; + this.name = name; + this.contact = contact; + this.age = age; + this.isStudent = isStudent; + } + + public void setId(Long id) { + this.id = id; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public void setName(String name) { + this.name = name; + } + + public void setContact(String contact) { + this.contact = contact; + } + + public void setAge(int age) { + this.age = age; + } + + public void setStudent(boolean student) { + isStudent = student; + } +} diff --git a/week2/src/main/resources/application.yml b/week2/src/main/resources/application.yml index 0884131..44f9a8d 100644 --- a/week2/src/main/resources/application.yml +++ b/week2/src/main/resources/application.yml @@ -1,2 +1,7 @@ server: - port: 8082 \ No newline at end of file + port: 8082 + +spring: + mvc: + pathmatch: + matching-strategy: ant_path_matcher \ No newline at end of file