Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#633 행사 추가 api 요청 명세 변경 #634

Merged
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
9 changes: 3 additions & 6 deletions backend/emm-sale/src/documentTest/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,10 @@ include::{snippets}/find-recruitment-post/response-fields.adoc[]

POST

[source]
----
/events?name=인프콘 2023&location=코엑스&informationUrl=https://~~~&startDateTime=2023:06:01:12:00:00&endDateTime=2023:09:01:12:00:00&applyStartDateTime=2023:05:01:12:00:00&applyEndDateTime=2023:06:01:12:00:00&tags=백엔드,안드로이드&imageUrl=https://image.url&type=CONFERENCE&eventMode=ON_OFFLINE&paymentType=FREE
----
.HTTP request
include::{snippets}/add-event/http-request.adoc[]
Copy link
Collaborator

Choose a reason for hiding this comment

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

제가 알기로는 request 스니펫이 이해하기 너무 어려워서 의도적으로 문자열로 하드코딩 해 둔 것으로 아는데 혹시 수정하신 이유가 있으신가요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

스니펫이 수정되기도 했고, 수정 후의 request 스니펫은 그대로 사용해도 이해하기 어렵지 않을거라 생각해서 수정해주었습니다!
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

multipart 로 adoc 만들면 엄청 지저분해지지 않아요??


.HTTP request 설명
include::{snippets}/add-event/request-parameters.adoc[]
include::{snippets}/add-event/request-parts.adoc[]

.HTTP response
Expand All @@ -298,7 +295,7 @@ include::{snippets}/add-event/response-fields.adoc[]
include::{snippets}/update-event/http-request.adoc[]

.HTTP request 설명
include::{snippets}/update-event/request-fields.adoc[]
include::{snippets}/update-event/request-parts.adoc[]

.HTTP response
include::{snippets}/update-event/http-response.adoc[]
Expand Down
408 changes: 252 additions & 156 deletions backend/emm-sale/src/documentTest/java/com/emmsale/EventApiTest.java

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions backend/emm-sale/src/main/java/com/emmsale/event/api/EventApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/events")
Expand All @@ -46,17 +48,19 @@ public ResponseEntity<List<EventResponse>> findEvents(
eventService.findEvents(category, LocalDate.now(), startDate, endDate, tags, statuses));
}

