Skip to content

Commit

Permalink
Merge pull request #31 from Likelion-Inner-Join/fix/signupFix
Browse files Browse the repository at this point in the history
Fix: 동아리 카테고리 long으로 변경
  • Loading branch information
BlueRedOrange authored Dec 21, 2024
2 parents a4fe623 + 2008365 commit c02b761
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum ErrorCode {
EMAIL_FORMAT_INVALID(false, HttpStatus.BAD_REQUEST.value(), "이메일 형식이 올바르지 않습니다."),
INVALID_UNIV_NAME(false, HttpStatus.BAD_REQUEST.value(), "유효하지 않은 학교 이름입니다."),
MISMATCHED_EMAIL_DOMAIN(false, HttpStatus.BAD_REQUEST.value(), "작성한 학교의 이메일 도메인 주소가 아닙니다."),

DUPLICATE_LOGIN_ID(false, HttpStatus.BAD_REQUEST.value(), "이미 존재하는 아이디입니다."),
DUPLICATE_EMAIL(false,HttpStatus.BAD_REQUEST.value(), "이미 존재하는 이메일입니다."),
//error
UNIV_CERT_API_ERROR(false, HttpStatus.INTERNAL_SERVER_ERROR.value(), "학교 인증 API 호출 중 오류가 발생했습니다."),
INTERNAL_SERVER_ERROR(false,HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부에서 문제가 발생했습니다."),
Expand All @@ -35,7 +36,6 @@ public enum ErrorCode {
JSON_CONVERT_ERROR(false, HttpStatus.INTERNAL_SERVER_ERROR.value(), "JSON 변환중 오류가 발생하였습니다."),
CLUB_NOT_FOUND(false, 404, "동아리를 찾을 수 없습니다."),
FORM_NOT_FOUND(false, 404, "지원폼을 찾을 수 없습니다."),
DUPLICATE_LOGIN_ID(false, HttpStatus.BAD_REQUEST.value(), "이미 존재하는 아이디입니다."),
ALREADY_APPLIED(false, HttpStatus.BAD_REQUEST.value(), "이미 지원했습니다.");


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.likelion.innerjoin.user.controller;

import com.likelion.innerjoin.common.exception.ErrorCode;
import com.likelion.innerjoin.common.response.CommonResponse;
import com.likelion.innerjoin.user.model.dto.request.ClubSignUpRequestDto;
import com.likelion.innerjoin.user.model.dto.response.ClubCategoryResponseDto;
Expand All @@ -13,7 +14,6 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

Expand Down Expand Up @@ -50,11 +50,10 @@ public CommonResponse<ClubResponseDto> getClubInfo(@PathVariable Long clubId, Ht

@Operation(summary = "동아리 회원가입 API", description = "동아리 회원가입")
@PostMapping("/signup")
public ResponseEntity<CommonResponse<String>> signupClub(
@RequestPart("data") ClubSignUpRequestDto clubSignUpRequestDto,
@RequestPart(value = "image", required = false) MultipartFile image) {
clubService.signupClub(clubSignUpRequestDto, image);
public ResponseEntity<CommonResponse<String>> signupClub(@RequestBody ClubSignUpRequestDto clubSignUpRequestDto) {
clubService.signupClub(clubSignUpRequestDto);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new CommonResponse<>("회원가입이 완료되었습니다."));
.body(new CommonResponse<>(ErrorCode.CREATED, "회원가입이 완료되었습니다."));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.likelion.innerjoin.user.exception;

public class SignUpEmailException extends RuntimeException {
public SignUpEmailException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package com.likelion.innerjoin.user.exception;

import com.likelion.innerjoin.common.response.CommonResponse;
import com.likelion.innerjoin.common.exception.ErrorCode;
import com.likelion.innerjoin.common.response.CommonResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class SignUpExceptionHandler {

/**
* SignUpIDException 처리
*
* @param ex SignUpIDException
* @return ResponseEntity<CommonResponse<Object>>
*/
@ExceptionHandler(SignUpIDException.class)
public ResponseEntity<CommonResponse<Object>> handleSignUpIDException(SignUpIDException ex) {
CommonResponse<Object> response = new CommonResponse<>(ErrorCode.DUPLICATE_LOGIN_ID, ex.getMessage());
return ResponseEntity.badRequest().body(response);
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(new CommonResponse<>(ErrorCode.DUPLICATE_LOGIN_ID, null)); // ErrorCode의 메시지를 설정
}

@ExceptionHandler(EmailValidationException.class)
public ResponseEntity<CommonResponse<Object>> handleSignUpEmailException(SignUpEmailException ex) {
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(new CommonResponse<>(ErrorCode.EMAIL_FORMAT_INVALID, null)); // ErrorCode의 메시지를 설정
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public class ClubSignUpRequestDto {
private String password; // 비밀번호
private String email; // 이메일
private String school; // 학교
private String category; // 카테고리 리스트 (JSON 문자열로 받음)
private Long category;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ClubResponseDto {
private String id;
private String name;
private String school;
private String categoryId;
private Long categoryId;
private String email;
private String imageUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class Club extends DataEntity implements User {
@Column(name = "login_id", unique = true, nullable = false)
private String loginId;

@Column(name = "cate_list")
private String categoryList;
// @Column(name = "cate_list")
private Long category;

@OneToMany(mappedBy = "club", orphanRemoval = true, cascade = CascadeType.ALL)
private List<Post> postList;
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/com/likelion/innerjoin/user/service/ClubService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.likelion.innerjoin.user.service;

import com.likelion.innerjoin.common.exception.ErrorCode;
import com.likelion.innerjoin.common.service.BlobService;
import com.likelion.innerjoin.post.exception.ImageProcessingException;
import com.likelion.innerjoin.post.exception.UnauthorizedException;
Expand Down Expand Up @@ -105,31 +106,31 @@ private ClubResponseDto toClubResponseDto(Club club) {
.school(club.getSchool())
.email(club.getEmail())
.imageUrl(club.getImageUrl())
.categoryId(club.getCategoryList())
.categoryId(club.getCategory())
.build();
}

private final BlobService blobService;

public void signupClub(ClubSignUpRequestDto requestDto, MultipartFile image) {
public void signupClub(ClubSignUpRequestDto requestDto) {
// 아이디 중복 체크
if (clubRepository.findByLoginId(requestDto.getLoginId()).isPresent()) {
throw new SignUpIDException("이미 존재하는 아이디입니다.");
throw new SignUpIDException(ErrorCode.DUPLICATE_LOGIN_ID.getMessage());
}
// 이메일 중복 체크
if (clubRepository.findByEmail(requestDto.getEmail()).isPresent()) {
throw new EmailValidationException("이미 존재하는 이메일입니다.");
throw new EmailValidationException(ErrorCode.DUPLICATE_EMAIL.getMessage());
}

// 이미지 처리
String imageUrl = null;
if (image != null) {
try {
imageUrl = blobService.storeFile(image.getOriginalFilename(), image.getInputStream(), image.getSize());
} catch (IOException e) {
throw new RuntimeException("이미지 업로드 중 오류가 발생했습니다: " + e.getMessage());
}
}
// // 이미지 처리
// String imageUrl = null;
// if (image != null) {
// try {
// imageUrl = blobService.storeFile(image.getOriginalFilename(), image.getInputStream(), image.getSize());
// } catch (IOException e) {
// throw new RuntimeException("이미지 업로드 중 오류가 발생했습니다: " + e.getMessage());
// }
// }

// Club 엔티티 생성 및 저장
Club club = Club.builder()
Expand All @@ -138,8 +139,8 @@ public void signupClub(ClubSignUpRequestDto requestDto, MultipartFile image) {
.password(requestDto.getPassword())
.email(requestDto.getEmail())
.school(requestDto.getSchool())
.categoryList(requestDto.getCategory())
.imageUrl(imageUrl)
.category(requestDto.getCategory())
//.imageUrl(imageUrl)
.build();

clubRepository.save(club);
Expand Down

0 comments on commit c02b761

Please sign in to comment.