문제 1
Controller
@GetMapping("api/v1/calc")
public Calc calc(CalcResponse request){
return new Calc(request);
}
Domain
public class Calc {
private int add;
private int minus;
private int multiply;
public Calc(CalcResponse response) {
this.add = response.getNum1() + response.getNum2();
this.minus = response.getNum1() - response.getNum2();
this.multiply = response.getNum1() * response.getNum2();
}
public int getAdd() {
return add;
}
public int getMinus() {
return minus;
}
public int getMultiply() {
return multiply;
}
}
DTO
public class CalcResponse {
private int num1;
private int num2;
public CalcResponse(int num1, int num2) {
this.num1 = num1;
this.num2 = num2;
}
public int getNum1() {
return num1;
}
public int getNum2() {
return num2;
}
}
결과
문제 2
Controller
@GetMapping("api/v1/day-of-the-week")
public DateResponse calc(CustomDate request){
LocalDate date = request.getDate();
DayOfWeek dayOfWeek = date.getDayOfWeek();
return new DateResponse(dayOfWeek);
}
Domain
public class CustomDate {
private LocalDate date;
private DayOfWeek dayOfWeek;
public Date(LocalDate date, DayOfWeek dayOfWeek) {
this.date = date;
this.dayOfWeek = dayOfWeek;
}
public LocalDate getDate() {
return date;
}
public DayOfWeek getDayOfWeek() {
return dayOfWeek;
}
DTO
public class DateResponse {
private String dayOfTheWeek;
public DateResponse(DayOfWeek dayOfWeek) {
this.dayOfTheWeek = dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.US).toUpperCase();
}
public String getDayOfTheWeek() {
return dayOfTheWeek;
}
결과
문제 3
Controller
@PostMapping("/api/vi/add") // POST /
public int addNumbers(@RequestBody AddResponse add) {
int sum = 0;
for(int number : add.getNumbers()) {
sum += number;
}
return sum;
}
DTO
private List<Integer> numbers;
public List<Integer> getNumbers() {
return numbers;
}
결과
'인프런 워밍업 스터디 > 과제' 카테고리의 다른 글
[인프런 워밍업 스터디 클럽 0기 - BE] #6 과제 (0) | 2024.02.26 |
---|---|
[인프런 워밍업 스터디 클럽 0기 - BE] #5 과제 (0) | 2024.02.23 |
[인프런 워밍업 스터디 클럽 0기 - BE] #4 과제 (0) | 2024.02.22 |
[인프런 워밍업 스터디 클럽 0기 - BE] #3 과제 (0) | 2024.02.21 |
[인프런 워밍업 스터디 클럽 0기 - BE] #1 과제 (0) | 2024.02.19 |