Skip to content

Commit

Permalink
merge: Feature/#633 행사 추가 api 요청 명세 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
amaran-th authored Sep 25, 2023
2 parents 45f1afe + 7d16992 commit 4634d17
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 231 deletions.
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[]

.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)
.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

0 comments on commit 4634d17

Please sign in to comment.