Skip to content

Commit

Permalink
merge: 머지 컨플릭트 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjerry committed Aug 1, 2023
2 parents 6f57953 + 7754fc5 commit bd53b87
Show file tree
Hide file tree
Showing 47 changed files with 5,002 additions and 3,730 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/backend-dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ jobs:
- name: 백엔드 메인으로 checkout
uses: actions/checkout@v3

- name: firebase key 생성
run: |
echo "${{ secrets.FIREBASE_KEY }}" > firebase-kerdy.json
- name: firebase key 이동
run: |
cp firebase-kerdy.json src/main/resources
- name: JDK 11로 설정
uses: actions/setup-java@v3
with:
Expand Down Expand Up @@ -70,7 +78,7 @@ jobs:

- name: 권한부여
run: chmod +x /home/ubuntu/backend/build/emm-sale-*.jar

- name: 배포하기
run: /home/ubuntu/backend/build/deploy.sh

Expand Down
3 changes: 3 additions & 0 deletions backend/emm-sale/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ dependencies {

// jwt
implementation 'io.jsonwebtoken:jjwt:0.9.1'

// firebase
implementation 'com.google.firebase:firebase-admin:9.2.0'
}

tasks.named('test') {
Expand Down
50 changes: 50 additions & 0 deletions backend/emm-sale/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ include::{snippets}/update-open-profile-url/http-request.adoc[]
.HTTP response
include::{snippets}/update-open-profile-url/http-response.adoc[]

=== `PUT`: 사용자의 한줄 자기소개 업데이트

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

.HTTP request
include::{snippets}/update-description/http-request.adoc[]

.HTTP response
include::{snippets}/update-description/http-response.adoc[]

=== `GET`: 특정 사용자의 프로필 정보 조회

.HTTP request
Expand Down Expand Up @@ -139,6 +150,45 @@ include::{snippets}/find-participants/http-response.adoc[]
.HTTP response 설명
include::{snippets}/find-participants/response-fields.adoc[]

=== `POST` : 이벤트 생성

.HTTP request
include::{snippets}/add-event/http-request.adoc[]

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

.HTTP response
include::{snippets}/add-event/http-response.adoc[]

.HTTP response 설명
include::{snippets}/add-event/response-fields.adoc[]

=== `PUT` : 이벤트 업데이트

.HTTP request
include::{snippets}/update-event/http-request.adoc[]

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

.HTTP response
include::{snippets}/update-event/http-response.adoc[]

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

=== `PUT` : 이벤트 삭제

.HTTP request
include::{snippets}/delete-event/http-request.adoc[]

.HTTP response
include::{snippets}/delete-event/http-response.adoc[]

.HTTP response 설명
include::{snippets}/delete-event/response-fields.adoc[]

== Comment

=== `GET` : 댓글 모두 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

import com.emmsale.base.BaseException;
import com.emmsale.base.BaseExceptionType;
import java.time.format.DateTimeParseException;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

Expand All @@ -18,6 +23,24 @@ public ResponseEntity<ExceptionResponse> handleException(final BaseException e)
return new ResponseEntity<>(ExceptionResponse.from(e), type.httpStatus());
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ExceptionResponse> handleValidationException(
final MethodArgumentNotValidException e) {
final String message = e.getBindingResult().getAllErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.joining("\n"));
log.warn("[WARN] MESSAGE: {}", message);
return new ResponseEntity<>(new ExceptionResponse(message), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(DateTimeParseException.class)
public ResponseEntity<ExceptionResponse> handleDateTimeParseException(
final DateTimeParseException e) {
final String message = "DateTime 입력 형식이 올바르지 않습니다.";
log.warn("[WARN] MESSAGE: " + message);
return new ResponseEntity<>(new ExceptionResponse(message), HttpStatus.BAD_REQUEST);
}

static class ExceptionResponse {

private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.emmsale.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
26 changes: 26 additions & 0 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 @@ -4,21 +4,27 @@
import static java.net.URI.create;

import com.emmsale.event.application.EventService;
import com.emmsale.event.application.dto.EventDetailRequest;
import com.emmsale.event.application.dto.EventDetailResponse;
import com.emmsale.event.application.dto.EventParticipateRequest;
import com.emmsale.event.application.dto.EventResponse;
import com.emmsale.event.application.dto.ParticipantResponse;
import com.emmsale.member.domain.Member;
import java.time.LocalDate;
import java.util.List;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
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.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -62,4 +68,24 @@ public ResponseEntity<List<EventResponse>> findEvents(@RequestParam final int ye
@RequestParam(required = false) final String status) {
return ResponseEntity.ok(eventService.findEvents(LocalDate.now(), year, month, tag, status));
}

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public EventDetailResponse addEvent(
@RequestBody @Valid final EventDetailRequest request) {
return eventService.addEvent(request);
}

@PutMapping("/{event-id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public EventDetailResponse updateEvent(@PathVariable(name = "event-id") final Long eventId,
@RequestBody @Valid final EventDetailRequest request) {
return eventService.updateEvent(eventId, request);
}

@DeleteMapping("/{event-id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public EventDetailResponse deleteEvent(@PathVariable(name = "event-id") final Long eventId) {
return eventService.deleteEvent(eventId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toUnmodifiableList;

import com.emmsale.event.application.dto.EventDetailRequest;
import com.emmsale.event.application.dto.EventDetailResponse;
import com.emmsale.event.application.dto.EventResponse;
import com.emmsale.event.application.dto.ParticipantResponse;
Expand All @@ -22,10 +23,12 @@
import com.emmsale.event.exception.EventException;
import com.emmsale.event.exception.EventExceptionType;
import com.emmsale.member.domain.Member;
import com.emmsale.tag.application.dto.TagRequest;
import com.emmsale.tag.domain.Tag;
import com.emmsale.tag.domain.TagRepository;
import com.emmsale.tag.exception.TagException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -46,6 +49,12 @@ public class EventService {
private final EventTagRepository eventTagRepository;
private final TagRepository tagRepository;

private static void validateMemberNotAllowed(final Long memberId, final Member member) {
if (member.isNotMe(memberId)) {
throw new EventException(EventExceptionType.FORBIDDEN_PARTICIPATE_EVENT);
}
}

@Transactional(readOnly = true)
public EventDetailResponse findEvent(final Long id) {
final Event event = eventRepository.findById(id)
Expand All @@ -63,22 +72,15 @@ public Long participate(final Long eventId, final Long memberId, final Member me
return participant.getId();
}

private static void validateMemberNotAllowed(final Long memberId, final Member member) {
if (member.isNotMe(memberId)) {
throw new EventException(EventExceptionType.FORBIDDEN_PARTICIPATE_EVENT);
}
}

@Transactional(readOnly = true)
public List<EventResponse> findEvents(final LocalDate nowDate, final int year, final int month,
final String tagName, final String statusName) {
validateYearAndMonth(year, month);
List<Event> events = filterEventsByTag(tagName);
final List<Event> events = filterEventsByTag(tagName);

final EnumMap<EventStatus, List<Event>> sortAndGroupByStatus
final EnumMap<EventStatus, List<Event>> eventsForEventStatus
= groupByEventStatus(nowDate, events, year, month);

return filterEventResponsesByStatus(statusName, sortAndGroupByStatus);
return filterEventResponsesByStatus(statusName, eventsForEventStatus);
}

@Transactional(readOnly = true)
Expand All @@ -102,7 +104,7 @@ private void validateYearAndMonth(final int year, final int month) {

private List<Event> filterEventsByTag(final String tagName) {
if (isExistTagName(tagName)) {
Tag tag = tagRepository.findByName(tagName)
final Tag tag = tagRepository.findByName(tagName)
.orElseThrow(() -> new TagException(NOT_FOUND_TAG));

return eventTagRepository.findEventTagsByTag(tag)
Expand Down Expand Up @@ -132,31 +134,87 @@ private EnumMap<EventStatus, List<Event>> groupByEventStatus(final LocalDate now

private boolean isOverlapToMonth(final int year, final int month,
final LocalDate eventStart, final LocalDate eventEnd) {
LocalDate monthStart = LocalDate.of(year, month, 1);
LocalDate monthEnd = LocalDate.of(year, month, monthStart.lengthOfMonth());
final LocalDate monthStart = LocalDate.of(year, month, 1);
final LocalDate monthEnd = LocalDate.of(year, month, monthStart.lengthOfMonth());

return (isBeforeOrEquals(eventStart, monthEnd) && isBeforeOrEquals(monthStart, eventEnd))
|| (isBeforeOrEquals(monthStart, eventStart) && isBeforeOrEquals(eventStart, monthEnd))
|| (isBeforeOrEquals(monthStart, eventEnd) && isBeforeOrEquals(eventEnd, monthEnd));
}

private boolean isBeforeOrEquals(LocalDate criteria, LocalDate comparison) {
private boolean isBeforeOrEquals(final LocalDate criteria, final LocalDate comparison) {
return criteria.isBefore(comparison) || criteria.isEqual(comparison);
}

private List<EventResponse> filterEventResponsesByStatus(final String statusName,
final EnumMap<EventStatus, List<Event>> sortAndGroupByEventStatus) {
final EnumMap<EventStatus, List<Event>> eventsForEventStatus) {
if (isExistStatusName(statusName)) {
EventStatus status = EventStatus.from(statusName);
return EventResponse.makeEventResponsesByStatus(status,
sortAndGroupByEventStatus.get(status));
List<Event> filteredEvents = eventsForEventStatus.get(status);
if (cannotFoundKeyStatus(filteredEvents)) {
return List.of();
}
return EventResponse.makeEventResponsesByStatus(status, filteredEvents);
}
return EventResponse.mergeEventResponses(sortAndGroupByEventStatus);
return EventResponse.mergeEventResponses(eventsForEventStatus);
}

private boolean cannotFoundKeyStatus(final List<Event> filteredEvents) {
return filteredEvents == null;
}

private boolean isExistStatusName(final String statusName) {
return statusName != null;
}

public EventDetailResponse addEvent(final EventDetailRequest request) {
final Event event = saveNewEvent(request);

final List<Tag> tags = findAllPersistTagsOrElseThrow(request.getTags());

event.addAllEventTags(tags);

return EventDetailResponse.from(event);
}

public EventDetailResponse updateEvent(final Long eventId, final EventDetailRequest request) {
final Event event = eventRepository.findById(eventId)
.orElseThrow(() -> new EventException(NOT_FOUND_EVENT));

final List<Tag> tags = findAllPersistTagsOrElseThrow(request.getTags());

eventTagRepository.deleteAllByEventId(eventId);

final Event updatedEvent = event.updateEventContent(request.getName(), request.getLocation(),
request.getStartDateTime(), request.getEndDateTime(), request.getInformationUrl(), tags);

return EventDetailResponse.from(updatedEvent);
}

public EventDetailResponse deleteEvent(final Long eventId) {
final Event event = eventRepository.findById(eventId)
.orElseThrow(() -> new EventException(NOT_FOUND_EVENT));

eventRepository.deleteById(eventId);

return EventDetailResponse.from(event);
}

private List<Tag> findAllPersistTagsOrElseThrow(final List<TagRequest> tags) {
if (tags == null || tags.isEmpty()) {
return new ArrayList<>();
}

return tags.stream()
.map(tag -> tagRepository.findByName(tag.getName())
.orElseThrow(() -> new EventException(EventExceptionType.NOT_FOUND_TAG)))
.collect(toList());
}

private Event saveNewEvent(final EventDetailRequest request) {
final Event event = new Event(request.getName(), request.getLocation(),
request.getStartDateTime(), request.getEndDateTime(), request.getInformationUrl());

return eventRepository.save(event);
}
}
Loading

0 comments on commit bd53b87

Please sign in to comment.