Skip to content

Commit

Permalink
Merge pull request #69 from Team-KeepGoing/feature/student
Browse files Browse the repository at this point in the history
Feat :: Mapping Image By StudentId
  • Loading branch information
priverg authored Jul 10, 2024
2 parents fab7ab4 + d2a62da commit 829719c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -24,7 +25,7 @@ public BaseResponse findStudentName(@RequestBody StudentFindDto studentFindDto)
}

@Operation(summary = "학반번호를 통한 학생검색", description = "내용에 학반번호(2304)만 넣으면 학생정보가 나옵니다")
@PostMapping("/find-studentId")
@PostMapping("/find-student-id")
public BaseResponse findStudentNum(@RequestBody StudentFindDto studentFindDto) {
return studentService.findByStudentNum(studentFindDto);
}
Expand All @@ -47,4 +48,10 @@ public BaseResponse createManyUserByExcel(@RequestPart(value = "excel") Multipar
return studentService.createManyUserByExcel(file);
}

@Operation(summary = "학생 이미지 업로드하기", description = "이미지 url을 enter로 구분해서 json raw 파일로 보내면 번호에 맞게 매핑됩니다")
@PostMapping("/add-image")
public BaseResponse updateImages(@RequestBody List<String> imgUrls) {
return studentService.AddStudentImage(imgUrls);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import com.keepgoing.keepserver.domain.student.repository.dto.StudentFindDto;
import com.keepgoing.keepserver.domain.student.repository.dto.StudentRequestDto;
import com.keepgoing.keepserver.global.common.BaseResponse;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

public interface StudentService {
BaseResponse findByStudentName(StudentFindDto studentFindDto);
BaseResponse findByStudentNum(StudentFindDto studentFindDto);
BaseResponse editStudent(StudentRequestDto studentRequestDto,Long id);
BaseResponse createManyUserByExcel(MultipartFile multipartFile) throws IOException;
BaseResponse findAll();
BaseResponse AddStudentImage(List<String> imgUrls);
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ public BaseResponse findAll() {
return new BaseResponse(HttpStatus.OK, "전체 학생 정보", lst);
}

@Override
@Transactional
public BaseResponse AddStudentImage(List<String> imageUrls) {
for (String imageUrl : imageUrls) {
String studentNum = extractStudentIDFromUrl(imageUrl);
Student student = studentRepository.findStudentByStudentId(studentNum);
if (student != null) {
student.setImgUrl(imageUrl);
studentRepository.save(student);
}
}
return new BaseResponse(HttpStatus.OK,"이미지 연결 성공");
}

private String extractStudentIDFromUrl(String url) {
String fileName = url.substring(url.lastIndexOf('/') + 1);
fileName = fileName.replace(".jpeg", "");
fileName = fileName.replace(".jpg", "");
return fileName;
}


private List<Student> findStudentsByStudentName(String studentName) {
return studentRepository.findStudentsByStudentName(studentName);
}
Expand Down

0 comments on commit 829719c

Please sign in to comment.