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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/accompanies/{accompanyId}/comments")
@Tag(name = "동행 후기 CRUD")
@Tag(name = "동행 후기", description = "동행 후기 글 CRUD api")
public class AccompanyCommentController {

private final AccompanyCommentService accompanyCommentService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.arom.with_travel.domain.accompanies.dto.response.AccompanyBriefResponse;
import com.arom.with_travel.domain.accompanies.dto.response.AccompanyDetailsResponse;
import com.arom.with_travel.domain.accompanies.dto.response.CursorSliceResponse;
import com.arom.with_travel.domain.accompanies.model.City;
import com.arom.with_travel.domain.accompanies.model.Continent;
import com.arom.with_travel.domain.accompanies.model.Country;
import com.arom.with_travel.domain.accompanies.service.AccompanyApplyService;
import com.arom.with_travel.domain.accompanies.service.AccompanyService;
Expand All @@ -15,21 +13,14 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/accompanies")
@Tag(name = "동행 모집 글 CRUD 및 부가 기능")
@Tag(name = "동행 모집 글", description = "동행 모집 글 CRUD api")
public class AccompanyController {

private final AccompanyService accompanyService;
Expand Down Expand Up @@ -70,5 +61,4 @@ public CursorSliceResponse<AccompanyBriefResponse> showAccompaniesBrief(
@RequestParam(defaultValue = "10") int size){
return accompanyService.showAccompaniesBrief(country, size, lastId);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.arom.with_travel.domain.accompanies.dto.request;

import com.arom.with_travel.domain.accompanies.model.*;
import com.arom.with_travel.domain.image.dto.ImageRequest;
import com.arom.with_travel.global.annotation.Enum;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.FutureOrPresent;
Expand All @@ -14,30 +15,31 @@

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;

@Getter
@NoArgsConstructor
public class AccompanyPostRequest {

@Enum(target = Continent.class, message = "대륙을 입력해주세요")
@Enum(target = Continent.class, message = "대륙을 입력해주세요(한글)")
private Continent continent;
@Enum(target = Country.class, message = "국가를 입력해주세요")
@Enum(target = Country.class, message = "국가를 입력해주세요(한글)")
private Country country;
@Enum(target = City.class, message = "도시를 입력해주세요")
@Enum(target = City.class, message = "도시를 입력해주세요(한글)")
private City city;
@Enum(target = AccompanyType.class, message = "동행 종류를 선택해주세요")
private AccompanyType accompanyType;

@NotEmpty private String destination;

@NotNull(message = "startDate는 필수입니다.")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) // ex) 2025-08-01
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) // ex) 2025-08-01
@JsonFormat(shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd")
private LocalDate startDate;

@NotNull(message = "startTime은 필수입니다.")
@DateTimeFormat(pattern = "HH:mm") // ex) 09:30
@DateTimeFormat(pattern = "HH:mm") // ex) 09:30
@JsonFormat(shape = JsonFormat.Shape.STRING,
pattern = "HH:mm")
private LocalTime startTime;
Expand All @@ -58,4 +60,5 @@ public class AccompanyPostRequest {
@NotEmpty private String title;
@NotEmpty private String description;
@Min(1) private int maxParticipants;
private List<ImageRequest> images;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@
import com.arom.with_travel.domain.accompanies.dto.response.AccompanyBriefResponse;
import com.arom.with_travel.domain.accompanies.dto.response.CursorSliceResponse;
import com.arom.with_travel.domain.accompanies.model.Accompany;
import com.arom.with_travel.domain.accompanies.model.AccompanyApply;
import com.arom.with_travel.domain.accompanies.dto.request.AccompanyPostRequest;
import com.arom.with_travel.domain.accompanies.dto.response.AccompanyDetailsResponse;
import com.arom.with_travel.domain.accompanies.model.Country;
import com.arom.with_travel.domain.accompanies.repository.accompany.AccompanyRepository;
import com.arom.with_travel.domain.accompanies.repository.accompany.AccompanyApplyRepository;
import com.arom.with_travel.domain.image.Image;
import com.arom.with_travel.domain.image.ImageType;
import com.arom.with_travel.domain.image.repository.ImageRepository;
import com.arom.with_travel.domain.likes.Likes;
import com.arom.with_travel.domain.likes.repository.LikesRepository;
import com.arom.with_travel.domain.member.Member;
import com.arom.with_travel.domain.member.dto.MemberProfileRequestDto;
import com.arom.with_travel.domain.member.repository.MemberRepository;
import com.arom.with_travel.global.exception.BaseException;
import com.arom.with_travel.global.exception.error.ErrorCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand All @@ -36,12 +33,18 @@ public class AccompanyService {
private final AccompanyRepository accompanyRepository;
private final MemberRepository memberRepository;
private final LikesRepository likesRepository;
private final ImageRepository imageRepository;

@Transactional
public String createAccompany(AccompanyPostRequest request, String oauthId) {
Member member = loadMemberOrThrow(oauthId);
Accompany accompany = Accompany.from(request);
accompany.post(member);
List<Image> images = request.getImages()
.stream()
.map(imageReq -> Image.fromAccompany(imageReq.getImageName(), imageReq.getImageUrl(), accompany, ImageType.ACCOMPANY))
.toList();
imageRepository.saveAll(images);
accompanyRepository.save(accompany);
return "등록 되었습니다";
}
Expand Down Expand Up @@ -71,7 +74,9 @@ public AccompanyDetailsResponse showAccompanyDetails(Long accompanyId){
@Transactional(readOnly = true)
public CursorSliceResponse<AccompanyBriefResponse> showAccompaniesBrief(Country country, int size, Long lastId){
Pageable pageable = PageRequest.of(0, size, Sort.by(Sort.Direction.DESC, "createdAt"));
Slice<AccompanyBriefResponse> dtoSlice = accompanyRepository.findByCountry(country, lastId, pageable).map(AccompanyBriefResponse::from);
Slice<AccompanyBriefResponse> dtoSlice = accompanyRepository
.findByCountry(country, lastId, pageable)
.map(AccompanyBriefResponse::from);
return CursorSliceResponse.of(dtoSlice);
}

Expand All @@ -88,10 +93,6 @@ private Accompany loadAccompanyOrThrow(Long accompanyId){
private Optional<Likes> loadLikes(Accompany accompany, Member member) {
return likesRepository.findByAccompanyAndMember(accompany, member);
}

private long countLikes(Accompany accompany){
return likesRepository.countByAccompanyId(accompany.getId());
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Operation(
summary = "동행 목록 간단 조회",
summary = "동행 목록 간단 조회, 동행 첫 화면에 사용됨",
description = """
동행 목록 첫 페이지는 어느 국가를 기반으로
국가(country) 필터와 커서(lastId) 기반으로
Expand All @@ -31,7 +31,7 @@
name = "country",
in = ParameterIn.QUERY,
required = false,
description = "국가 코드 (예: KOREA, JAPAN)",
description = "국가 (예: 일본)",
example = "KOREA"
)
@Parameter(
Expand All @@ -46,7 +46,7 @@
in = ParameterIn.QUERY,
required = false,
description = "한 번에 가져올 데이터 개수",
schema = @Schema(defaultValue = "10", minimum = "1", maximum = "50")
schema = @Schema(defaultValue = "10")
)
@ApiResponses(value = {
@ApiResponse(
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/com/arom/with_travel/domain/image/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLDelete(sql = "UPDATE image SET is_deleted = true, deleted_at = now() where id = ?")
@SQLRestriction("is_deleted is FALSE")
public class Image extends BaseEntity {

@Id
Expand All @@ -26,6 +24,8 @@ public class Image extends BaseEntity {
@NotNull private String imageName;
@NotNull private String imageUrl;

@Enumerated(EnumType.STRING)
private ImageType imageType;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "community_id")
Expand All @@ -38,4 +38,40 @@ public class Image extends BaseEntity {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

private Image(String imageName, String imageUrl, Accompany accompany, ImageType imageType) {
this.imageName = imageName;
this.imageUrl = imageUrl;
this.accompany = accompany;
this.imageType = imageType;
this.accompany.getImages().add(this);
}

private Image(String imageName, String imageUrl, Member member, ImageType imageType){
this.imageName = imageName;
this.imageUrl = imageUrl;
this.member = member;
this.imageType = imageType;
this.member.uploadImage(this);
}

private Image(String imageName, String imageUrl, Community community, ImageType imageType){
this.imageName = imageName;
this.imageUrl = imageUrl;
this.imageType = imageType;
this.community = community;
this.community.getImages().add(this);
}

public static Image fromAccompany(String imageName, String imageUrl, Accompany accompany, ImageType imageType) {
return new Image(imageName, imageUrl, accompany, imageType);
}

public static Image fromMember(String imageName, String imageUrl, Member member, ImageType imageType) {
return new Image(imageName, imageUrl, member, imageType);
}

public static Image fromCommunity(String imageName, String imageUrl, Community community) {
return new Image(imageName, imageUrl, community, ImageType.COMMUNITY);
Comment on lines +74 to +75
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fromCommunity factory method hardcodes ImageType.COMMUNITY instead of accepting it as a parameter like the other factory methods. This is inconsistent with fromAccompany and fromMember methods which accept ImageType as a parameter.

Suggested change
public static Image fromCommunity(String imageName, String imageUrl, Community community) {
return new Image(imageName, imageUrl, community, ImageType.COMMUNITY);
public static Image fromCommunity(String imageName, String imageUrl, Community community, ImageType imageType) {
return new Image(imageName, imageUrl, community, imageType);

Copilot uses AI. Check for mistakes.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.arom.with_travel.domain.image;

public enum ImageType {
ACCOMPANY, COMMUNITY, MEMBER_PROFILE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.arom.with_travel.domain.image;

import com.arom.with_travel.domain.image.dto.UploadedImageResponse;
import com.arom.with_travel.global.exception.response.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.MediaType;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Operation(
summary = "이미지 업로드",
description = """
Multipart/form-data 요청으로 여러 이미지를 S3에 업로드합니다.
저장 디렉터리(dir) 파라미터는 S3 버킷 내의 하위 경로를 의미하며,
정상 처리되면 업로드된 각 이미지의 URL과 원본 파일명을 담은 리스트를 반환합니다.
""")
@Parameters({
@Parameter(
name = "files",
description = "업로드할 이미지 파일들 (복수 가능)",
in = ParameterIn.DEFAULT,
required = true,
content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE,
array = @ArraySchema(schema = @Schema(type = "string", format = "binary")))
),
@Parameter(
name = "dir",
description = """
S3 저장 디렉터리
디렉토리 종류 :
accompany-img(동행글),
member-profile-img(프로필 이미지),
community-img(커뮤니티 글)
""",
in = ParameterIn.QUERY,
required = true,
schema = @Schema(type = "string")
)
})
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "업로드 성공",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
array = @ArraySchema(schema = @Schema(implementation = UploadedImageResponse.class)))
),
@ApiResponse(
responseCode = "400",
description = "요청 형식 오류(파일 누락 등)",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ErrorResponse.class)))
})
public @interface PostUploadImages {
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
package com.arom.with_travel.domain.image.controller;

import com.arom.with_travel.domain.image.PostUploadImages;
import com.arom.with_travel.domain.image.dto.UploadedImageResponse;
import com.arom.with_travel.global.oauth2.dto.CustomOAuth2User;
import com.arom.with_travel.global.s3.service.S3Service;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

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

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/image")
@RequestMapping("/api/v1/images")
@Tag(name = "이미지", description = "이미지 업로드 api")
public class ImageController {

private final S3Service s3Service;

@PostUploadImages
@PostMapping("/upload")
public String upload(
@RequestParam("file") MultipartFile file,
@RequestParam("dir") String directory) throws IOException {
log.info("Uploading file {}", file.getOriginalFilename());
return s3Service.uploadFile(file, directory);
public List<UploadedImageResponse> uploadAccompanyImages(@AuthenticationPrincipal CustomOAuth2User user,
@RequestParam("files") List<MultipartFile> files,
@RequestParam("dir") String directory) throws IOException {
return s3Service.uploadFiles(files, directory);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.arom.with_travel.domain.image.dto;

import lombok.Getter;

@Getter
public class ImageRequest {
private String imageName;
private String imageUrl;
}
Loading