Skip to content
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

[과제 #4 제출 스레드] #33

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.group.libarayapp.controller.task;
package com.group.libarayapp.controller.task02;

import com.group.libarayapp.dto.task.request.Ex01Request;
import com.group.libarayapp.dto.task.response.Ex01Response;
import com.group.libarayapp.dto.task02.request.Ex01Request;
import com.group.libarayapp.dto.task02.response.Ex01Response;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.group.libarayapp.controller.task;
package com.group.libarayapp.controller.task02;

import com.group.libarayapp.dto.task.request.Ex02Request;
import com.group.libarayapp.dto.task.response.Ex02Response;
import com.group.libarayapp.dto.task02.request.Ex02Request;
import com.group.libarayapp.dto.task02.response.Ex02Response;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.group.libarayapp.controller.task;
package com.group.libarayapp.controller.task02;


import com.group.libarayapp.dto.task.request.Ex03Request;
import com.group.libarayapp.dto.task.response.Ex03Response;
import com.group.libarayapp.dto.task02.request.Ex03Request;
import com.group.libarayapp.dto.task02.response.Ex03Response;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.group.libarayapp.controller.task04;

import com.group.libarayapp.dto.task04.request.Task04CreateRequest;
import com.group.libarayapp.dto.task04.request.Task04ExRequest;
import com.group.libarayapp.dto.task04.response.Task04ExResponse;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class Task04ExController {

private final JdbcTemplate jdbcTemplate;

public Task04ExController(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

// 문제 1
@PostMapping("/api/v1/fruit")
public void saveFruit(@RequestBody Task04ExRequest request) {
String sql = "insert into fruit(name, warehousing, price) values(?, ?, ?)";
jdbcTemplate.update(sql, request.getName(), request.getWarehousingDate(), request.getPrice());
}


// 문제 2
@PutMapping("/api/v1/fruit")
public void salesQuantityFruit(@RequestBody Task04ExRequest request) {
String readSql = "select * from fruit where id=?";
boolean isSalesFruit = jdbcTemplate.query(readSql, (rs, rowNum) -> 0, request.getId()).isEmpty();
if (isSalesFruit) {
throw new IllegalArgumentException();
}
String sql = "update fruit set salesQuantity=? where id=?";
jdbcTemplate.update(sql, request.getSalesQuantity() + 1, request.getId());
}

// 문제 3 - sum, group by 미적용
@GetMapping("/api/v1/fruit/stat")
public Task04ExResponse SalesAmountFruit(@RequestParam String name) {
String readNotSalesSql = """
select sum(price) as notSalesAmount
from fruit
where name=? and salesQuantity = 0
group by salesQuantity;
""";
List<Integer> readNotSalesList = jdbcTemplate.query(readNotSalesSql, (rs, rowNum) -> rs.getInt("notSalesAmount"), name);

String readSalesSql = """
select sum(price) as salesAmount
from fruit
where name=? and salesQuantity = 1
group by salesQuantity;
""";
List<Integer> readSalesList = jdbcTemplate.query(readSalesSql, (rs, rowNum) -> rs.getInt("salesAmount"), name);

return new Task04ExResponse(readSalesList, readNotSalesList);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.group.libarayapp.dto.task.request;
package com.group.libarayapp.dto.task02.request;

public class Ex01Request {
private final int num1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.group.libarayapp.dto.task.request;
package com.group.libarayapp.dto.task02.request;

import java.time.LocalDate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.group.libarayapp.dto.task.request;
package com.group.libarayapp.dto.task02.request;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.group.libarayapp.dto.task.response;
package com.group.libarayapp.dto.task02.response;

import com.group.libarayapp.dto.task.request.Ex01Request;
import com.group.libarayapp.dto.task02.request.Ex01Request;

public class Ex01Response {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.group.libarayapp.dto.task.response;
package com.group.libarayapp.dto.task02.response;

import com.group.libarayapp.dto.task.request.Ex02Request;
import com.group.libarayapp.dto.task02.request.Ex02Request;

import java.time.format.TextStyle;
import java.util.Locale;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.group.libarayapp.dto.task.response;
package com.group.libarayapp.dto.task02.response;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.group.libarayapp.dto.task04.request;

import java.time.LocalDate;

public class Task04CreateRequest {

Long id;
String name;
LocalDate warehousing;
Long price;
int salesQuantity;

public Task04CreateRequest(Long id, String name, LocalDate warehousing, Long price, int salesQuantity) {
this.id = id;
this.name = name;
this.warehousing = warehousing;
this.price = price;
this.salesQuantity = salesQuantity;
}

public String getName() {
return name;
}

public Long getId() {
return id;
}

public LocalDate getWarehousing() {
return warehousing;
}

public Long getPrice() {
return price;
}

public int getSalesQuantity() {
return salesQuantity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.group.libarayapp.dto.task04.request;

import java.time.LocalDate;

public class Task04ExRequest {

private Long id;
private String name;
private LocalDate warehousingDate;

private int salesQuantity;
private Long price;

public Task04ExRequest(String name, LocalDate warehousingDate, Long price) {
this.name = name;
this.warehousingDate = warehousingDate;
this.price = price;
}

public String getName() {
return name;
}

public LocalDate getWarehousingDate() {
return warehousingDate;
}

public Long getPrice() {
return price;
}

public Long getId() {
return id;
}

public int getSalesQuantity() {
return salesQuantity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.group.libarayapp.dto.task04.response;

import java.util.List;

public class Task04ExResponse {
private final long salesAmount;
private final long notSalesAmount;

public Task04ExResponse(List<Integer> readSalesList, List<Integer> readNotSalesList) {
this.salesAmount = readSalesList.get(0);
this.notSalesAmount = readNotSalesList.get(0);
}

public long getSalesAmount() {
return salesAmount;
}

public long getNotSalesAmount() {
return notSalesAmount;
}
}