Skip to content

Commit

Permalink
Merge pull request #33 from LimdaeIl/feature/#31-task
Browse files Browse the repository at this point in the history
[๊ณผ์ œ #4 ์ œ์ถœ ์Šค๋ ˆ๋“œ]
  • Loading branch information
LimdaeIl committed Feb 22, 2024
2 parents d9ab4d5 + 1ecb857 commit 35bda8d
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 17 deletions.
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;
}
}

0 comments on commit 35bda8d

Please sign in to comment.