1. 배운내용
1)알고리즘코드카타

class Solution {
fun solution(arr1: Array<IntArray>, arr2: Array<IntArray>): Array<IntArray> {
return Array<IntArray>(arr1.size){ i ->
IntArray(arr1[0].size){ j -> arr1[i][j] + arr2[i][j] }
}
}
}
-출처: https://yline.tistory.com/56 [Y_LINE's_Repository:티스토리]
class Solution {
fun solution(arr1: Array<IntArray>, arr2: Array<IntArray>): Array<IntArray>
{ var answer = Array(arr1.size) { IntArray(arr1[0].size) }
for(i in 0 .. answer.size-1){ for( j in 0 .. answer[0].size-1){
answer[i][j] = arr1[i][j] + arr2[i][j] } }
return answer } }
class Solution {
fun solution(arr1: Array<IntArray>, arr2: Array<IntArray>): Array<IntArray> {
//var answer = Array(arr1.count()) {IntArray(arr1[0].count())}
var answer = Array(arr1.count()) {IntArray(arr1[0].count(), {0})}
for (i in arr1.indices) {
for (j in arr1[i].indices) {
answer[i][j] = arr1[i][j] + arr2[i][j]
}
}
return answer
}
}
다른 사람 풀이
class Solution {
fun solution(arr1: Array<IntArray>, arr2: Array<IntArray>): Array<IntArray> {
return Array(arr1.size) {
row ->
IntArray(arr1[0].size) {
col ->
arr1[row][col] + arr2[row][col]
}
}
}
}
이라고 합니다..
2) 백오피스 프로젝트 진행..
-노티 CRUD 작성중....
2) 백오피스 프로젝트 진행..
-노티 CRUD 작성중....
- 곽준선 - 로그아웃 기능 개선 준비 중 / 전체 코드 확인 준비
- 박지영 - Notice를 user와 연결시키는 작업 중
- 김철학 - 좋아요(Heart)까지 구현 / 백오피스 고민
- 노하영 - Comment 인가, 페이징 처리 마무리 / 백오피스 등 선택 구현 과제 고민
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.*
@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))
}
@PostMapping
fun createNotice(
@AuthenticationPrincipal userPrincipal: UserPrincipal,
@RequestBody createNoticeRequest: CreateNoticeRequest,
) : ResponseEntity<NoticeResponse> {
return ResponseEntity
.status(HttpStatus.CREATED)
.body(noticeService.createNotice(userPrincipal.id, createNoticeRequest))
}
@PutMapping("/notice/{noticeId}")
fun updateNotice(
@PathVariable noticeId: Long,
@AuthenticationPrincipal userPrincipal: UserPrincipal,
@RequestBody updateNoticeRequest: UpdateNoticeRequest,
) :ResponseEntity<NoticeResponse>{
return ResponseEntity
.status(HttpStatus.OK)
.body(noticeService.updateNotice(noticeId, userPrincipal.id, updateNoticeRequest))
}
@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()
}
}
package com.b3backoffice.domain.notice.service
import com.b3backoffice.domain.exception.ModelNotFoundException
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.model.Notice
import com.b3backoffice.domain.notice.repository.NoticeRepository
import com.b3backoffice.domain.user.repositiry.UserRepository
import jakarta.transaction.Transactional
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
@Service
class NoticeService(
private val noticeRepository: NoticeRepository,
private val userRepository: UserRepository,
)
{
fun getAllNoticeList(): List<NoticeResponse> {
return noticeRepository.findAll().map { it.toResponse() }
}
fun getNoticeById(noticeId: Long): NoticeResponse {
val notice = noticeRepository.findByIdOrNull(noticeId) ?: throw ModelNotFoundException("Notice", noticeId)
return notice.toResponse()
}
@Transactional
fun createNotice(userId: Long, request: CreateNoticeRequest): NoticeResponse {
val foundUser = userRepository.findByIdOrNull(userId) ?: throw IllegalArgumentException("적절한 예외처리 필요함") // TODO 적절한 예외처리 필요함
return noticeRepository.save(
Notice(
title = request.title,
content = request.content,
user = foundUser
)
).toResponse()
}
@Transactional
fun updateNotice(noticeId: Long, userId: Long, request: UpdateNoticeRequest): NoticeResponse {
val notice = noticeRepository.findByIdOrNull(noticeId) ?: throw ModelNotFoundException("Notice", noticeId)
if (notice.user.id != userId) throw IllegalArgumentException("요청한 사용자와 Notice 작성한 사용자가 다릅니다.") // TODO 더 적절한 예외 처리 필요
val (title, context) = request
notice.title = title
notice.content =context
return noticeRepository.save(notice).toResponse()
}
@Transactional
fun deleteNotice(noticeId: Long, userId: Long) {
val notice = noticeRepository.findByIdOrNull(noticeId) ?:throw ModelNotFoundException("Notice", noticeId)
if (notice.user.id != userId) throw IllegalArgumentException("요청한 사용자와 Notice 작성한 사용자가 다릅니다.") // TODO 더 적절한 예외 처리 필요
noticeRepository.delete(notice)
}
}
...
'개발일지' 카테고리의 다른 글
| 2024.01.26 TIL (0) | 2024.01.26 |
|---|---|
| 2024.01.25 TIL (0) | 2024.01.25 |
| 2024.01.23 TIL (0) | 2024.01.23 |
| 2024.01.22 TIL (0) | 2024.01.22 |
| 2024.01.19 TIL (0) | 2024.01.19 |