Skip to content

Commit

Permalink
Merge pull request #66 from BudgetBuddiesTeam/feat/#56
Browse files Browse the repository at this point in the history
[feat] 할인 정보 수정/삭제 API 구현
  • Loading branch information
SoulTree-Lovers authored Aug 1, 2024
2 parents fd7341a + 817c7bb commit 48c3c0a
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.bbteam.budgetbuddies.domain.discountinfo.controller;

import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -41,9 +40,12 @@ ResponseEntity<Page<DiscountResponseDto>> getDiscountsByYearAndMonth(
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
@Parameters({
// @Parameter(name = "discountRequestDto", description = "등록할 할인 정보의 전체 내용입니다."),
})
public ResponseEntity<DiscountResponseDto> registerDiscountInfo(
@RequestBody DiscountRequestDto discountRequestDto
@RequestBody DiscountRequest.RegisterDto discountRequestDto
);

@Operation(summary = "[User] 특정 할인정보에 좋아요 클릭 API", description = "특정 할인정보에 좋아요 버튼을 클릭하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)")
Expand All @@ -62,4 +64,52 @@ public ResponseEntity<DiscountResponseDto> likeDiscountInfo(
@PathVariable Long discountInfoId
);

@Operation(summary = "[ADMIN] 특정 할인정보 수정하기 API", description = "특정 할인정보를 수정하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
@Parameters({
@Parameter(name = "userId", description = "수정할 사용자의 id입니다."),
// @Parameter(name = "discountRequestDto", description = "수정할 할인 정보의 전체 내용입니다."),
})
public ResponseEntity<DiscountResponseDto> updateDiscountInfo(
@RequestParam Long userId,
@RequestBody DiscountRequest.UpdateDto discountRequestDto
);

@Operation(summary = "[ADMIN] 특정 할인정보 삭제하기 API", description = "특정 할인정보를 삭제하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
@Parameters({
@Parameter(name = "userId", description = "삭제할 사용자의 id입니다."),
@Parameter(name = "discountInfoId", description = "삭제할 할인 정보의 id입니다."),
})
public ResponseEntity<String> deleteDiscountInfo(
@RequestParam Long userId,
@PathVariable Long discountInfoId
);

@Operation(summary = "[ADMIN] 특정 할인정보 가져오기 API", description = "ID를 통해 특정 할인정보를 가져오는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))),
// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))
})
@Parameters({
@Parameter(name = "userId", description = "조회할 사용자의 id입니다."),
@Parameter(name = "discountInfoId", description = "조회할 할인 정보의 id입니다."),
})
public ResponseEntity<DiscountResponseDto> getDiscountInfo(
@RequestParam Long userId,
@PathVariable Long discountInfoId
);

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.bbteam.budgetbuddies.domain.discountinfo.controller;

import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto;
import com.bbteam.budgetbuddies.domain.discountinfo.service.DiscountInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -35,15 +31,15 @@ public ResponseEntity<Page<DiscountResponseDto>> getDiscountsByYearAndMonth(
@Override
@PostMapping("")
public ResponseEntity<DiscountResponseDto> registerDiscountInfo(
@RequestBody DiscountRequestDto discountRequestDto
@RequestBody DiscountRequest.RegisterDto discountRequestDto
) {
DiscountResponseDto discountResponseDto = discountInfoService.registerDiscountInfo(discountRequestDto);

return ResponseEntity.ok(discountResponseDto);
}

@Override
@PostMapping("/{discountInfoId}/likes")
@PostMapping("/likes/{discountInfoId}")
public ResponseEntity<DiscountResponseDto> likeDiscountInfo(
@RequestParam Long userId,
@PathVariable Long discountInfoId
Expand All @@ -53,4 +49,38 @@ public ResponseEntity<DiscountResponseDto> likeDiscountInfo(
return ResponseEntity.ok(discountResponseDto);
}

@Override
@PutMapping("")
public ResponseEntity<DiscountResponseDto> updateDiscountInfo(
@RequestParam Long userId,
@RequestBody DiscountRequest.UpdateDto discountRequestDto
) {
DiscountResponseDto discountResponseDto = discountInfoService.updateDiscountInfo(userId, discountRequestDto);

return ResponseEntity.ok(discountResponseDto);
}

@Override
@DeleteMapping("/{discountInfoId}")
public ResponseEntity<String> deleteDiscountInfo(
@RequestParam Long userId,
@PathVariable Long discountInfoId
) {
String message = discountInfoService.deleteDiscountInfo(userId, discountInfoId);

return ResponseEntity.ok(message);
}


@Override
@GetMapping("/{discountInfoId}")
public ResponseEntity<DiscountResponseDto> getDiscountInfo(
@RequestParam Long userId,
@PathVariable Long discountInfoId
) {
DiscountResponseDto discountResponseDto = discountInfoService.getDiscountInfoById(userId, discountInfoId);

return ResponseEntity.ok(discountResponseDto);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bbteam.budgetbuddies.domain.discountinfo.converter;

import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto;
import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo;
import org.springframework.stereotype.Service;
Expand All @@ -23,6 +23,7 @@ public DiscountResponseDto toDto(DiscountInfo entity) {
.discountRate(entity.getDiscountRate())
.likeCount(entity.getLikeCount())
.siteUrl(entity.getSiteUrl())
.thumbnailUrl(entity.getThumbnailUrl())
.build();
}

Expand All @@ -31,7 +32,7 @@ public DiscountResponseDto toDto(DiscountInfo entity) {
* @param requestDto
* @return entity
*/
public DiscountInfo toEntity(DiscountRequestDto requestDto) {
public DiscountInfo toEntity(DiscountRequest.RegisterDto requestDto) {

return DiscountInfo.builder()
.title(requestDto.getTitle())
Expand All @@ -41,6 +42,7 @@ public DiscountInfo toEntity(DiscountRequestDto requestDto) {
.discountRate(requestDto.getDiscountRate())
.likeCount(0)
.siteUrl(requestDto.getSiteUrl())
.thumbnailUrl(requestDto.getThumbnailUrl())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.bbteam.budgetbuddies.domain.discountinfo.dto;

import lombok.*;

import java.time.LocalDate;

public class DiscountRequest {

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class RegisterDto {

private String title;

private LocalDate startDate;

private LocalDate endDate;

private Integer discountRate;

private String siteUrl;

private String thumbnailUrl;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class UpdateDto {

private Long id;

private String title;

private LocalDate startDate;

private LocalDate endDate;

private Integer discountRate;

private String siteUrl;

private String thumbnailUrl;
}


}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public class DiscountResponseDto {

private String siteUrl;

private String thumbnailUrl;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bbteam.budgetbuddies.domain.discountinfo.entity;

import com.bbteam.budgetbuddies.common.BaseEntity;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import lombok.*;
Expand Down Expand Up @@ -34,6 +35,9 @@ public class DiscountInfo extends BaseEntity {
@Column(length = 1000)
private String siteUrl;

@Column(length = 1000)
private String thumbnailUrl; // 카드 썸네일 이미지

public void addLikeCount() {
this.likeCount++;
}
Expand All @@ -47,4 +51,13 @@ public Integer addAndGetAnonymousNumber() {
return anonymousNumber;
}

public void update(DiscountRequest.UpdateDto discountRequestDto) {
this.title = discountRequestDto.getTitle();
this.startDate = discountRequestDto.getStartDate();
this.endDate = discountRequestDto.getEndDate();
this.discountRate = discountRequestDto.getDiscountRate();
this.siteUrl = discountRequestDto.getSiteUrl();
this.thumbnailUrl = discountRequestDto.getThumbnailUrl();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bbteam.budgetbuddies.domain.discountinfo.service;

import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto;
import org.springframework.data.domain.Page;

Expand All @@ -12,9 +12,14 @@ Page<DiscountResponseDto> getDiscountsByYearAndMonth(
Integer size
);

DiscountResponseDto registerDiscountInfo(DiscountRequestDto discountRequestDto);
DiscountResponseDto registerDiscountInfo(DiscountRequest.RegisterDto discountRequestDto);

DiscountResponseDto toggleLike(Long userId, Long discountInfoId);

DiscountResponseDto updateDiscountInfo(Long userId, DiscountRequest.UpdateDto discountRequestDto);

}
String deleteDiscountInfo(Long userId, Long discountInfoId);

DiscountResponseDto getDiscountInfoById(Long userId, Long discountInfoId);

}
Loading

0 comments on commit 48c3c0a

Please sign in to comment.