Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
implementation "org.springframework.boot:spring-boot-starter-mail"

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.13'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,48 +202,6 @@ public InputStream openObject(String key) {
return obj.getObjectContent(); // 반드시 호출 측에서 close
}

// public ResponseEntity<Resource> viewImage(String fileId,String type) throws IOException {
// FileTargetType fileType = FileTargetType.fromType(type);
// FileAttachment file = fileAttachmentRepository.findByFileIdAndFiletype(fileId,fileType)
// .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "파일을 찾을 수 없습니다."));
// Path filePath = Paths.get(file.getPath()).resolve(file.getStoredName());
// Resource resource = new UrlResource(filePath.toUri());
// if (!resource.exists() || !resource.isReadable()) {
// throw new ResponseStatusException(HttpStatus.NOT_FOUND, "파일을 읽을 수 없습니다.");
// }
//
// String contentType = Files.probeContentType(filePath);
// if (contentType == null) {
// contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE;
// }
// return ResponseEntity.ok()
// .contentType(MediaType.parseMediaType(contentType))
// .body(resource);
// }
//
// public ResponseEntity<Resource> viewPdf(String fileId, String type) throws IOException {
// FileTargetType fileType = FileTargetType.fromType(type);
// FileAttachment file = fileAttachmentRepository.findByFileIdAndFiletype(fileId, fileType)
// .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "파일을 찾을 수 없습니다."));
//
// Path filePath = Paths.get(file.getPath()).resolve(file.getStoredName());
// Resource resource = new UrlResource(filePath.toUri());
//
// if (!resource.exists() || !resource.isReadable()) {
// throw new ResponseStatusException(HttpStatus.NOT_FOUND, "파일을 읽을 수 없습니다.");
// }
//
// String contentType = Files.probeContentType(filePath);
// if (contentType == null) {
// contentType = MediaType.APPLICATION_PDF_VALUE; // 기본값을 PDF로 설정
// }
//
// return ResponseEntity.ok()
// .contentType(MediaType.parseMediaType(contentType))
// .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getFilename() + "\"")
// .body(resource);
// }

