개발일지

2024.01.26 TIL

과일바구니♡ 2024. 1. 26. 21:01

1. 배운내용

   1)알고리즘코드카타

  

 

2) 백오피스 프로젝트

곽준선: refresh token

박지영: Notice 역할 기반 접근 제어 / 학습.

김철학:Review 관리자 API 컨트롤러 / 역할 기반 접근 제어

노하영: Comment 관리자 API 컨트롤러 / 역할 기반 접근 제어

 

package com.b3backoffice.domain.notice.controller


import com.b3backoffice.domain.notice.dto.CreateNoticeRequest
import com.b3backoffice.domain.notice.dto.NoticeResponse
import com.b3backoffice.domain.notice.dto.UpdateNoticeRequest
import com.b3backoffice.domain.notice.service.NoticeService
import com.b3backoffice.infra.security.UserPrincipal
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.*
import jakarta.validation.Valid
import org.springframework.security.access.prepost.PreAuthorize

@RequestMapping("/notices")
@RestController
class NoticeController(
    private val noticeService: NoticeService
) {

    @GetMapping
    fun getNoticeList(): ResponseEntity<List<NoticeResponse>> {
        return ResponseEntity
                 .status(HttpStatus.OK)
                 .body(noticeService.getAllNoticeList())
    }

    @GetMapping("/{noticeId}")
    fun getNotice(@PathVariable noticeId: Long) : ResponseEntity<NoticeResponse> {
        return ResponseEntity
                .status(HttpStatus.OK)
                .body(noticeService.getNoticeById(noticeId))
    }

     @PreAuthorize("hasRole('ADMIN')")
     @PostMapping
     fun createNotice(
         @AuthenticationPrincipal userPrincipal: UserPrincipal,
         @RequestBody @Valid request: CreateNoticeRequest,
     ) : ResponseEntity<NoticeResponse> {

         return ResponseEntity
                 .status(HttpStatus.CREATED)
                 .body(noticeService.createNotice(userPrincipal.id, request))
     }

     @PreAuthorize("hasRole('ADMIN')")
     @PutMapping("/notice/{noticeId}")
     fun updateNotice(
         @PathVariable noticeId: Long,
         @AuthenticationPrincipal userPrincipal: UserPrincipal,
         @RequestBody @Valid request: UpdateNoticeRequest,
     ) :ResponseEntity<NoticeResponse>{
         return ResponseEntity
               .status(HttpStatus.OK)
               .body(noticeService.updateNotice(noticeId, userPrincipal.id, request))
     }

    @PreAuthorize("hasRole('ADMIN')")
    @DeleteMapping("/notices/{noticeId}")
    fun deleteNotice(
        @PathVariable noticeId: Long,
        @AuthenticationPrincipal userPrincipal: UserPrincipal,
    ): ResponseEntity<Unit> {
        noticeService.deleteNotice(noticeId, userPrincipal.id)
        return ResponseEntity
               .status(HttpStatus.NO_CONTENT)
               .build()
    }
}

  

강의듣고있는중...

 

 

..........................어렵다.....................

'개발일지' 카테고리의 다른 글

2024.01.30 TIL  (1) 2024.01.30
2024.01.29 TIL,백오피스 KPT 회고록  (1) 2024.01.29
2024.01.25 TIL  (0) 2024.01.25
2024.01.24 TIL  (0) 2024.01.24
2024.01.23 TIL  (0) 2024.01.23