Skip to content

Commit

Permalink
feat: always 관련 로직 적용, 이미지 업로드 안하면, 스파크 장소 이미지 리턴하도록 구현 (#74)
Browse files Browse the repository at this point in the history
* feat: Spark 엔티티에 채팅url 추가, 관련 api 적용 (#14)

* feat: 스파크 날짜가 이전이면 카운트 세지 않도록 변경 (#14)

* feat: 이미지 업로드 안하면, 스파크 장소 이미지 리턴하도록 구현 (#14)

* feat: always 관련 로직 적용 (#14)
  • Loading branch information
ympark99 authored Oct 17, 2023
1 parent c4ef3ae commit e4e83b6
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDateTime;

import com.onna.onnaback.domain.apply.domain.AcceptStatus;
import com.onna.onnaback.domain.spark.domain.Always;
import com.onna.onnaback.domain.spark.domain.CapacityType;
import com.onna.onnaback.domain.spark.domain.DurationHour;

Expand All @@ -17,6 +18,8 @@ public class ApplyDto {

private String placeName;

private Always always;

private LocalDateTime sparkDate;

private DurationHour durationHour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public List<ApplyDto> getList(Member applicant) {
for (MemberSparkMapping memberSparkMapping : memberSparkMappings) {
applyDtos.add(new ApplyDto(memberSparkMapping.getApplySpark().getSparkId(),
memberSparkMapping.getApplySpark().getPlace().getName(),
memberSparkMapping.getApplySpark().getAlways(),
memberSparkMapping.getApplySpark().getSparkDate(),
memberSparkMapping.getApplySpark().getDurationHour(),
memberSparkMapping.getApplySpark().getMemberCount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.onna.onnaback.domain.place.application.port.out.LoadPlacePort;
import com.onna.onnaback.domain.place.domain.Place;
import com.onna.onnaback.domain.place.domain.PlaceType;
import com.onna.onnaback.domain.spark.domain.Always;
import com.onna.onnaback.domain.spark.domain.DurationHour;
import com.onna.onnaback.domain.spark.domain.RecruitType;
import com.onna.onnaback.domain.spark.domain.SortType;
Expand Down Expand Up @@ -90,7 +91,7 @@ private Long calculateSparkCount(Place place, SparkType sparkType,

for (Spark spark : sparks) {
// 스파크 날짜가 이전이면 카운트 x
if (spark.getSparkDate().isBefore(LocalDateTime.now())) {
if (spark.getAlways() == Always.NOT_ALWAYS && spark.getSparkDate().isBefore(LocalDateTime.now())) {
sparkCnt--;
} else if (sparkType != null && spark.getType() != sparkType) {
sparkCnt--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.onna.onnaback.domain.spark.domain.CapacityType;
import com.onna.onnaback.domain.spark.domain.DurationHour;
import com.onna.onnaback.domain.spark.domain.SortType;
import com.onna.onnaback.domain.spark.domain.Spark;
import com.onna.onnaback.domain.spark.domain.SparkType;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -75,8 +76,10 @@ public ResponseEntity<SparkHostResponse> host(@AuthenticationPrincipal CustomUse
capacity, durationHour, hostDetail, chatUrl);

Member host = customUserDetails.getMember();
Spark spark = this.sparkUseCase.uploadSpark(host, hostDto);
return ResponseEntity.ok().body(
new SparkHostResponse(this.sparkUseCase.uploadSpark(host, hostDto).getSparkId())
new SparkHostResponse(spark.getSparkId(),
img == null ? spark.getPlace().getImg() : spark.getImg())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
public class SparkHostResponse {
Long sparkId;

public SparkHostResponse(Long sparkId) {
String img;

public SparkHostResponse(Long sparkId, String img) {
this.sparkId = sparkId;
this.img = img;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDateTime;

import com.onna.onnaback.domain.spark.domain.Always;
import com.onna.onnaback.domain.spark.domain.CapacityType;
import com.onna.onnaback.domain.spark.domain.DurationHour;
import com.onna.onnaback.domain.spark.domain.RecruitType;
Expand All @@ -26,6 +27,8 @@ public class SparkListDto {

SparkType sparkType;

Always always;

LocalDateTime sparkDate;

DurationHour durationHour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDateTime;
import java.util.List;

import com.onna.onnaback.domain.spark.domain.Always;
import com.onna.onnaback.domain.spark.domain.CapacityType;
import com.onna.onnaback.domain.spark.domain.DurationHour;
import com.onna.onnaback.domain.spark.domain.RecruitType;
Expand All @@ -27,6 +28,8 @@ public class SparkResponse {

SparkType sparkType;

Always always;

LocalDateTime sparkDate;

DurationHour durationHour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public List<SparkResponse> getSparkListByPlaceId(Long placeId) {
.title(spark.getTitle())
.durationHour(spark.getDurationHour())
.sparkType(spark.getType())
.always(spark.getAlways())
.sparkDate(spark.getSparkDate())
.capacity(spark.getCapacity())
.memberCount(spark.getMemberCount())
Expand Down Expand Up @@ -125,6 +126,7 @@ public List<SparkListDto> getList(Pageable pageable, SparkType sparkType,
spark.getPlace().getPlaceId(),
spark.getTitle(),
spark.getType(),
spark.getAlways(),
spark.getSparkDate(),
spark.getDurationHour(),
spark.getCapacity(),
Expand Down Expand Up @@ -192,6 +194,7 @@ public SparkResponse getSparkInfo(Long id) {
.title(spark.getTitle())
.img(spark.getImg())
.sparkType(spark.getType())
.always(spark.getAlways())
.sparkDate(spark.getSparkDate())
.description(spark.getDescription())
.price(spark.getPrice())
Expand Down Expand Up @@ -232,6 +235,7 @@ public List<SparkResponse> searchSpark(String value) {
return sparkRepository.findByTitleContaining(value).stream().map(
spark -> SparkResponse.builder()
.sparkId(spark.getSparkId())
.always(spark.getAlways())
.sparkDate(spark.getSparkDate())
.sparkType(spark.getType())
.memberCount(spark.getMemberCount())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
package com.onna.onnaback.domain.spark.adapter.out.persistence;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Optional;

import com.onna.onnaback.domain.member.domain.Member;
import com.onna.onnaback.domain.spark.adapter.in.web.response.SparkResponse;
import org.joda.time.LocalDate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.onna.onnaback.domain.place.domain.Place;
import com.onna.onnaback.domain.spark.domain.Spark;

public interface SparkRepository extends JpaRepository<Spark, Long>, JpaSpecificationExecutor<Spark> {
Optional<Spark> findBySparkId(Long sparkId);

@Query(value = "select s from Spark s where s.place.placeId = :placeId and s.sparkDate >= CURRENT_TIMESTAMP")
@Query(value = "select s from Spark s where s.place.placeId = :placeId and (s.always = 'ALWAYS' or s.sparkDate >= CURRENT_TIMESTAMP)")
List<Spark> findSparksByPlace(@Param("placeId") Long placeId);

List<Spark> findAllByHostMemberId(Long hostId);
Expand Down

0 comments on commit e4e83b6

Please sign in to comment.