|
|
|
@ -1,16 +1,22 @@ |
|
|
|
|
package com.example.todoapp.controller; |
|
|
|
|
|
|
|
|
|
import com.example.todoapp.dto.DeleteStockRequest; |
|
|
|
|
import com.example.todoapp.dto.ResponseStockDTO; |
|
|
|
|
import com.example.todoapp.dto.StockDTO; |
|
|
|
|
import com.example.todoapp.model.Stocks; |
|
|
|
|
import com.example.todoapp.service.StocksService; |
|
|
|
|
import jakarta.validation.Valid; |
|
|
|
|
import lombok.Data; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import lombok.Data; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -81,27 +87,33 @@ public class StocksController { |
|
|
|
|
* @param stockDetails 更新内容 |
|
|
|
|
* @return 更新された在庫 |
|
|
|
|
*/ |
|
|
|
|
@PutMapping("/{id}") |
|
|
|
|
public ResponseEntity<StockDTO> updateStock( |
|
|
|
|
@PutMapping("/update") |
|
|
|
|
public ResponseEntity<Map<String, Object>> updateStock( |
|
|
|
|
Authentication authentication, |
|
|
|
|
@PathVariable("id") Long stockId, |
|
|
|
|
@Valid @RequestBody Stocks stockDetails) { |
|
|
|
|
Stocks updatedStock = stockService.updateStocks(authentication.getName(), stockId, stockDetails); |
|
|
|
|
return ResponseEntity.ok(StockDTO.fromEntity(updatedStock)); |
|
|
|
|
|
|
|
|
|
stockService.updateStocks(authentication.getName(), stockDetails); |
|
|
|
|
|
|
|
|
|
Map<String, Object> response = new HashMap<>(); |
|
|
|
|
response.put("result", true); |
|
|
|
|
return ResponseEntity.ok(response); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 指定されたIDの在庫を削除する |
|
|
|
|
* |
|
|
|
|
* @param authentication 認証情報 |
|
|
|
|
* @param taskId 削除する在庫のID |
|
|
|
|
* @return 空のレスポンス |
|
|
|
|
* @param stockInfo 削除する在庫情報(stockIdをキーに持つ) |
|
|
|
|
* @return レスポンス |
|
|
|
|
*/ |
|
|
|
|
@DeleteMapping("/{id}") |
|
|
|
|
public ResponseEntity<?> deleteStock( |
|
|
|
|
@DeleteMapping("/delete") |
|
|
|
|
public ResponseEntity<Map<String, Object>> deleteStock( |
|
|
|
|
Authentication authentication, |
|
|
|
|
@PathVariable("id") Long stockId) { |
|
|
|
|
stockService.deleteStock(authentication.getName(), stockId); |
|
|
|
|
return ResponseEntity.ok().build(); |
|
|
|
|
@Valid @RequestBody DeleteStockRequest request) { |
|
|
|
|
stockService.deleteStock(authentication.getName(), request.getStockId()); |
|
|
|
|
|
|
|
|
|
Map<String, Object> response = new HashMap<>(); |
|
|
|
|
response.put("result", true); |
|
|
|
|
return ResponseEntity.ok(response); |
|
|
|
|
} |
|
|
|
|
} |