Skip to content

Commit

Permalink
BE: [feat] 크루 프로필 등록 추가 CSID-DGU#83
Browse files Browse the repository at this point in the history
  • Loading branch information
Seoyoung2222 committed Nov 27, 2024
1 parent b582057 commit f2ad46f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public class CrewController {
private final CrewCommandService crewCommandService;

@PostMapping("/create")
public ResponseEntity<Integer> createCrew(@RequestParam String title, @RequestPart MultipartFile certificationImage) {
public ResponseEntity<Integer> createCrew(@RequestParam String title, @RequestPart MultipartFile certificationImage,@RequestPart MultipartFile profileImage) {
CrewCreateCommandDto crewCreateCommandDto = CrewCreateCommandDto.builder()
.title(title)
.certificationImage(certificationImage)
.profileImage(profileImage)
.build();

Integer crewPasscode = crewCommandService.createCrew(crewCreateCommandDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class CrewCreateCommandDto {
private String title;
private MultipartFile certificationImage;
private MultipartFile profileImage;

public void validate() {
if (title==null || title.isEmpty()) {
Expand All @@ -18,5 +19,8 @@ public void validate() {
if (certificationImage == null || certificationImage.isEmpty()) {
throw new IllegalArgumentException("인증 사진을 입력해주세요.");
}
if (profileImage == null || profileImage.isEmpty()) {
throw new IllegalArgumentException("프로필 사진을 입력해주세요.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Crew extends BaseEntity {
@OneToMany(mappedBy = "crew")
private List<CrewPost> crewPosts = new ArrayList<>();

@OneToOne(mappedBy = "crew")
@OneToOne(mappedBy = "crew", cascade = CascadeType.PERSIST, orphanRemoval = true)
private CrewProfileImage images = new CrewProfileImage();

public void setImages(CrewProfileImage profileImage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package RunningMachines.R2R.domain.crew.common.repository;

import RunningMachines.R2R.domain.crew.common.entity.CrewProfileImage;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CrewProfileImageRepository extends JpaRepository<CrewProfileImage, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import RunningMachines.R2R.domain.crew.common.dto.CrewCreateCommandDto;
import RunningMachines.R2R.domain.crew.common.entity.Crew;
import RunningMachines.R2R.domain.crew.common.entity.CrewProfileImage;
import RunningMachines.R2R.domain.crew.common.entity.CrewRole;
import RunningMachines.R2R.domain.crew.common.entity.CrewUser;
import RunningMachines.R2R.domain.crew.common.repository.CrewRepository;
import RunningMachines.R2R.domain.crew.common.repository.CrewUserRepository;
import RunningMachines.R2R.domain.user.entity.User;
import RunningMachines.R2R.domain.user.service.AuthCommandService;
import RunningMachines.R2R.global.s3.S3Provider;
import RunningMachines.R2R.global.s3.S3RequestDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -31,11 +33,24 @@ public int createCrew(CrewCreateCommandDto crewCreateCommandDto) {
User currentUser = authCommandService.getCurrentUser();
int passcode = generateRandomPasscode();

String profileImageUrl = s3Provider.uploadFile(crewCreateCommandDto.getProfileImage(),
S3RequestDto.builder()
.userId(currentUser.getId())
.dirName("크루_프로필")
.build()
);

// Crew 생성
Crew crew = Crew.builder()
.title(crewCreateCommandDto.getTitle())
.passcode(passcode)
.build();

CrewProfileImage profileImage = CrewProfileImage.builder()
.imageUrl(profileImageUrl)
.build();

crew.setImages(profileImage);
crewRepository.save(crew);

// 생성자 크루원 가입
Expand Down

0 comments on commit f2ad46f

Please sign in to comment.