From 22ff4ec80f1105b804f7b3e5cff960dae5d07652 Mon Sep 17 00:00:00 2001 From: Jack <jack.su@pollex.com.tw> Date: 星期二, 11 一月 2022 17:04:17 +0800 Subject: [PATCH] [UPDATE] 更新預約單狀態新增新的狀態 [UPDATE] 取消預約時一併更新預約單的狀態為cancel [REF] 針對發送email和簡訊當設定檔為開發環境時不會實際連線 --- pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java | 71 +++++++++++++++++++++++++++-------- 1 files changed, 55 insertions(+), 16 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java b/pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java index 0323979..d80947c 100644 --- a/pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java +++ b/pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java @@ -1,8 +1,11 @@ package com.pollex.pam.web.rest; +import com.pollex.pam.domain.Consultant; +import com.pollex.pam.security.SecurityUtils; import com.pollex.pam.service.ConsultantService; import com.pollex.pam.service.dto.*; import org.apache.commons.compress.utils.IOUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.http.HttpStatus; @@ -10,25 +13,31 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.List; @RestController @RequestMapping("/api/consultant") public class ConsultantResource { - private final ConsultantService consultantService; - - public ConsultantResource(ConsultantService consultantService) { - this.consultantService = consultantService; - } + @Autowired + ConsultantService consultantService; @GetMapping("/favorite") - public ResponseEntity<List<ConsultantDTO>> getMyConsultantList() { - List<ConsultantDTO> myConsultants = consultantService.getMyConsultantList(); + public ResponseEntity<List<CustomerFavoriteConsultantDTO>> getMyConsultantList() { + List<CustomerFavoriteConsultantDTO> myConsultants = consultantService.getMyConsultantList(); return new ResponseEntity<>(myConsultants, HttpStatus.OK); + } + + @PostMapping("/favorite/view") + public ResponseEntity<Void> recordMyConsultantListView() { + consultantService.recordMyConsultantListView(); + return ResponseEntity.noContent().build(); } @GetMapping("/recommend") @@ -42,6 +51,13 @@ consultantService.addConsultantToCustomList(param); return new ResponseEntity<>(HttpStatus.ACCEPTED); } + + @DeleteMapping("/favorite/{agentNo}") + public ResponseEntity<Void> removeConsultantFromCustomList(@PathVariable String agentNo) { + consultantService.removeConsultantFromCustomList(agentNo); + return new ResponseEntity<>(HttpStatus.OK); + } + @PostMapping("/strictQuery") public ResponseEntity<List<ConsultantDTO>> strictQueryConsultant(@RequestBody StrictQueryConsultantParam param) { @@ -66,14 +82,37 @@ return consultantService.getMyAppointment(); } - @GetMapping(value = "/avatar/{fileName}", produces = MediaType.IMAGE_JPEG_VALUE) - public ResponseEntity<byte[]> getAvatarImage(@PathVariable String fileName) throws IOException { - try { - Resource resource = new ClassPathResource("static/consultant/" + fileName); - InputStream in = resource.getInputStream(); - return new ResponseEntity<>(IOUtils.toByteArray(in), HttpStatus.OK); - } catch (FileNotFoundException e) { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } + @GetMapping(value = "/avatar/{agentNo}", produces = MediaType.IMAGE_JPEG_VALUE) + public ResponseEntity<byte[]> getAvatarImage(@PathVariable String agentNo) throws IOException { +// try { +// Resource resource = new ClassPathResource("static/consultant/" + fileName); +// InputStream in = resource.getInputStream(); +// return new ResponseEntity<>(IOUtils.toByteArray(in), HttpStatus.OK); +// } catch (FileNotFoundException e) { +// return new ResponseEntity<>(HttpStatus.NOT_FOUND); +// } + InputStream in = consultantService.getAvatarImage(agentNo); + if(in!=null) { + return new ResponseEntity<>(IOUtils.toByteArray(in), HttpStatus.OK); + }else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + + } + + @PostMapping("/record/allAppointmentsView") + public ResponseEntity<Void> recordAllAppointmentsView() { + consultantService.recordAllAppointmentsView(); + return ResponseEntity.noContent().build(); + } + + @PostMapping("/edit") + public ResponseEntity<Consultant> editConsultant(@RequestBody ConsultantEditDTO editDTO) { + if(!editDTO.getAgentNo().equals(SecurityUtils.getAgentNo())) { + throw new IllegalAccessError(); + } + Consultant editResult = consultantService.editConsultant(editDTO); + return new ResponseEntity<>(editResult, HttpStatus.OK); } } -- Gitblit v1.8.0