Skip to content

Commit

Permalink
Merge pull request CSID-DGU#108 from CSID-DGU/backend/feature/crew
Browse files Browse the repository at this point in the history
BE: [feat] 크루 프로필 이미지 추가 CSID-DGU#83
  • Loading branch information
Seoyoung2222 authored Nov 27, 2024
2 parents b728ebd + f2ad46f commit 266ce75
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
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 @@ -29,4 +29,12 @@ public class Crew extends BaseEntity {

@OneToMany(mappedBy = "crew")
private List<CrewPost> crewPosts = new ArrayList<>();

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

public void setImages(CrewProfileImage profileImage) {
this.images = profileImage;
profileImage.setCrew(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package RunningMachines.R2R.domain.crew.common.entity;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class CrewProfileImage {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

@OneToOne
@JoinColumn(name = "crew_id", nullable = false)
private Crew crew;

private String imageUrl;

public void setCrew(Crew crew) {
this.crew = crew;
}
}
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 266ce75

Please sign in to comment.