Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/image-upload-notify-seperation
Browse files Browse the repository at this point in the history
  • Loading branch information
dradnats1012 committed Dec 7, 2024
2 parents d8b9964 + d874940 commit ca4c6de
Show file tree
Hide file tree
Showing 48 changed files with 805 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import in.koreatech.koin.admin.abtest.dto.request.AbtestAssignRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestCloseRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestRequest;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAccessHistoryResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAssignResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestDevicesResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestResponse;
Expand Down Expand Up @@ -179,6 +180,20 @@ ResponseEntity<Void> assignAbtestVariableByAdmin(
@RequestBody @Valid AbtestAdminAssignRequest abtestAdminAssignRequest
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true)))
}
)
@Operation(summary = "(NORMAL) AB테스트 토큰(access_history_id) 발급")
@PostMapping("/assign/token")
ResponseEntity<AbtestAccessHistoryResponse> issueAccessHistoryId(
@UserAgent UserAgentInfo userAgentInfo,
@UserId Integer userId
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import in.koreatech.koin.admin.abtest.dto.request.AbtestAssignRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestCloseRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestRequest;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAccessHistoryResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAssignResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestDevicesResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestResponse;
Expand Down Expand Up @@ -125,6 +126,15 @@ public ResponseEntity<Void> assignAbtestVariableByAdmin(
return ResponseEntity.ok().build();
}

@PostMapping("/assign/token")
public ResponseEntity<AbtestAccessHistoryResponse> issueAccessHistoryId(
@UserAgent UserAgentInfo userAgentInfo,
@UserId Integer userId
) {
AbtestAccessHistoryResponse response = abtestService.issueAccessHistoryId(userAgentInfo, userId);
return ResponseEntity.ok(response);
}

@PostMapping("/assign")
public ResponseEntity<AbtestAssignResponse> assignOrGetAbtestVariable(
@RequestHeader(value = "access_history_id", required = false) Integer accessHistoryId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package in.koreatech.koin.admin.abtest.dto.response;

import in.koreatech.koin.admin.abtest.model.AccessHistory;
import io.swagger.v3.oas.annotations.media.Schema;

public record AbtestAccessHistoryResponse(
@Schema(description = "기기 식별자")
Integer accessHistoryId
) {

public static AbtestAccessHistoryResponse from(AccessHistory accessHistory) {
return new AbtestAccessHistoryResponse(accessHistory.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import in.koreatech.koin.admin.abtest.model.AccessHistory;
import in.koreatech.koin.admin.abtest.model.Device;
import io.swagger.v3.oas.annotations.media.Schema;

Expand Down Expand Up @@ -37,11 +38,12 @@ private record InnerDeviceResponse(
) {

public static InnerDeviceResponse from(Device device) {
AccessHistory accessHistory = device.getAccessHistory();
return new InnerDeviceResponse(
device.getId(),
device.getType(),
device.getModel(),
device.getAccessHistory().getLastAccessedAt().toLocalDate());
accessHistory != null ? accessHistory.getLastAccessedAt().toLocalDate() : null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ private AccessHistory(
this.lastAccessedAt = lastAccessedAt;
}

public static AccessHistory create() {
return AccessHistory.builder()
.lastAccessedAt(LocalDateTime.now())
.build();
}

public void connectDevice(Device device) {
this.device = device;
device.setAccessHistory(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import in.koreatech.koin.admin.abtest.dto.request.AbtestAssignRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestCloseRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestRequest;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAccessHistoryResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAssignResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestDevicesResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestResponse;
Expand Down Expand Up @@ -139,8 +140,7 @@ public void closeAbtest(Integer abtestId, AbtestCloseRequest request) {

@Transactional
public AbtestAssignResponse assignOrGetVariable(Integer accessHistoryId, UserAgentInfo userAgentInfo,
Integer userId,
AbtestAssignRequest request) {
Integer userId, AbtestAssignRequest request) {
Abtest abtest = abtestRepository.getByTitle(request.title());
AccessHistory accessHistory = findOrCreateAccessHistory(accessHistoryId);
Optional<AbtestVariable> winnerResponse = returnWinnerIfClosed(abtest);
Expand Down Expand Up @@ -312,31 +312,42 @@ private static Optional<AbtestVariable> returnWinnerIfClosed(Abtest abtest) {

public AccessHistory findOrCreateAccessHistory(Integer id) {
if (id == null) {
return accessHistoryRepository.save(AccessHistory.builder().build());
return accessHistoryRepository.save(AccessHistory.create());
}
return accessHistoryRepository.getById(id);
}

@Transactional
public AbtestAccessHistoryResponse issueAccessHistoryId(UserAgentInfo userAgentInfo, Integer userId) {
AccessHistory accessHistory = accessHistoryRepository.save(AccessHistory.create());
if (userId != null) {
createDeviceIfNotExists(userId, userAgentInfo, accessHistory, null);
}
return AbtestAccessHistoryResponse.from(accessHistory);
}

private void createDeviceIfNotExists(Integer userId, UserAgentInfo userAgentInfo,
AccessHistory accessHistory, Abtest abtest) {
userRepository.getById(userId);
if (accessHistory.getDevice() == null) {
Device device = deviceRepository.save(
User user = userRepository.getById(userId);
Device device = accessHistory.getDevice();
if (device == null) {
device = deviceRepository.save(
Device.builder()
.user(userRepository.getById(userId))
.user(user)
.model(userAgentInfo.getModel())
.type(userAgentInfo.getType())
.build()
);
accessHistory.connectDevice(device);
}
Device device = accessHistory.getDevice();
if (device.getModel() == null || device.getType() == null) {
device.setModelInfo(userAgentInfo.getModel(), userAgentInfo.getType());
}
if (!Objects.equals(device.getUser().getId(), userId)) {
device.changeUser(userRepository.getById(userId));
removeBeforeUserCache(accessHistory, abtest);
device.changeUser(user);
if (abtest != null) {
removeBeforeUserCache(accessHistory, abtest);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoryResponse;
import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoriesResponse;
import in.koreatech.koin.admin.benefit.dto.AdminBenefitShopsResponse;
import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryRequest;
import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryResponse;
Expand Down Expand Up @@ -44,7 +44,7 @@ public interface AdminBenefitApi {
)
@Operation(summary = "상점 혜택 카테고리를 모두 조회한다.")
@GetMapping("/categories")
ResponseEntity<AdminBenefitCategoryResponse> getBenefitCategories(
ResponseEntity<AdminBenefitCategoriesResponse> getBenefitCategories(
@Auth(permit = {ADMIN}) Integer adminId
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoryResponse;
import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoriesResponse;
import in.koreatech.koin.admin.benefit.dto.AdminBenefitShopsResponse;
import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryRequest;
import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryResponse;
Expand All @@ -36,10 +36,10 @@ public class AdminBenefitController implements AdminBenefitApi {
private final AdminBenefitService adminBenefitService;

@GetMapping("/categories")
public ResponseEntity<AdminBenefitCategoryResponse> getBenefitCategories(
public ResponseEntity<AdminBenefitCategoriesResponse> getBenefitCategories(
@Auth(permit = {ADMIN}) Integer adminId
) {
AdminBenefitCategoryResponse response = adminBenefitService.getBenefitCategories();
AdminBenefitCategoriesResponse response = adminBenefitService.getBenefitCategories();
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import io.swagger.v3.oas.annotations.media.Schema;

@JsonNaming(SnakeCaseStrategy.class)
public record AdminBenefitCategoryResponse(
public record AdminBenefitCategoriesResponse(
@Schema(description = "혜택 카테고리 리스트")
List<InnerBenefitResponse> benefits
) {

public static AdminBenefitCategoryResponse from(List<BenefitCategory> benefitCategories) {
return new AdminBenefitCategoryResponse(
public static AdminBenefitCategoriesResponse from(List<BenefitCategory> benefitCategories) {
return new AdminBenefitCategoriesResponse(
benefitCategories.stream().map(InnerBenefitResponse::from).toList()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoryResponse;
import in.koreatech.koin.admin.benefit.dto.AdminBenefitCategoriesResponse;
import in.koreatech.koin.admin.benefit.dto.AdminBenefitShopsResponse;
import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryRequest;
import in.koreatech.koin.admin.benefit.dto.AdminCreateBenefitCategoryResponse;
Expand Down Expand Up @@ -36,9 +36,9 @@ public class AdminBenefitService {
private final AdminBenefitCategoryMapRepository adminBenefitCategoryMapRepository;
private final AdminShopRepository adminShopRepository;

public AdminBenefitCategoryResponse getBenefitCategories() {
public AdminBenefitCategoriesResponse getBenefitCategories() {
List<BenefitCategory> categories = adminBenefitCategoryRepository.findAllByOrderByTitleAsc();
return AdminBenefitCategoryResponse.from(categories);
return AdminBenefitCategoriesResponse.from(categories);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ private void excludeGetMapping() {
+ "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.refresh(..)) && "
+ "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.createAdmin(..)) && "
+ "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminPasswordChange(..)) && "
+ "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.assignOrGetAbtestVariable(..))")
+ "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.assignOrGetAbtestVariable(..)) &&"
+ "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.issueAccessHistoryId(..))")
private void excludeSpecificMethods() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.LocalTime;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand Down Expand Up @@ -67,7 +68,10 @@ public record InnerShopResponse(
double averageRate,

@Schema(example = "10", description = "리뷰 개수", requiredMode = REQUIRED)
long reviewCount
long reviewCount,

@Schema(example = "콜라 서비스", description = "혜택 설명", requiredMode = NOT_REQUIRED)
String benefitDetail
) {

public static Comparator<InnerShopResponse> getComparator() {
Expand All @@ -80,7 +84,8 @@ public static Comparator<InnerShopResponse> getComparator() {
public static InnerShopResponse from(
Shop shop,
boolean isEvent,
boolean isOpen
boolean isOpen,
String benefitDetail
) {
return new InnerShopResponse(
shop.getShopCategories().stream().map(shopCategoryMap ->
Expand All @@ -102,7 +107,8 @@ public static InnerShopResponse from(
.orElse(0.0) * 10) / 10.0,
shop.getReviews().stream()
.filter(review -> !review.isDeleted())
.count()
.count(),
benefitDetail
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

import in.koreatech.koin.domain.shop.model.shop.Shop;
import in.koreatech.koin.global.domain.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Size;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -34,9 +36,14 @@ public class BenefitCategoryMap extends BaseEntity {
@JoinColumn(name = "benefit_id", referencedColumnName = "id", nullable = false)
private BenefitCategory benefitCategory;

@Size(min = 2, max = 20)
@Column(name = "detail")
private String detail;

@Builder
public BenefitCategoryMap(Shop shop, BenefitCategory benefitCategory) {
public BenefitCategoryMap(Shop shop, BenefitCategory benefitCategory, String detail) {
this.shop = shop;
this.benefitCategory = benefitCategory;
this.detail = detail;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;

import in.koreatech.koin.domain.benefit.model.BenefitCategoryMap;

public interface BenefitCategoryMapRepository extends Repository<BenefitCategoryMap, Integer> {

List<BenefitCategoryMap> findAllByBenefitCategoryId(Integer benefitCategoryId);
List<BenefitCategoryMap> findByBenefitCategoryId(Integer benefitCategoryId);

@Query("""
SELECT bcm FROM BenefitCategoryMap bcm
JOIN FETCH bcm.shop s
JOIN FETCH bcm.benefitCategory bc
""")
List<BenefitCategoryMap> findAllWithFetchJoin();

BenefitCategoryMap save(BenefitCategoryMap benefitCategoryMap);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,24 @@ public BenefitCategoryResponse getBenefitCategories() {
}

public BenefitShopsResponse getBenefitShops(Integer benefitId) {
List<BenefitCategoryMap> benefitCategoryMaps = benefitCategoryMapRepository
.findAllByBenefitCategoryId(benefitId);
List<BenefitCategoryMap> benefitCategoryMaps = benefitCategoryMapRepository.findByBenefitCategoryId(benefitId);
LocalDateTime now = LocalDateTime.now(clock);

List<InnerShopResponse> innerShopResponses = benefitCategoryMaps.stream()
.map(benefitCategoryMap -> {
Shop shop = benefitCategoryMap.getShop();
String benefitDetail = benefitCategoryMap.getDetail();
boolean isDurationEvent = eventArticleRepository.isDurationEvent(shop.getId(), now.toLocalDate());
return InnerShopResponse.from(shop, isDurationEvent, shop.isOpen(now));
return InnerShopResponse.from(
shop,
isDurationEvent,
shop.isOpen(now),
benefitDetail
);
})
.sorted(InnerShopResponse.getComparator())
.toList();
BenefitShopsResponse shopsResponse = BenefitShopsResponse.from(innerShopResponses);
return shopsResponse;

return BenefitShopsResponse.from(innerShopResponses);
}
}
Loading

0 comments on commit ca4c6de

Please sign in to comment.