@PostMapping
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public EventDetailResponse addEvent(@Valid final EventDetailRequest request) {
return eventService.addEvent(request, LocalDate.now());
public EventDetailResponse addEvent(@RequestPart @Valid final EventDetailRequest request,
@RequestPart final List<MultipartFile> images) {
return eventService.addEvent(request, images, LocalDate.now());
}

@PutMapping("/{eventId}")
@PutMapping(path = "/{eventId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.OK)
public EventDetailResponse updateEvent(@PathVariable final Long eventId,
@RequestBody @Valid final EventDetailRequest request) {
return eventService.updateEvent(eventId, request, LocalDate.now());
@RequestPart @Valid final EventDetailRequest request,
@RequestPart final List<MultipartFile> images) {
return eventService.updateEvent(eventId, request, images, LocalDate.now());
}

@DeleteMapping("/{eventId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Service
@Transactional
Expand Down Expand Up @@ -178,13 +179,14 @@ private List<EventResponse> filterEventResponseByStatuses(
});
}

public EventDetailResponse addEvent(final EventDetailRequest request, final LocalDate today) {
public EventDetailResponse addEvent(final EventDetailRequest request,
final List<MultipartFile> images, final LocalDate today) {
final Event event = eventRepository.save(request.toEvent());
final List<Tag> tags = findAllPersistTagsOrElseThrow(request.getTags());
event.addAllEventTags(tags);

final List<String> imageUrls = imageCommandService
.saveImages(ImageType.EVENT, event.getId(), request.getImages())
.saveImages(ImageType.EVENT, event.getId(), images)
.stream()
.sorted(comparing(Image::getOrder))
.map(Image::getName)
Expand All @@ -196,7 +198,7 @@ public EventDetailResponse addEvent(final EventDetailRequest request, final Loca
}

public EventDetailResponse updateEvent(final Long eventId, final EventDetailRequest request,
final LocalDate today) {
final List<MultipartFile> images, final LocalDate today) {
final Event event = eventRepository.findById(eventId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

update에서는 images 파라미터가 안 사용 되는 것 같은데 파라미터로 넣으신 이유가 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

관리자 페이지(프론트)를 미리 완성시켜놓으려고 요청 포맷만 미리 수정해두었습니다...!
지금 생각해보니 이슈를 분리하고 했어야 했는데 혼동하게 한 것 같네요. 제 실수입니다🥲
새로 판 피쳐 브랜치에서는 해당 images 데이터를 사용하도록 구현해둔 상태입니다!

.orElseThrow(() -> new EventException(NOT_FOUND_EVENT));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.multipart.MultipartFile;

@RequiredArgsConstructor
@Getter
Expand Down Expand Up @@ -51,8 +50,6 @@ public class EventDetailRequest {
private final EventMode eventMode;
private final PaymentType paymentType;

private final List<MultipartFile> images;

private final String organization;

public Event toEvent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

public enum ImageType {
FEED(5),
EVENT(2);

EVENT(0);

private static final int NO_LIMIT_COUNT = 0;
private final int maxImageCount;

ImageType(final int maxImageCount) {
this.maxImageCount = maxImageCount;
}

public boolean isOverMaxImageCount(final int imageCount) {
if (maxImageCount == NO_LIMIT_COUNT) {
return false;
}
return imageCount > maxImageCount;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@
import org.springframework.data.repository.query.Param;

public interface InterestTagRepository extends JpaRepository<InterestTag, Long> {

List<InterestTag> findInterestTagsByMemberId(final Long memberId);


@Query("select it from InterestTag it "
+ "join fetch it.tag "
+ "where it.member.id = :memberId")
List<InterestTag> findInterestTagsByMemberId(@Param("memberId") final Long memberId);

boolean existsByTagIdIn(List<Long> tagIds);

@Query("select it from InterestTag it "
+ "where it.member = :member "
+ "and it.tag.id in :deleteTagId")
List<InterestTag> findAllByMemberAndTagIds(
@Param("member") final Member member,
@Param("deleteTagId") final List<Long> deleteTagId);

@Query("select it from InterestTag it join fetch it.tag where it.tag.id in :ids")
List<InterestTag> findInterestTagsByTagIdIn(@Param("ids") final List<Long> ids);

void deleteAllByMember(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,13 @@ void addEventTest() {
type,
eventMode,
paymentType,
mockMultipartFiles,
organization
);

doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class));

//when
final EventDetailResponse response = eventService.addEvent(request, now);
final EventDetailResponse response = eventService.addEvent(request, mockMultipartFiles, now);
final Event savedEvent = eventRepository.findById(response.getId()).get();

//then
Expand Down Expand Up @@ -589,15 +588,14 @@ void addEventWithStartDateTimeAfterBeforeDateTimeTest() {
type,
eventMode,
paymentType,
mockMultipartFiles,
organization
);

doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class));

//when & then
final EventException exception = assertThrowsExactly(EventException.class,
() -> eventService.addEvent(request, now));
() -> eventService.addEvent(request, mockMultipartFiles, now));

assertEquals(exception.exceptionType(), START_DATE_TIME_AFTER_END_DATE_TIME);
}
Expand Down Expand Up @@ -625,15 +623,14 @@ void addEventWithNotExistTagTest() {
type,
eventMode,
paymentType,
mockMultipartFiles,
organization
);

doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class));

//when & then
final EventException exception = assertThrowsExactly(EventException.class,
() -> eventService.addEvent(request, now));
() -> eventService.addEvent(request, mockMultipartFiles, now));

assertEquals(exception.exceptionType(), NOT_FOUND_TAG);
}
Expand Down Expand Up @@ -677,15 +674,15 @@ void updateEventTest() {
EventType.CONFERENCE,
eventMode,
paymentType,
mockMultipartFiles,
organization
);

final Event event = eventRepository.save(인프콘_2023());
final Long eventId = event.getId();

//when
final EventDetailResponse response = eventService.updateEvent(eventId, updateRequest, now);
final EventDetailResponse response = eventService.updateEvent(eventId, updateRequest,
mockMultipartFiles, now);
final Event updatedEvent = eventRepository.findById(eventId).get();

//then
Expand Down Expand Up @@ -723,13 +720,12 @@ void updateEventWithNotExistsEventTest() {
EventType.CONFERENCE,
eventMode,
paymentType,
mockMultipartFiles,
organization
);

//when & then
final EventException exception = assertThrowsExactly(EventException.class,
() -> eventService.updateEvent(notExistsEventId, updateRequest, now));
() -> eventService.updateEvent(notExistsEventId, updateRequest, mockMultipartFiles, now));

assertEquals(exception.exceptionType(), NOT_FOUND_EVENT);
}
Expand All @@ -754,7 +750,6 @@ void updateEventWithStartDateTimeAfterBeforeDateTimeTest() {
EventType.CONFERENCE,
eventMode,
paymentType,
mockMultipartFiles,
organization
);

Expand All @@ -763,7 +758,7 @@ void updateEventWithStartDateTimeAfterBeforeDateTimeTest() {

//when & then
final EventException exception = assertThrowsExactly(EventException.class,
() -> eventService.updateEvent(eventId, updateRequest, now));
() -> eventService.updateEvent(eventId, updateRequest, mockMultipartFiles, now));

assertEquals(exception.exceptionType(), START_DATE_TIME_AFTER_END_DATE_TIME);
}
Expand All @@ -789,7 +784,6 @@ void updateEventWithNotExistTagTest() {
EventType.CONFERENCE,
eventMode,
paymentType,
mockMultipartFiles,
organization
);

Expand All @@ -798,7 +792,7 @@ void updateEventWithNotExistTagTest() {

//when & then
final EventException exception = assertThrowsExactly(EventException.class,
() -> eventService.updateEvent(eventId, updateRequest, now));
() -> eventService.updateEvent(eventId, updateRequest, mockMultipartFiles, now));

assertEquals(exception.exceptionType(), NOT_FOUND_TAG);
}
Expand Down
Loading
Loading