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

v2.1.2 #421

Merged
merged 4 commits into from
Sep 28, 2024
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
package org.sopt.makers.crew.main.advertisement.dto;

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

import org.sopt.makers.crew.main.entity.advertisement.Advertisement;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

@Schema(name = "AdvertisementGetResponseDto", description = "κ΄‘κ³  ꡬ쒌 쑰회 응닡 Dto")
@Schema(name = "AdvertisementsGetResponseDto", description = "κ΄‘κ³  ꡬ쒌 쑰회 응닡 Dto")
public record AdvertisementsGetResponseDto(
@Schema(description = "κ΄‘κ³  ꡬ쒌 이미지 객체", example = "")
@Schema(description = "κ΄‘κ³  ꡬ쒌 이미지 리슀트", example = "")
@NotNull
List<AdvertisementGetDto> advertisements
) {
public static AdvertisementsGetResponseDto of(List<AdvertisementGetDto> advertisements) {
@Schema(name = "AdvertisementGetDto", description = "κ΄‘κ³  ꡬ쒌 이미지 Dto")
public record AdvertisementGetDto(

@Schema(description = "κ΄‘κ³  id", example = "3")
@NotNull
Integer advertisementId,

@Schema(description = "[Desktop] κ΄‘κ³  ꡬ쒌 이미지 url", example = "[pc 버전 url ν˜•μ‹]")
@NotNull
String desktopImageUrl,

@Schema(description = "[mobile] κ΄‘κ³  ꡬ쒌 이미지 url", example = "[mobile 버전 url ν˜•μ‹]")
@NotNull
String mobileImageUrl,

@Schema(description = "κ΄‘κ³  ꡬ쒌 링크", example = "https://www.naver.com")
@NotNull
String advertisementLink,

@Schema(description = "κ΄‘κ³  κ²Œμ‹œ μ‹œμž‘μΌ", example = "2024-07-31T00:00:00")
@NotNull
LocalDateTime advertisementStartDate
) {
public static AdvertisementGetDto of(Advertisement advertisement) {
return new AdvertisementGetDto(
advertisement.getId(),
advertisement.getAdvertisementDesktopImageUrl(),
advertisement.getAdvertisementMobileImageUrl(),
advertisement.getAdvertisementLink(),
advertisement.getAdvertisementStartDate()
);
}
}

public static AdvertisementsGetResponseDto of(List<AdvertisementGetDto> advertisements) {
return new AdvertisementsGetResponseDto(advertisements);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.sopt.makers.crew.main.advertisement.service;

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

import org.sopt.makers.crew.main.advertisement.dto.AdvertisementsGetResponseDto;
import org.sopt.makers.crew.main.advertisement.dto.AdvertisementGetDto;
import org.sopt.makers.crew.main.common.util.Time;
import org.sopt.makers.crew.main.advertisement.dto.AdvertisementsGetResponseDto.AdvertisementGetDto;
import org.sopt.makers.crew.main.global.util.Time;
import org.sopt.makers.crew.main.entity.advertisement.Advertisement;
import org.sopt.makers.crew.main.entity.advertisement.AdvertisementRepository;
import org.sopt.makers.crew.main.entity.advertisement.enums.AdvertisementCategory;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -17,21 +20,38 @@
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class AdvertisementService {
private final AdvertisementRepository advertisementRepository;

private final AdvertisementRepository advertisementRepository;
private final Time time;

public AdvertisementsGetResponseDto getAdvertisement(AdvertisementCategory advertisementCategory) {
List<Advertisement> advertisements = advertisementRepository.findTop6ByAdvertisementCategoryAndAdvertisementEndDateAfterAndAdvertisementStartDateBeforeOrderByPriority(
advertisementCategory, time.now(), time.now());
LocalDateTime now = time.now();

int maxItems = advertisementCategory.getMaxItems();
Pageable pageable = PageRequest.of(0, maxItems);

List<Advertisement> advertisements = advertisementRepository.findAdvertisementsByDateAndType(
advertisementCategory,
true,
now,
pageable);

if (advertisements.isEmpty()) {
return AdvertisementsGetResponseDto.of(null);
if (!advertisements.isEmpty()) {
return createResponseDto(advertisements);
}

List<AdvertisementGetDto> advertisementDtos = advertisements.stream().map(AdvertisementGetDto::of)
.toList();
advertisements = advertisementRepository.findAdvertisementsByCategory(
advertisementCategory,
false,
pageable);

return createResponseDto(advertisements);
}

private AdvertisementsGetResponseDto createResponseDto(List<Advertisement> advertisements) {
List<AdvertisementGetDto> advertisementDtos = advertisements.stream()
.map(AdvertisementGetDto::of)
.toList();
return AdvertisementsGetResponseDto.of(advertisementDtos);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.sopt.makers.crew.main.auth.v2.dto.request.AuthV2RequestDto;
import org.sopt.makers.crew.main.auth.v2.dto.response.AuthV2ResponseDto;
import org.sopt.makers.crew.main.common.jwt.JwtTokenProvider;
import org.sopt.makers.crew.main.global.jwt.JwtTokenProvider;
import org.sopt.makers.crew.main.entity.user.User;
import org.sopt.makers.crew.main.entity.user.UserRepository;
import org.sopt.makers.crew.main.external.playground.PlaygroundService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2ReportCommentResponseDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2SwitchCommentLikeResponseDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2UpdateCommentResponseDto;
import org.sopt.makers.crew.main.common.dto.TempResponseDto;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.sopt.makers.crew.main.comment.v2;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;

import java.security.Principal;
Expand All @@ -18,8 +17,7 @@
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2SwitchCommentLikeResponseDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2UpdateCommentResponseDto;
import org.sopt.makers.crew.main.comment.v2.service.CommentV2Service;
import org.sopt.makers.crew.main.common.dto.TempResponseDto;
import org.sopt.makers.crew.main.common.util.UserUtil;
import org.sopt.makers.crew.main.global.util.UserUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.makers.crew.main.comment.v2.dto.query;

import org.sopt.makers.crew.main.common.pagination.dto.PageOptionsDto;
import org.sopt.makers.crew.main.global.pagination.dto.PageOptionsDto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import org.sopt.makers.crew.main.common.pagination.dto.PageMetaDto;
import org.sopt.makers.crew.main.global.pagination.dto.PageMetaDto;

import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2ReportCommentResponseDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2SwitchCommentLikeResponseDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2UpdateCommentResponseDto;
import org.sopt.makers.crew.main.common.exception.BadRequestException;
import org.sopt.makers.crew.main.global.exception.BadRequestException;

public interface CommentV2Service {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2SwitchCommentLikeResponseDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.CommentV2UpdateCommentResponseDto;
import org.sopt.makers.crew.main.comment.v2.dto.response.ReplyDto;
import org.sopt.makers.crew.main.common.exception.BadRequestException;
import org.sopt.makers.crew.main.common.exception.ErrorStatus;
import org.sopt.makers.crew.main.common.exception.ForbiddenException;
import org.sopt.makers.crew.main.common.pagination.dto.PageMetaDto;
import org.sopt.makers.crew.main.common.pagination.dto.PageOptionsDto;
import org.sopt.makers.crew.main.common.util.MentionSecretStringRemover;
import org.sopt.makers.crew.main.common.util.Time;
import org.sopt.makers.crew.main.global.exception.BadRequestException;
import org.sopt.makers.crew.main.global.exception.ErrorStatus;
import org.sopt.makers.crew.main.global.exception.ForbiddenException;
import org.sopt.makers.crew.main.global.pagination.dto.PageMetaDto;
import org.sopt.makers.crew.main.global.pagination.dto.PageOptionsDto;
import org.sopt.makers.crew.main.global.util.MentionSecretStringRemover;
import org.sopt.makers.crew.main.global.util.Time;
import org.sopt.makers.crew.main.entity.comment.Comment;
import org.sopt.makers.crew.main.entity.comment.CommentRepository;
import org.sopt.makers.crew.main.entity.comment.Comments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.LocalDateTime;

import org.sopt.makers.crew.main.entity.advertisement.enums.AdvertisementCategory;
import org.sopt.makers.crew.main.entity.common.BaseTimeEntity;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.Entity;
Expand All @@ -23,9 +24,8 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
@Table(name = "advertisement")
public class Advertisement {
public class Advertisement extends BaseTimeEntity {
/**
* Primary Key
*/
Expand Down Expand Up @@ -55,16 +55,21 @@ public class Advertisement {
@NotNull
private LocalDateTime advertisementEndDate;

@NotNull
private boolean isSponsoredContent;

@Builder
private Advertisement(String advertisementDesktopImageUrl, String advertisementMobileImageUrl, String advertisementLink,
private Advertisement(String advertisementDesktopImageUrl, String advertisementMobileImageUrl,
String advertisementLink,
AdvertisementCategory advertisementCategory, Long priority, LocalDateTime advertisementStartDate,
LocalDateTime advertisementEndDate) {
LocalDateTime advertisementEndDate, boolean isSponsoredContent) {
this.advertisementDesktopImageUrl = advertisementDesktopImageUrl;
this.advertisementMobileImageUrl = advertisementMobileImageUrl;
this.advertisementLink = advertisementLink;
this.advertisementCategory = advertisementCategory;
this.priority = priority;
this.advertisementStartDate = advertisementStartDate;
this.advertisementEndDate = advertisementEndDate;
this.isSponsoredContent = isSponsoredContent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,31 @@
import java.util.List;

import org.sopt.makers.crew.main.entity.advertisement.enums.AdvertisementCategory;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface AdvertisementRepository extends JpaRepository<Advertisement, Integer> {
List<Advertisement> findTop6ByAdvertisementCategoryAndAdvertisementEndDateAfterAndAdvertisementStartDateBeforeOrderByPriority(
AdvertisementCategory advertisementCategory, LocalDateTime now1, LocalDateTime now2);
}

@Query("SELECT a FROM Advertisement a " +
"WHERE a.isSponsoredContent = :isSponsored " +
"AND a.advertisementCategory = :category " +
"AND a.advertisementStartDate <= :now " +
"AND a.advertisementEndDate >= :now " +
"ORDER BY a.priority ASC")
List<Advertisement> findAdvertisementsByDateAndType(
@Param("category") AdvertisementCategory category,
@Param("isSponsored") boolean isSponsored,
@Param("now") LocalDateTime now,
Pageable pageable);

@Query("SELECT a FROM Advertisement a " +
"WHERE a.isSponsoredContent = :isSponsored " +
"AND a.advertisementCategory = :category " +
"ORDER BY a.priority ASC")
List<Advertisement> findAdvertisementsByCategory(
@Param("category") AdvertisementCategory category,
@Param("isSponsored") boolean isSponsored,
Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package org.sopt.makers.crew.main.entity.advertisement.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum AdvertisementCategory {
POST, MEETING
POST(6),
MEETING(1);

private final int maxItems;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.sopt.makers.crew.main.entity.apply;

import static jakarta.persistence.GenerationType.IDENTITY;
import static org.sopt.makers.crew.main.common.exception.ErrorStatus.*;
import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
Expand All @@ -21,7 +21,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import org.sopt.makers.crew.main.common.exception.BadRequestException;
import org.sopt.makers.crew.main.entity.common.BaseTimeEntity;
import org.sopt.makers.crew.main.global.exception.BadRequestException;
import org.sopt.makers.crew.main.entity.apply.enums.ApplyStatusConverter;
import org.sopt.makers.crew.main.entity.apply.enums.ApplyTypeConverter;
import org.sopt.makers.crew.main.entity.apply.enums.EnApplyStatus;
Expand All @@ -34,9 +35,8 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
@Table(name = "apply")
public class Apply {
public class Apply extends BaseTimeEntity {

/**
* Primary Key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.sopt.makers.crew.main.entity.apply;

import static org.sopt.makers.crew.main.common.exception.ErrorStatus.NOT_FOUND_APPLY;
import static org.sopt.makers.crew.main.global.exception.ErrorStatus.NOT_FOUND_APPLY;

import java.util.List;
import java.util.Optional;
import org.sopt.makers.crew.main.common.exception.BadRequestException;

import org.sopt.makers.crew.main.global.exception.BadRequestException;
import org.sopt.makers.crew.main.entity.apply.enums.EnApplyStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.makers.crew.main.entity.apply;

import static org.sopt.makers.crew.main.common.constant.CrewConst.*;
import static org.sopt.makers.crew.main.global.constant.CrewConst.*;
import static org.sopt.makers.crew.main.entity.apply.QApply.apply;
import static org.sopt.makers.crew.main.entity.user.QUser.user;

Expand Down
Loading
Loading