Skip to content

Commit

Permalink
feat: change http status of postController, add getCompanyByCurator
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeqwaszx committed Feb 1, 2025
1 parent adeaaea commit 6834635
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import jakarta.validation.Valid
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
Expand Down Expand Up @@ -68,7 +69,7 @@ class PostController(
@PathVariable("post_id") postId: String,
): ResponseEntity<Void> {
postService.addBookmark(user.id, postId)
return ResponseEntity.ok().build()
return ResponseEntity.status(HttpStatus.CREATED).build()
}

// 관심 채용 삭제하기
Expand All @@ -78,7 +79,7 @@ class PostController(
@PathVariable("post_id") postId: String,
): ResponseEntity<Void> {
postService.deleteBookmark(user.id, postId)
return ResponseEntity.ok().build()
return ResponseEntity.noContent().build()
}

// 북마크 가져오기
Expand Down Expand Up @@ -148,7 +149,7 @@ class PostController(
@Valid @RequestBody request: CreateCompanyRequest,
): ResponseEntity<Company> {
val company = postService.createCompany(user, request)
return ResponseEntity.ok(company)
return ResponseEntity.status(HttpStatus.CREATED).body(company)
}

@PostMapping("/company/{company_id}/position")
Expand All @@ -158,7 +159,15 @@ class PostController(
@Valid @RequestBody request: CreatePositionRequest,
): ResponseEntity<Position> {
val position = postService.createPosition(user, companyId, request)
return ResponseEntity.ok(position)
return ResponseEntity.status(HttpStatus.CREATED).body(position)
}

@GetMapping("/company/me")
fun getCompanyByCurator(
@AuthUser user: User,
): ResponseEntity<List<Company>> {
val companies = postService.getCompanyByCurator(user)
return ResponseEntity.ok(companies)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.waffletoy.team1server.post.persistence

import com.waffletoy.team1server.user.persistence.UserEntity
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

Expand All @@ -12,4 +13,6 @@ interface CompanyRepository : JpaRepository<CompanyEntity, String> {
* @return True if a company with the email exists, else false.
*/
fun existsByEmail(email: String): Boolean

fun findAllByAdmin(admin: UserEntity): List<CompanyEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class PostService(
private val bookmarkRepository: BookmarkRepository,
private val positionRepository: PositionRepository,
@Lazy private val userService: UserService,
private val userRepository: UserRepository,
) {
@Value("\${custom.page.size:12}")
private val pageSize: Int = 12
Expand Down Expand Up @@ -343,6 +342,15 @@ class PostService(
return Company.fromEntity(savedCompany)
}

@Transactional
fun getCompanyByCurator(user: User): List<Company> {
if (user.userRole != UserRole.CURATOR) {
throw NotAuthorizedException()
}
val userEntity = userService.getUserEntityByUserId(user.id) ?: throw UserNotFoundException(mapOf("userId" to user.id))
return companyRepository.findAllByAdmin(userEntity).map { Company.fromEntity(it) }
}

@Transactional
fun createPosition(
user: User,
Expand Down

0 comments on commit 6834635

Please sign in to comment.