@Transactional
public void deleteFile(FileAttachment fileAttachment){
try{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.cooperation.project.cooperationcenter.domain.member.dto.UpdatePasswordDto;
import com.cooperation.project.cooperationcenter.domain.member.service.MemberService;
import com.cooperation.project.cooperationcenter.domain.member.service.ProfileService;
import com.cooperation.project.cooperationcenter.global.exception.BaseException;
import com.cooperation.project.cooperationcenter.global.exception.BaseResponse;
import com.cooperation.project.cooperationcenter.global.exception.codes.ErrorCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -23,34 +25,65 @@ public class MemberProfileRestController {

@PatchMapping("/member")
public BaseResponse<?> updateMemberInfo(@RequestBody Profile.MemberDto request, @AuthenticationPrincipal MemberDetails memberDetails){

log.info("request:{}",request.toString());
profileService.updateMember(request,memberDetails);
return BaseResponse.onSuccess("success");
try{
profileService.updateMember(request,memberDetails);
return BaseResponse.onSuccess("success");
}catch (BaseException e){
log.warn(e.getCode().toString());
return BaseResponse.onFailure(e.getCode(),null);
}catch (Exception e){
log.warn(e.getMessage());
return BaseResponse.onFailure("ERROR",e.getMessage().toString(),false);
}
}

@PatchMapping("/agency")
public BaseResponse<?> updateAgencyInfo(@RequestBody Profile.MemberDto request, @AuthenticationPrincipal MemberDetails memberDetails){
log.info("request:{}",request.toString());
profileService.updateAgency(request,memberDetails);
return BaseResponse.onSuccess("success");
try{
profileService.updateAgency(request,memberDetails);
return BaseResponse.onSuccess("success");
}catch (BaseException e){
log.warn(e.getCode().toString());
return BaseResponse.onFailure(e.getCode(),null);
}catch (Exception e){
log.warn(e.getMessage());
return BaseResponse.onFailure("ERROR",e.getMessage().toString(),false);
}
}

@PatchMapping("/businessCert")
public BaseResponse<?> updateBusinessCertificate(
@RequestPart(name = "businessCertificate", required = false) MultipartFile file
, @AuthenticationPrincipal MemberDetails memberDetails
){
profileService.updateBussinessCert(file,memberDetails);
return BaseResponse.onSuccess("success");
try{
profileService.updateBussinessCert(file,memberDetails);
return BaseResponse.onSuccess("success");
}catch (BaseException e){
log.warn(e.getCode().toString());
return BaseResponse.onFailure(e.getCode(),null);
}catch (Exception e){
log.warn(e.getMessage());
return BaseResponse.onFailure("ERROR",e.getMessage().toString(),false);
}
}

@PatchMapping("/agencyPicture")
public BaseResponse<?> updateAgencyPicture(
@RequestPart(name = "agencyPicture", required = false) MultipartFile file
, @AuthenticationPrincipal MemberDetails memberDetails
){
profileService.updateAgencyPicture(file,memberDetails);
return BaseResponse.onSuccess("success");
try{
profileService.updateAgencyPicture(file,memberDetails);
return BaseResponse.onSuccess("success");
}catch (BaseException e){
log.warn(e.getCode().toString());
return BaseResponse.onFailure(e.getCode(),null);
}catch (Exception e){
log.warn(e.getMessage());
return BaseResponse.onFailure("ERROR",e.getMessage().toString(),false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.cooperation.project.cooperationcenter.domain.member.dto.MemberRequest;
import com.cooperation.project.cooperationcenter.domain.member.dto.UpdatePasswordDto;
import com.cooperation.project.cooperationcenter.domain.member.service.MemberService;
import com.cooperation.project.cooperationcenter.global.exception.BaseException;
import com.cooperation.project.cooperationcenter.global.exception.BaseResponse;
import com.cooperation.project.cooperationcenter.global.exception.codes.ErrorCode;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -36,30 +37,52 @@ public BaseResponse<?> signup(
try{
memberService.signup(data,agencyPicture,businessCertificate);
return BaseResponse.onSuccess("success");
}catch (BaseException e){
return BaseResponse.onFailure(e.getCode(),null);
}catch (Exception e){
log.warn(e.getMessage());
return BaseResponse.onFailure(ErrorCode.BAD_REQUEST,null);
return BaseResponse.onFailure("ERROR",e.getMessage().toString(),false);
}
}

@GetMapping("/check-id")
public BaseResponse<?> checkDuplicateId(@RequestParam String username) {
boolean isDuplicate = memberService.isUsernameTaken(username);
log.info("response:{}",isDuplicate);
return BaseResponse.onSuccess(isDuplicate);
try{
return BaseResponse.onSuccess(memberService.isUsernameTaken(username));
}catch (BaseException e){
return BaseResponse.onFailure(e.getCode(),false);
}catch (Exception e){
log.warn(e.getMessage());
return BaseResponse.onFailure("ERROR",e.getMessage().toString(),false);
}
}

@PostMapping("/login")
public BaseResponse<?> login(@RequestBody MemberRequest.LoginDto requestDto, HttpServletResponse response,HttpServletRequest request){
try{
memberService.login(requestDto,response,request);
log.info("loginSuccess");
return BaseResponse.onSuccess("success");
}catch (BaseException e){
return BaseResponse.onFailure(e.getCode(),false);
}catch (Exception e){
log.warn(e.getMessage());
return BaseResponse.onFailure("ERROR",e.getMessage().toString(),false);
}

}

@PostMapping("/logout")
public BaseResponse<?> userLogout(HttpServletRequest request ,HttpServletResponse response){
memberService.logout(request,response);
return BaseResponse.onSuccess("log out success");
try {
memberService.logout(request, response);
return BaseResponse.onSuccess("log out success");
}catch (BaseException e){
return BaseResponse.onFailure(e.getCode(),false);
}catch (Exception e){
log.warn(e.getMessage());
return BaseResponse.onFailure("ERROR",e.getMessage().toString(),false);
}
}

@PostMapping("/refresh")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,8 @@ public Member getMember(String email){
}

public boolean isUsernameTaken(String username){
try{
log.info("username:{}",username);
return memberRepository.existsMemberByEmail(username);
}catch (Exception e){
log.warn(e.getMessage());
return false;
}
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,8 @@ public class ProfileService {
private final FileService fileService;

public Member getMember(String email){
try {
return memberRepository.findMemberByEmail(email)
.orElseThrow(() -> new BaseException(ErrorCode.MEMBER_NOT_FOUND));
} catch (BaseException e){
log.warn("멤버 조회 실패: {}", e.getMessage());
return null;
} catch (Exception e){
log.error("알 수 없는 에러 발생: {}", e.getMessage(), e);
return null;
}
return memberRepository.findMemberByEmail(email)
.orElseThrow(() -> new BaseException(ErrorCode.MEMBER_NOT_FOUND));
}

public Profile.ProfileDto getProfileDto(MemberDetails memberDetails, Pageable pageable){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ public interface SchoolPostRepository extends JpaRepository<SchoolPost,Long> {
void incrementViewCount(@Param("postId") Long postId);

@Query("""
SELECT p FROM SchoolPost p
WHERE p.schoolBoard.id = :boardId
ORDER BY
CASE WHEN p.type = com.cooperation.project.cooperationcenter.domain.school.dto.PostType.NOTICE THEN 0 ELSE 2 END,
p.createdAt DESC
""")
Page<SchoolPost> findPostsByBoardOrderByNoticeFirst(@Param("boardId") Long boardId, Pageable pageable);
SELECT p FROM SchoolPost p
WHERE p.schoolBoard.id = :boardId
AND p.status = com.cooperation.project.cooperationcenter.domain.school.dto.PostStatus.PUBLISHED
ORDER BY
CASE WHEN p.type = com.cooperation.project.cooperationcenter.domain.school.dto.PostType.NOTICE THEN 0 ELSE 2 END,
p.createdAt DESC
""")
Page<SchoolPost> findPostsByBoardOrderByNoticeFirst(
@Param("boardId") Long boardId,
Pageable pageable
);


}
Loading