Skip to content

Commit

Permalink
Merge pull request #674 from woowacourse-teams/develop
Browse files Browse the repository at this point in the history
Hang-Log Prod 2.0.0 Release
  • Loading branch information
dladncks1217 authored Oct 6, 2023
2 parents 9ec3d53 + 65e7226 commit 0fb8607
Show file tree
Hide file tree
Showing 186 changed files with 5,181 additions and 604 deletions.
74 changes: 73 additions & 1 deletion backend/src/docs/asciidoc/docs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ include::{snippets}/trip-controller-test/delete-trip/path-parameters.adoc[]
include::{snippets}/trip-controller-test/delete-trip/http-response.adoc[]


=== 공개 상태 수정 (PATCH /trips/:tripId/publish)

==== 요청
include::{snippets}/trip-controller-test/update-published-status/http-request.adoc[]
include::{snippets}/trip-controller-test/update-published-status/path-parameters.adoc[]
include::{snippets}/trip-controller-test/update-published-status/request-fields.adoc[]

==== 응답
include::{snippets}/trip-controller-test/update-published-status/http-response.adoc[]


== DayLog API
Expand Down Expand Up @@ -287,13 +296,14 @@ include::{snippets}/shared-trip-controller-test/get-shared-trip/path-parameters.

==== 응답
include::{snippets}/shared-trip-controller-test/get-shared-trip/http-response.adoc[]
include::{snippets}/shared-trip-controller-test/get-shared-trip/path-parameters.adoc[]
include::{snippets}/shared-trip-controller-test/get-shared-trip/response-fields.adoc[]

=== 공유 상태 수정 (PATCH /trips/:tripId/share)

==== 요청
include::{snippets}/shared-trip-controller-test/update-shared-status/http-request.adoc[]
include::{snippets}/shared-trip-controller-test/update-shared-status/path-parameters.adoc[]
include::{snippets}/shared-trip-controller-test/update-shared-status/request-fields.adoc[]

==== 응답
include::{snippets}/shared-trip-controller-test/update-shared-status/http-response.adoc[]
Expand All @@ -308,3 +318,65 @@ include::{snippets}/shared-trip-controller-test/get-shared-expenses/path-paramet
==== 응답
include::{snippets}/shared-trip-controller-test/get-shared-expenses/http-response.adoc[]
include::{snippets}/shared-trip-controller-test/get-shared-expenses/response-fields.adoc[]

== 커뮤니티 API

=== 공개 여행 페이지 조회 (GET /community/trips)

==== 요청
include::{snippets}/community-controller-test/get-trips-by-page/http-request.adoc[]
include::{snippets}/community-controller-test/get-trips-by-page/path-parameters.adoc[]

==== 응답
include::{snippets}/community-controller-test/get-trips-by-page/http-response.adoc[]
include::{snippets}/community-controller-test/get-trips-by-page/path-parameters.adoc[]

== 커뮤니티 API

=== 공개 여행 페이지 조회 (GET /community/trips)

==== 요청
include::{snippets}/community-controller-test/get-trips-by-page/http-request.adoc[]

==== 응답
include::{snippets}/community-controller-test/get-trips-by-page/http-response.adoc[]
include::{snippets}/community-controller-test/get-trips-by-page/response-fields.adoc[]

=== 추천 여행 목록 조회 (GET /community/recommends)

==== 요청
include::{snippets}/community-controller-test/get-recommend-trips/http-request.adoc[]

==== 응답
include::{snippets}/community-controller-test/get-recommend-trips/http-response.adoc[]
include::{snippets}/community-controller-test/get-recommend-trips/response-fields.adoc[]

=== 게시물 좋아요 반영 (POST /trips/:tripId/like)

==== 요청
include::{snippets}/like-controller-test/update-like-status/http-request.adoc[]
include::{snippets}/like-controller-test/update-like-status/path-parameters.adoc[]
include::{snippets}/like-controller-test/update-like-status/request-fields.adoc[]

==== 응답
include::{snippets}/like-controller-test/update-like-status/http-response.adoc[]

