Skip to content

Commit

Permalink
Merge pull request #70 from BudgetBuddiesTeam/feat/#67
Browse files Browse the repository at this point in the history
[feat] 지원 정보 수정/삭제 API 구현
  • Loading branch information
SoulTree-Lovers authored Aug 1, 2024
2 parents 48c3c0a + 6676928 commit dff8713
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bbteam.budgetbuddies.domain.supportinfo.controller;

import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -27,7 +27,7 @@ public interface SupportInfoApi {
@Parameter(name = "page", description = "페이지 번호, 0번이 1 페이지 입니다. (기본값은 0입니다.)"),
@Parameter(name = "size", description = "한 페이지에 불러올 데이터 개수입니다. (기본값은 10개입니다.)")
})
public ResponseEntity<Page<SupportResponseDto>> getSupportsByYearAndMonth(
ResponseEntity<Page<SupportResponseDto>> getSupportsByYearAndMonth(
@RequestParam Integer year,
@RequestParam Integer month,
@RequestParam(defaultValue = "0") Integer page,
Expand All @@ -41,8 +41,8 @@ public ResponseEntity<Page<SupportResponseDto>> getSupportsByYearAndMonth(
// @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)))
})
public ResponseEntity<SupportResponseDto> registerDiscountInfo(
@RequestBody SupportRequestDto requestDto
ResponseEntity<SupportResponseDto> registerSupportInfo(
@RequestBody SupportRequest.RegisterDto requestDto
);

@Operation(summary = "[User] 특정 지원정보에 좋아요 클릭 API", description = "특정 지원정보에 좋아요 버튼을 클릭하는 API이며, 일단은 사용자 ID를 입력하여 사용합니다. (추후 토큰으로 검증)")
Expand All @@ -56,7 +56,54 @@ public ResponseEntity<SupportResponseDto> registerDiscountInfo(
@Parameter(name = "userId", description = "좋아요를 누른 사용자의 id입니다."),
@Parameter(name = "supportInfoId", description = "좋아요를 누를 지원정보의 id입니다."),
})
public ResponseEntity<SupportResponseDto> likeDiscountInfo(
ResponseEntity<SupportResponseDto> likeSupportInfo(
@RequestParam Long userId,
@PathVariable Long supportInfoId
);

@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입니다."),
})
ResponseEntity<SupportResponseDto> updateSupportInfo(
@RequestParam Long userId,
@RequestBody SupportRequest.UpdateDto supportRequestDto
);

@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 = "supportInfoId", description = "삭제할 지원 정보의 id입니다."),
})
ResponseEntity<String> deleteSupportInfo(
@RequestParam Long userId,
@PathVariable Long supportInfoId
);

@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 = "supportInfoId", description = "조회할 지원 정보의 id입니다."),
})
ResponseEntity<SupportResponseDto> getSupportInfo(
@RequestParam Long userId,
@PathVariable Long supportInfoId
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.bbteam.budgetbuddies.domain.supportinfo.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.supportinfo.dto.SupportRequestDto;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto;
import com.bbteam.budgetbuddies.domain.supportinfo.service.SupportInfoService;
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 @@ -36,17 +32,17 @@ public ResponseEntity<Page<SupportResponseDto>> getSupportsByYearAndMonth(

@Override
@PostMapping("")
public ResponseEntity<SupportResponseDto> registerDiscountInfo(
@RequestBody SupportRequestDto requestDto
public ResponseEntity<SupportResponseDto> registerSupportInfo(
@RequestBody SupportRequest.RegisterDto requestDto
) {
SupportResponseDto supportResponseDto = supportInfoService.registerSupportInfo(requestDto);

return ResponseEntity.ok(supportResponseDto);
}

@Override
@PostMapping("/{supportInfoId}/likes")
public ResponseEntity<SupportResponseDto> likeDiscountInfo(
@PostMapping("/likes/{supportInfoId}")
public ResponseEntity<SupportResponseDto> likeSupportInfo(
@RequestParam Long userId,
@PathVariable Long supportInfoId
) {
Expand All @@ -55,4 +51,37 @@ public ResponseEntity<SupportResponseDto> likeDiscountInfo(
return ResponseEntity.ok(supportResponseDto);
}

@Override
@PutMapping("")
public ResponseEntity<SupportResponseDto> updateSupportInfo(
@RequestParam Long userId,
@RequestBody SupportRequest.UpdateDto supportRequestDto
) {
SupportResponseDto supportResponseDto = supportInfoService.updateSupportInfo(userId, supportRequestDto);

return ResponseEntity.ok(supportResponseDto);
}

@Override
@DeleteMapping("/{supportInfoId}")
public ResponseEntity<String> deleteSupportInfo(
@RequestParam Long userId,
@PathVariable Long supportInfoId
) {
String message = supportInfoService.deleteSupportInfo(userId, supportInfoId);

return ResponseEntity.ok(message);
}

@Override
@GetMapping("/{supportInfoId}")
public ResponseEntity<SupportResponseDto> getSupportInfo(
@RequestParam Long userId,
@PathVariable Long supportInfoId
) {
SupportResponseDto supportResponseDto = supportInfoService.getSupportInfoById(userId, supportInfoId);

return ResponseEntity.ok(supportResponseDto);
}

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

import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto;
import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -30,7 +30,7 @@ public SupportResponseDto toDto(SupportInfo entity) {
* @param requestDto
* @return entity
*/
public SupportInfo toEntity(SupportRequestDto requestDto) {
public SupportInfo toEntity(SupportRequest.RegisterDto requestDto) {

return SupportInfo.builder()
.title(requestDto.getTitle())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.bbteam.budgetbuddies.domain.supportinfo.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;


public class SupportRequest {

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

private String title;

private LocalDate startDate;

private LocalDate endDate;

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 String siteUrl;

private String thumbnailUrl;

}


}

This file was deleted.

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

import com.bbteam.budgetbuddies.common.BaseEntity;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequest;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import lombok.*;
Expand Down Expand Up @@ -48,4 +50,12 @@ public Integer addAndGetAnonymousNumber() {
return anonymousNumber;
}

public void update(SupportRequest.UpdateDto supportRequestDto) {
this.title = supportRequestDto.getTitle();
this.startDate = supportRequestDto.getStartDate();
this.endDate = supportRequestDto.getEndDate();
this.siteUrl = supportRequestDto.getSiteUrl();
this.thumbnailUrl = supportRequestDto.getThumbnailUrl();
}

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

import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountRequestDto;
import com.bbteam.budgetbuddies.domain.discountinfo.dto.DiscountResponseDto;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequestDto;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportRequest;
import com.bbteam.budgetbuddies.domain.supportinfo.dto.SupportResponseDto;
import org.springframework.data.domain.Page;

Expand All @@ -14,7 +12,14 @@ Page<SupportResponseDto> getSupportsByYearAndMonth(
Integer size
);

SupportResponseDto registerSupportInfo(SupportRequestDto supportRequestDto);
SupportResponseDto registerSupportInfo(SupportRequest.RegisterDto supportRequest);

SupportResponseDto toggleLike(Long userId, Long supportInfoId);
}

SupportResponseDto updateSupportInfo(Long userId, SupportRequest.UpdateDto supportRequestDto);

String deleteSupportInfo(Long userId, Long supportInfoId);

SupportResponseDto getSupportInfoById(Long userId, Long supportInfoId);

}
Loading

0 comments on commit dff8713

Please sign in to comment.