From eb73d7ccdc4c65e0faa57476aacd118dfc248e0b Mon Sep 17 00:00:00 2001
From: Jack <jack.su@pollex.com.tw>
Date: 星期五, 17 十二月 2021 15:34:16 +0800
Subject: [PATCH] [ADD] 編輯顧問API [UPDATE] 調整取得顧問頭像API

---
 pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java |   46 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 9 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 19f5000..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,5 +1,7 @@
 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;
@@ -11,9 +13,12 @@
 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
@@ -27,6 +32,12 @@
     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")
@@ -71,15 +82,23 @@
     	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")
@@ -87,4 +106,13 @@
         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