=== 공개 단일 여행 조회 (GET /community/trips/:tripId)

==== 요청
include::{snippets}/community-controller-test/get-trip/http-request.adoc[]
include::{snippets}/community-controller-test/get-trip/path-parameters.adoc[]

==== 응답
include::{snippets}/community-controller-test/get-trip/http-response.adoc[]
include::{snippets}/community-controller-test/get-trip/response-fields.adoc[]

=== 공개 단일 여행 경비 조회 (GET /community/trips/:tripId/expense)

==== 요청
include::{snippets}/community-controller-test/get-expenses/http-request.adoc[]
include::{snippets}/community-controller-test/get-expenses/path-parameters.adoc[]

==== 응답
include::{snippets}/community-controller-test/get-expenses/http-response.adoc[]
include::{snippets}/community-controller-test/get-expenses/response-fields.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RefreshTokenRepository extends JpaRepository<RefreshToken, Long> {
public interface RefreshTokenRepository extends JpaRepository<RefreshToken, String> {

Optional<RefreshToken> findByToken(final String token);

boolean existsByToken(final String token);

void deleteByMemberId(final Long memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public ResponseEntity<AccessTokenResponse> extendLogin(

@DeleteMapping("/logout")
@MemberOnly
public ResponseEntity<Void> logout(@Auth final Accessor accessor) {
authService.removeMemberRefreshToken(accessor.getMemberId());
public ResponseEntity<Void> logout(
@Auth final Accessor accessor,
@CookieValue("refresh-token") final String refreshToken) {
authService.removeRefreshToken(refreshToken);
return ResponseEntity.noContent().build();
}

Expand Down
10 changes: 6 additions & 4 deletions backend/src/main/java/hanglog/auth/service/AuthService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package hanglog.auth.service;

import static hanglog.global.exception.ExceptionCode.FAIL_TO_GENERATE_RANDOM_NICKNAME;
import static hanglog.global.exception.ExceptionCode.FAIL_TO_VALIDATE_TOKEN;
import static hanglog.global.exception.ExceptionCode.INVALID_REFRESH_TOKEN;

import hanglog.auth.domain.BearerAuthorizationExtractor;
import hanglog.auth.domain.JwtProvider;
import hanglog.auth.domain.MemberTokens;
Expand All @@ -16,8 +20,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static hanglog.global.exception.ExceptionCode.*;

@Service
@Transactional
@RequiredArgsConstructor
Expand Down Expand Up @@ -79,8 +81,8 @@ public String renewalAccessToken(final String refreshTokenRequest, final String
throw new AuthException(FAIL_TO_VALIDATE_TOKEN);
}

public void removeMemberRefreshToken(final Long memberId) {
refreshTokenRepository.deleteByMemberId(memberId);
public void removeRefreshToken(final String refreshToken) {
refreshTokenRepository.deleteById(refreshToken);
}

public void deleteAccount(final Long memberId) {
Expand Down
14 changes: 14 additions & 0 deletions backend/src/main/java/hanglog/community/domain/BaseTripInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hanglog.community.domain;

public class BaseTripInfo implements TripInfo {

@Override
public Long getLikeCount() {
return 0L;
}

@Override
public Boolean getIsLike() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package hanglog.trip.domain;
package hanglog.community.domain;

import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import hanglog.member.domain.Member;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -18,17 +15,20 @@
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
public class Like {
public class Likes {

@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;

@OneToOne(fetch = LAZY)
@JoinColumn(name = "trip_id", nullable = false)
private Trip trip;
@Column(nullable = false)
private Long tripId;

@OneToOne(fetch = LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;
@Column(nullable = false)
private Long memberId;

public Likes(final Long tripId, final Long memberId) {
this.tripId = tripId;
this.memberId = memberId;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package hanglog.trip.domain;
package hanglog.community.domain;

import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import hanglog.global.BaseEntity;
import hanglog.trip.domain.Trip;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -19,7 +20,7 @@
@Entity
@Getter
@AllArgsConstructor
@SQLDelete(sql = "UPDATE shared_trip SET status = 'DELETED' WHERE id = ?")
@SQLDelete(sql = "UPDATE published_trip SET status = 'DELETED' WHERE id = ?")
@NoArgsConstructor(access = PROTECTED)
@Where(clause = "status = 'USABLE'")
public class PublishedTrip extends BaseEntity {
Expand All @@ -31,4 +32,8 @@ public class PublishedTrip extends BaseEntity {
@OneToOne(fetch = LAZY)
@JoinColumn(name = "trip_id", nullable = false)
private Trip trip;

public PublishedTrip(final Trip trip) {
this(null, trip);
}
}
8 changes: 8 additions & 0 deletions backend/src/main/java/hanglog/community/domain/TripInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hanglog.community.domain;

public interface TripInfo {

Long getLikeCount();

Boolean getIsLike();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package hanglog.community.domain.recommendstrategy;

import static hanglog.community.domain.recommendstrategy.RecommendType.LIKE;

import hanglog.trip.domain.Trip;
import hanglog.trip.domain.repository.TripRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class LikesRecommendStrategy implements RecommendStrategy {

private static final String TITLE = "지금 인기있는 여행들이에요";

private final TripRepository tripRepository;

@Override
public List<Trip> recommend(final Pageable pageable) {
return tripRepository.findTripsOrderByLikesCount(pageable);
}

@Override
public boolean isType(final RecommendType recommendType) {
return LIKE.equals(recommendType);
}

@Override
public String getTitle() {
return TITLE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hanglog.community.domain.recommendstrategy;

import hanglog.global.exception.ExceptionCode;
import hanglog.global.exception.InvalidDomainException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class RecommendStrategies {

private final List<RecommendStrategy> recommendStrategies;

public RecommendStrategy mapByRecommendType(final RecommendType recommendType) {
return recommendStrategies.stream()
.filter(recommendStrategy -> recommendStrategy.isType(recommendType))
.findFirst()
.orElseThrow(() -> new InvalidDomainException(ExceptionCode.NOT_FOUND_RECOMMEND_TRIP_STRATEGY));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hanglog.community.domain.recommendstrategy;

import hanglog.trip.domain.Trip;
import java.util.List;
import org.springframework.data.domain.Pageable;

public interface RecommendStrategy {

List<Trip> recommend(Pageable pageable);

boolean isType(RecommendType recommendType);

String getTitle();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package hanglog.community.domain.recommendstrategy;

public enum RecommendType {
LIKE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package hanglog.community.domain.repository;

import hanglog.community.domain.Likes;
import hanglog.community.domain.TripInfo;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface LikeRepository extends JpaRepository<Likes, Long> {

boolean existsByMemberIdAndTripId(final Long memberId, final Long tripId);

void deleteByMemberIdAndTripId(final Long memberId, final Long tripId);

Long countLikesByTripId(final Long tripId);

@Query("""
SELECT l.tripId,
COUNT(l.memberId) AS like_count,
EXISTS(SELECT 1 FROM Likes l_1 WHERE l_1.memberId = :memberId AND l_1.tripId = l.tripId) AS is_like
FROM Likes l
WHERE l.tripId in :tripIds
GROUP BY l.tripId
""")
List<Object[]> countByMemberIdAndTripId(@Param("memberId") Long memberId, @Param("tripIds") List<Long> tripIds);

@Query("""
SELECT COUNT(l.memberId) AS like_count,
EXISTS(SELECT 1 FROM Likes l_1 WHERE l_1.memberId = :memberId AND l_1.tripId = l.tripId) AS is_like
FROM Likes l
WHERE l.tripId = :tripId
GROUP BY l.tripId
""")
Optional<TripInfo> countByMemberIdAndTripId(@Param("memberId") Long memberId, @Param("tripId") Long tripId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hanglog.community.domain.type;

public enum PublishedStatusType {

PUBLISHED,
UNPUBLISHED;

public static PublishedStatusType mappingType(final boolean isPublished) {
if (isPublished) {
return PUBLISHED;
}
return UNPUBLISHED;
}
}
Loading

0 comments on commit 0fb8607

Please sign in to comment.