-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[๊ณผ์ #4 ์ ์ถ ์ค๋ ๋]
- Loading branch information
Showing
13 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
...ayapp/controller/task/Ex01Controller.java โ ...app/controller/task02/Ex01Controller.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
6 changes: 3 additions & 3 deletions
6
...ayapp/controller/task/Ex02Controller.java โ ...app/controller/task02/Ex02Controller.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
6 changes: 3 additions & 3 deletions
6
...ayapp/controller/task/Ex03Controller.java โ ...app/controller/task02/Ex03Controller.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
62 changes: 62 additions & 0 deletions
62
library-app/src/main/java/com/group/libarayapp/controller/task04/Task04ExController.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,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); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...arayapp/dto/task/request/Ex01Request.java โ ...ayapp/dto/task02/request/Ex01Request.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
2 changes: 1 addition & 1 deletion
2
...arayapp/dto/task/request/Ex02Request.java โ ...ayapp/dto/task02/request/Ex02Request.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
2 changes: 1 addition & 1 deletion
2
...arayapp/dto/task/request/Ex03Request.java โ ...ayapp/dto/task02/request/Ex03Request.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
4 changes: 2 additions & 2 deletions
4
...ayapp/dto/task/response/Ex01Response.java โ ...app/dto/task02/response/Ex01Response.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
4 changes: 2 additions & 2 deletions
4
...ayapp/dto/task/response/Ex02Response.java โ ...app/dto/task02/response/Ex02Response.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
2 changes: 1 addition & 1 deletion
2
...ayapp/dto/task/response/Ex03Response.java โ ...app/dto/task02/response/Ex03Response.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
40 changes: 40 additions & 0 deletions
40
library-app/src/main/java/com/group/libarayapp/dto/task04/request/Task04CreateRequest.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,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; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
library-app/src/main/java/com/group/libarayapp/dto/task04/request/Task04ExRequest.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,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; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
library-app/src/main/java/com/group/libarayapp/dto/task04/response/Task04ExResponse.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,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; | ||
} | ||
} |