Skip to content

Commit

Permalink
Feat/52 advanced-api-jwt (#76)
Browse files Browse the repository at this point in the history
* test: update tests for Bookmark API

* feat: update Bookmark API to use JWT Authorization

* docs: update open-api.json

* docs: update open-api.json

* feat : change jwt userprincipal username to id , change some test codes

* fix : change some integration test code

* docs: update open-api.yaml

* chore: apply pr

* feat: authorize /event/**

* feat: authorize /reservation/**

* docs: update open-api.yaml

* chore: test commit

* feat: apply pr

* docs: update open-api.yaml

* chore: klint

---------

Co-authored-by: Git Actions <no-reply@github.com>
Co-authored-by: MinJun Kim <minjun3021@naver.com>
Co-authored-by: Junha <junha.ahn.dev@gmail.com>
  • Loading branch information
4 people authored Sep 13, 2023
1 parent 61d1ddc commit ea83bee
Show file tree
Hide file tree
Showing 34 changed files with 495 additions and 574 deletions.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ services:
JWT_SECRET: d2VhcmVuYXZ5c3dkZXZlbG9wZXJzLmFuZGlhbW1pbmp1bjMwMjE=
JWT_EXPIRATION_HOURS: 24
JWT_ISSUER: minjun

depends_on:
db:
condition: service_healthy
Expand Down
Empty file added docs/open-api.json
Empty file.
195 changes: 51 additions & 144 deletions docs/open-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,67 +64,6 @@ paths:
responses:
"200":
description: OK
/events/{id}:
get:
tags:
- event-controller
operationId: getEvent
parameters:
- name: id
in: path
required: true
schema:
type: integer
format: int64
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/EventResponse'
put:
tags:
- event-controller
operationId: updateEvent
parameters:
- name: id
in: path
required: true
schema:
type: integer
format: int64
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/EventCreateRequest'
required: true
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/EventResponse'
delete:
tags:
- event-controller
operationId: deleteEvent
parameters:
- name: id
in: path
required: true
schema:
type: integer
format: int64
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/Unit'
/users/signup:
post:
tags:
Expand Down Expand Up @@ -161,24 +100,6 @@ paths:
'*/*':
schema:
$ref: '#/components/schemas/ReservationResponse'
/events:
post:
tags:
- event-controller
operationId: createEvent
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/EventCreateRequest'
required: true
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/EventResponse'
/bookmarks:
get:
tags:
Expand All @@ -195,12 +116,12 @@ paths:
tags:
- bookmark-controller
operationId: addBookmark
parameters:
- name: boardFormDto
in: query
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/BookmarkFromdto'
required: true
schema:
$ref: '#/components/schemas/BookmarkFromdto'
responses:
"200":
description: OK
Expand Down Expand Up @@ -234,6 +155,25 @@ paths:
'*/*':
schema:
type: object
/events/{id}:
get:
tags:
- event-controller
operationId: getEvent
parameters:
- name: id
in: path
required: true
schema:
type: integer
format: int64
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/EventResponse'
/events/:
get:
tags:
Expand Down Expand Up @@ -327,56 +267,6 @@ components:
bookedAt:
type: string
format: date-time
EventCreateRequest:
required:
- date
- maxAttendees
- reservationEndTime
- reservationStartTime
- title
type: object
properties:
title:
type: string
date:
type: string
format: date-time
reservationStartTime:
type: string
format: date-time
reservationEndTime:
type: string
format: date-time
maxAttendees:
type: integer
format: int32
EventResponse:
required:
- date
- id
- maxAttendees
- reservationEndTime
- reservationStartTime
- title
type: object
properties:
id:
type: integer
format: int64
title:
type: string
date:
type: string
format: date-time
reservationStartTime:
type: string
format: date-time
reservationEndTime:
type: string
format: date-time
maxAttendees:
type: integer
format: int32
SignUpRequest:
required:
- email
Expand Down Expand Up @@ -410,26 +300,43 @@ components:
ReservationCreateRequest:
required:
- eventId
- userId
type: object
properties:
eventId:
type: integer
format: int64
userId:
type: integer
format: int64
BookmarkFromdto:
required:
- show_id
- user_id
- event_id
type: object
properties:
user_id:
event_id:
type: integer
format: int32
show_id:
EventResponse:
required:
- date
- id
- maxAttendees
- reservationEndTime
- reservationStartTime
- title
type: object
properties:
id:
type: integer
format: int64
title:
type: string
date:
type: string
format: date-time
reservationStartTime:
type: string
format: date-time
reservationEndTime:
type: string
format: date-time
maxAttendees:
type: integer
format: int32
Unit:
type: object
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,86 @@ package com.group4.ticketingservice.Bookmark

import com.group4.ticketingservice.AbstractIntegrationTest
import com.group4.ticketingservice.entity.Bookmark
import com.group4.ticketingservice.entity.Event
import com.group4.ticketingservice.entity.User
import com.group4.ticketingservice.repository.BookmarkRepository
import com.group4.ticketingservice.repository.EventRepository
import com.group4.ticketingservice.repository.UserRepository
import com.group4.ticketingservice.utils.Authority
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.assertInstanceOf
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.repository.findByIdOrNull
import org.springframework.transaction.annotation.Transactional
import java.time.Clock
import java.time.OffsetDateTime

class BookmarkRepositoryTest(
@Autowired val bookmarkRepository: BookmarkRepository
@Autowired val bookmarkRepository: BookmarkRepository,
@Autowired val userRepository: UserRepository,
@Autowired val eventRepository: EventRepository,
@Autowired private val clock: Clock
) : AbstractIntegrationTest() {

val sampleUser = User(
name = "james",
email = "james@example.com",
password = "12345678",
authority = Authority.USER
)

private val sampleEvent: Event = Event(
title = "test title",
date = OffsetDateTime.now(),
reservationEndTime = OffsetDateTime.now(),
reservationStartTime = OffsetDateTime.now(),
maxAttendees = 10
)

private val sampleBookmark = Bookmark(
user = sampleUser,
event = sampleEvent
)

@Test
fun `bookmarkRepository_save should return savedBookmark`() {
// given
val sampleBookmark = Bookmark(
user_id = 1,
show_id = 1
)
val savedUser = userRepository.save(sampleUser)
val savedEvent = eventRepository.save(sampleEvent)
val requestBookmark = Bookmark(user = savedUser, event = savedEvent)

// when
val savedBookmark = bookmarkRepository.save(sampleBookmark)
val savedBookmark = bookmarkRepository.save(requestBookmark)

// then
assertThat(savedBookmark).isEqualTo(sampleBookmark)
assertThat(savedBookmark).isEqualTo(requestBookmark)
}

@Test
fun `bookmarkRepository_findByIdOrNull should return foundBookmark`() {
fun `bookmarkRepository_findByIdAndUser should return foundBookmark`() {
// given
val sampleBookmark = Bookmark(
user_id = 1,
show_id = 1
)

val savedBookmark = bookmarkRepository.save(sampleBookmark)
val savedUser = userRepository.save(sampleUser)
val savedEvent = eventRepository.save(sampleEvent)
val savedBookmark = bookmarkRepository.save(Bookmark(user = savedUser, event = savedEvent))

// when
val foundBookmark = bookmarkRepository.findByIdOrNull(savedBookmark.id?.toLong())
val foundBookmark = bookmarkRepository.findByIdAndUserId(savedBookmark.id!!, savedUser.id!!)

// then
assert(savedBookmark.id == foundBookmark?.id)
assert(savedBookmark.id == foundBookmark.id)
}

@Test
fun `bookmarkRepository_deleteById should delete requestedBookmark`() {
@Transactional
fun `bookmarkRepository_deleteByIdAndUser should delete requestedBookmark`() {
// given
val sampleBookmark = Bookmark(
user_id = 1,
show_id = 1
)

val savedBookmark = bookmarkRepository.save(sampleBookmark)
val savedUser = userRepository.save(sampleUser)
val savedEvent = eventRepository.save(sampleEvent)
val savedBookmark = bookmarkRepository.save(Bookmark(user = savedUser, event = savedEvent))

// when
savedBookmark.id?.let { bookmarkRepository.deleteById(it.toLong()) }
bookmarkRepository.deleteByIdAndUserId(savedBookmark.id!!, savedUser.id!!)

// then
val deletedBookmark = bookmarkRepository.findByIdOrNull(savedBookmark.id?.toLong())
Expand All @@ -65,17 +90,14 @@ class BookmarkRepositoryTest(
}

@Test
fun `bookmarkRepository_findAll should return list of Bookmarks`() {
fun `bookmarkRepository_findByUser should return list of Bookmarks`() {
// given
val sampleBookmark = Bookmark(
user_id = 1,
show_id = 1
)

bookmarkRepository.save(sampleBookmark)
val savedUser = userRepository.save(sampleUser)
val savedEvent = eventRepository.save(sampleEvent)
bookmarkRepository.save(Bookmark(user = savedUser, event = savedEvent))

// when
val listofBookmarks = bookmarkRepository.findAll()
val listofBookmarks = bookmarkRepository.findByUserId(savedUser.id!!)

// then
assertInstanceOf(ArrayList::class.java, listofBookmarks)
Expand Down
Loading

0 comments on commit ea83bee

Please sign in to comment.