|
| 1 | +package com.gpt.geumpumtabackend.badge.api; |
| 2 | + |
| 3 | +import com.gpt.geumpumtabackend.badge.dto.request.BadgeCreateRequest; |
| 4 | +import com.gpt.geumpumtabackend.badge.dto.request.RepresentativeBadgeRequest; |
| 5 | +import com.gpt.geumpumtabackend.badge.dto.response.BadgeCreateResponse; |
| 6 | +import com.gpt.geumpumtabackend.badge.dto.response.BadgeResponse; |
| 7 | +import com.gpt.geumpumtabackend.badge.dto.response.MyBadgeResponse; |
| 8 | +import com.gpt.geumpumtabackend.badge.dto.response.MyBadgeStatusResponse; |
| 9 | +import com.gpt.geumpumtabackend.badge.dto.response.RepresentativeBadgeResponse; |
| 10 | +import com.gpt.geumpumtabackend.global.aop.AssignUserId; |
| 11 | +import com.gpt.geumpumtabackend.global.config.swagger.SwaggerApiFailedResponse; |
| 12 | +import com.gpt.geumpumtabackend.global.config.swagger.SwaggerApiResponses; |
| 13 | +import com.gpt.geumpumtabackend.global.config.swagger.SwaggerApiSuccessResponse; |
| 14 | +import com.gpt.geumpumtabackend.global.exception.ExceptionType; |
| 15 | +import com.gpt.geumpumtabackend.global.response.ResponseBody; |
| 16 | +import io.swagger.v3.oas.annotations.Operation; |
| 17 | +import io.swagger.v3.oas.annotations.Parameter; |
| 18 | +import io.swagger.v3.oas.annotations.media.Content; |
| 19 | +import io.swagger.v3.oas.annotations.media.Schema; |
| 20 | +import io.swagger.v3.oas.annotations.responses.ApiResponse; |
| 21 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 22 | +import jakarta.validation.Valid; |
| 23 | +import org.springframework.http.ResponseEntity; |
| 24 | +import org.springframework.security.access.prepost.PreAuthorize; |
| 25 | +import org.springframework.web.bind.annotation.*; |
| 26 | + |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +@Tag(name = "배지 API", description = """ |
| 30 | + 배지 생성/조회/삭제 및 사용자 배지 조회 기능을 제공합니다. |
| 31 | + """) |
| 32 | +public interface BadgeApi { |
| 33 | + |
| 34 | + @Operation( |
| 35 | + summary = "배지 생성", |
| 36 | + description = """ |
| 37 | + ADMIN 권한으로 새로운 배지를 생성합니다. |
| 38 | + - code: 배지 고유 코드 (중복 불가) |
| 39 | + - badgeType: 배지 종류 |
| 40 | + - thresholdValue: 누적 시간/연속 일수 계열 배지 기준값 |
| 41 | + - rank: 시즌 랭킹 배지 등수 값(예: 1,2,3) |
| 42 | + """ |
| 43 | + ) |
| 44 | + @ApiResponse(content = @Content(schema = @Schema(implementation = BadgeCreateResponse.class))) |
| 45 | + @SwaggerApiResponses( |
| 46 | + success = @SwaggerApiSuccessResponse( |
| 47 | + response = BadgeCreateResponse.class, |
| 48 | + description = "배지 생성 성공" |
| 49 | + ), |
| 50 | + errors = { |
| 51 | + @SwaggerApiFailedResponse(ExceptionType.NEED_AUTHORIZED), |
| 52 | + @SwaggerApiFailedResponse(ExceptionType.ACCESS_DENIED), |
| 53 | + @SwaggerApiFailedResponse(ExceptionType.BADGE_CODE_ALREADY_EXISTS) |
| 54 | + } |
| 55 | + ) |
| 56 | + @PostMapping |
| 57 | + @PreAuthorize("isAuthenticated() and hasRole('ADMIN')") |
| 58 | + ResponseEntity<ResponseBody<BadgeCreateResponse>> createBadge( |
| 59 | + @RequestBody @Valid BadgeCreateRequest request |
| 60 | + ); |
| 61 | + |
| 62 | + @Operation( |
| 63 | + summary = "전체 배지 조회", |
| 64 | + description = "ADMIN 권한으로 전체 배지 목록을 조회합니다." |
| 65 | + ) |
| 66 | + @ApiResponse(content = @Content(schema = @Schema(implementation = BadgeResponse.class))) |
| 67 | + @SwaggerApiResponses( |
| 68 | + success = @SwaggerApiSuccessResponse( |
| 69 | + response = BadgeResponse.class, |
| 70 | + description = "전체 배지 조회 성공" |
| 71 | + ), |
| 72 | + errors = { |
| 73 | + @SwaggerApiFailedResponse(ExceptionType.NEED_AUTHORIZED), |
| 74 | + @SwaggerApiFailedResponse(ExceptionType.ACCESS_DENIED) |
| 75 | + } |
| 76 | + ) |
| 77 | + @GetMapping |
| 78 | + @PreAuthorize("isAuthenticated() and hasRole('ADMIN')") |
| 79 | + ResponseEntity<ResponseBody<List<BadgeResponse>>> getAllBadges(); |
| 80 | + |
| 81 | + @Operation( |
| 82 | + summary = "배지 삭제", |
| 83 | + description = """ |
| 84 | + ADMIN 권한으로 배지를 삭제합니다. |
| 85 | + 이미 사용자에게 지급된 이력이 있으면 삭제할 수 없고 B004(BADGE_IN_USE)를 반환합니다. |
| 86 | + """ |
| 87 | + ) |
| 88 | + @ApiResponse(content = @Content(schema = @Schema(implementation = ResponseBody.class))) |
| 89 | + @SwaggerApiResponses( |
| 90 | + success = @SwaggerApiSuccessResponse(description = "배지 삭제 성공"), |
| 91 | + errors = { |
| 92 | + @SwaggerApiFailedResponse(ExceptionType.NEED_AUTHORIZED), |
| 93 | + @SwaggerApiFailedResponse(ExceptionType.ACCESS_DENIED), |
| 94 | + @SwaggerApiFailedResponse(ExceptionType.BADGE_NOT_FOUND), |
| 95 | + @SwaggerApiFailedResponse(ExceptionType.BADGE_IN_USE) |
| 96 | + } |
| 97 | + ) |
| 98 | + @DeleteMapping("/{badgeId}") |
| 99 | + @PreAuthorize("isAuthenticated() and hasRole('ADMIN')") |
| 100 | + ResponseEntity<ResponseBody<Void>> deleteBadge( |
| 101 | + @PathVariable Long badgeId |
| 102 | + ); |
| 103 | + |
| 104 | + @Operation( |
| 105 | + summary = "내 배지 조회", |
| 106 | + description = """ |
| 107 | + 항상 전체 배지 목록을 반환합니다. |
| 108 | + 각 원소는 아래 정보를 포함합니다. |
| 109 | + - owned: 사용자의 배지 보유 여부 |
| 110 | + - awardedAt: 배지 획득 시각 (owned=false이면 null) |
| 111 | + """ |
| 112 | + ) |
| 113 | + @ApiResponse(content = @Content(schema = @Schema(implementation = MyBadgeStatusResponse.class))) |
| 114 | + @SwaggerApiResponses( |
| 115 | + success = @SwaggerApiSuccessResponse( |
| 116 | + response = MyBadgeStatusResponse.class, |
| 117 | + description = "내 배지 조회 성공" |
| 118 | + ), |
| 119 | + errors = { |
| 120 | + @SwaggerApiFailedResponse(ExceptionType.NEED_AUTHORIZED), |
| 121 | + @SwaggerApiFailedResponse(ExceptionType.USER_NOT_FOUND) |
| 122 | + } |
| 123 | + ) |
| 124 | + @GetMapping("/me") |
| 125 | + @AssignUserId |
| 126 | + @PreAuthorize("isAuthenticated() and hasRole('USER')") |
| 127 | + ResponseEntity<ResponseBody<List<MyBadgeStatusResponse>>> getMyBadges( |
| 128 | + @Parameter(hidden = true) Long userId |
| 129 | + ); |
| 130 | + |
| 131 | + @Operation( |
| 132 | + summary = "대표 배지 설정", |
| 133 | + description = """ |
| 134 | + 보유한 배지 중 하나를 대표 배지로 설정합니다. |
| 135 | + 요청은 badgeCode 기준으로 처리됩니다. |
| 136 | + """ |
| 137 | + ) |
| 138 | + @ApiResponse(content = @Content(schema = @Schema(implementation = RepresentativeBadgeResponse.class))) |
| 139 | + @SwaggerApiResponses( |
| 140 | + success = @SwaggerApiSuccessResponse( |
| 141 | + response = RepresentativeBadgeResponse.class, |
| 142 | + description = "대표 배지 설정 성공" |
| 143 | + ), |
| 144 | + errors = { |
| 145 | + @SwaggerApiFailedResponse(ExceptionType.NEED_AUTHORIZED), |
| 146 | + @SwaggerApiFailedResponse(ExceptionType.USER_NOT_FOUND), |
| 147 | + @SwaggerApiFailedResponse(ExceptionType.BADGE_NOT_FOUND), |
| 148 | + @SwaggerApiFailedResponse(ExceptionType.BADGE_NOT_OWNED) |
| 149 | + } |
| 150 | + ) |
| 151 | + @PostMapping("/me/representative-badge") |
| 152 | + @AssignUserId |
| 153 | + @PreAuthorize("isAuthenticated() and hasRole('USER')") |
| 154 | + ResponseEntity<ResponseBody<RepresentativeBadgeResponse>> setRepresentativeBadge( |
| 155 | + @RequestBody RepresentativeBadgeRequest request, |
| 156 | + @Parameter(hidden = true) Long userId |
| 157 | + ); |
| 158 | + |
| 159 | + @Operation( |
| 160 | + summary = "미확인 배지 조회", |
| 161 | + description = """ |
| 162 | + 사용자의 미확인 배지 목록을 조회합니다. |
| 163 | + 조회된 배지는 같은 요청 트랜잭션에서 확인 처리(notifiedAt 설정)됩니다. |
| 164 | + """ |
| 165 | + ) |
| 166 | + @ApiResponse(content = @Content(schema = @Schema(implementation = MyBadgeResponse.class))) |
| 167 | + @SwaggerApiResponses( |
| 168 | + success = @SwaggerApiSuccessResponse( |
| 169 | + response = MyBadgeResponse.class, |
| 170 | + description = "미확인 배지 조회 성공" |
| 171 | + ), |
| 172 | + errors = { |
| 173 | + @SwaggerApiFailedResponse(ExceptionType.NEED_AUTHORIZED), |
| 174 | + @SwaggerApiFailedResponse(ExceptionType.USER_NOT_FOUND) |
| 175 | + } |
| 176 | + ) |
| 177 | + @GetMapping("/unnotified") |
| 178 | + @AssignUserId |
| 179 | + @PreAuthorize("isAuthenticated() and hasRole('USER')") |
| 180 | + ResponseEntity<ResponseBody<List<MyBadgeResponse>>> getUnnotifiedBadges( |
| 181 | + @Parameter(hidden = true) Long userId |
| 182 | + ); |
| 183 | +} |
0 commit comments