Skip to content

Commit

Permalink
ApiResponses added
Browse files Browse the repository at this point in the history
  • Loading branch information
mayararysia committed Jul 29, 2020
1 parent 3b4413d commit bf0a0cd
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.rysia.conferencedemo.models.AttendeeTicket;
import com.rysia.conferencedemo.repositories.AttendeeTicketRepository;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -23,6 +25,7 @@ public class AttendeeTicketsController {
private AttendeeTicketRepository attendeeTicketRepository;

@ApiOperation(value = "LIST ALL ATTENDEES' TICKETS")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Attendees Tickets Not Found")})
@GetMapping("/attendees/tickets")
public ResponseEntity<List<AttendeeTicket>> list() {
List<AttendeeTicket> attendeeTickets = this.attendeeTicketRepository.findAll();
Expand All @@ -39,6 +42,7 @@ public ResponseEntity<List<AttendeeTicket>> list() {
}

@ApiOperation(value = "GET A UNIQUE ATTENDEE TICKET")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Attendee Ticket Not Found")})
@GetMapping("/attendee/ticket/{id}")
public ResponseEntity<AttendeeTicket> get(@PathVariable(value = "id") Long id) {
Optional<AttendeeTicket> optionalAttendeeTicket = this.attendeeTicketRepository.findById(id);
Expand All @@ -54,13 +58,18 @@ public ResponseEntity<AttendeeTicket> get(@PathVariable(value = "id") Long id) {
}

@ApiOperation(value = "CREATE AN ATTENDEE TICKET")
@ApiResponses(value = {@ApiResponse(code = 201, message = "Attendee Ticket Created")})
@PostMapping("/attendee/ticket")
public ResponseEntity<AttendeeTicket> create(@RequestBody @Valid final AttendeeTicket attendeeTicket) {
return new ResponseEntity<AttendeeTicket>(this.attendeeTicketRepository.saveAndFlush(attendeeTicket),
HttpStatus.CREATED);
}

@ApiOperation(value = "UPDATE AN ATTENDEE TICKET")
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Updated Attendee Ticket"),
@ApiResponse(code = 404, message = "Attendee Ticket Not Found")
})
@RequestMapping(value = "/attendee/ticket/{id}", method = RequestMethod.PUT)
public ResponseEntity<AttendeeTicket> update(@PathVariable(value = "id") Long id, @RequestBody @Valid AttendeeTicket attendeeTicket) {
Optional<AttendeeTicket> optionalAttendeeTicket = this.attendeeTicketRepository.findById(id);
Expand All @@ -78,6 +87,10 @@ public ResponseEntity<AttendeeTicket> update(@PathVariable(value = "id") Long id
}

@ApiOperation(value = "DELETE AN ATTENDEE TICKET")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Deleted Attendee Ticket"),
@ApiResponse(code = 404, message = "Attendee Ticket Not Found")
})
@RequestMapping(value = "/attendee/ticket/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(@PathVariable(value = "id") Long id) {
if (Optional.ofNullable(this.attendeeTicketRepository.findById(id)).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.rysia.conferencedemo.models.Attendee;
import com.rysia.conferencedemo.repositories.AttendeeRepository;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -23,6 +25,7 @@ public class AttendeesController {
private AttendeeRepository attendeeRepository;

@ApiOperation(value = "LIST ALL ATTENDEES")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Attendee Not Found")})
@GetMapping("/attendees")
public ResponseEntity<List<Attendee>> list() {
List<Attendee> attendees = this.attendeeRepository.findAll();
Expand All @@ -37,6 +40,7 @@ public ResponseEntity<List<Attendee>> list() {
}

@ApiOperation(value = "GET A UNIQUE ATTENDEE")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Attendee Not Found")})
@GetMapping("/attendee/{id}")
public ResponseEntity<Attendee> get(@PathVariable(value = "id") Long id) {
Optional<Attendee> optionalAttendee = this.attendeeRepository.findById(id);
Expand All @@ -51,12 +55,17 @@ public ResponseEntity<Attendee> get(@PathVariable(value = "id") Long id) {
}

@ApiOperation(value = "CREATE AN ATTENDEE")
@ApiResponses(value = {@ApiResponse(code = 201, message = "Attendee Created")})
@PostMapping("/attendee")
public ResponseEntity<Attendee> create(@RequestBody @Valid final Attendee attendee) {
return new ResponseEntity<Attendee>(this.attendeeRepository.saveAndFlush(attendee), HttpStatus.CREATED);
}

@ApiOperation(value = "UPDATE AN ATTENDEE")
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Updated Attendee"),
@ApiResponse(code = 404, message = "Attendee Not Found")
})
@RequestMapping(value = "/attendee/{id}", method = RequestMethod.PUT)
public ResponseEntity<Attendee> update(@PathVariable(value = "id") Long id, @RequestBody @Valid Attendee attendee) {
Optional<Attendee> optionalAttendee = this.attendeeRepository.findById(id);
Expand All @@ -73,6 +82,7 @@ public ResponseEntity<Attendee> update(@PathVariable(value = "id") Long id, @Req
}

@ApiOperation(value = "DELETE AN ATTENDEE")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Deleted Attendee"), @ApiResponse(code = 404, message = "Attendee Not Found")})
@RequestMapping(value = "/attendee/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(@PathVariable(value = "id") Long id) {
if (Optional.ofNullable(this.attendeeRepository.findById(id)).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.rysia.conferencedemo.models.DiscountCode;
import com.rysia.conferencedemo.repositories.DiscountCodeRepository;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -24,6 +26,7 @@ public class DiscountCodesController {
private DiscountCodeRepository discountCodeRepository;

@ApiOperation(value = "LIST ALL DISCOUNT CODES")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Discount Not Found")})
@GetMapping("/codes")
public ResponseEntity<List<DiscountCode>> list() {
List<DiscountCode> discountCodes = this.discountCodeRepository.findAll();
Expand All @@ -39,6 +42,7 @@ public ResponseEntity<List<DiscountCode>> list() {
}

@ApiOperation(value = "GET A UNIQUE DISCOUNT CODE")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Discount Not Found")})
@GetMapping("/code/{id}")
public ResponseEntity<DiscountCode> get(@PathVariable(value = "id") Long id) {
Optional<DiscountCode> optionalDiscountCode = this.discountCodeRepository.findById(id);
Expand All @@ -54,13 +58,18 @@ public ResponseEntity<DiscountCode> get(@PathVariable(value = "id") Long id) {
}

@ApiOperation(value = "CREATE A DISCOUNT CODE")
@ApiResponses(value = {@ApiResponse(code = 201, message = "Discount Created")})
@PostMapping("/code")
public ResponseEntity<DiscountCode> create(@RequestBody @Valid final DiscountCode discountCode) {
return new ResponseEntity<DiscountCode>(this.discountCodeRepository.saveAndFlush(discountCode),
HttpStatus.CREATED);
}

@ApiOperation(value = "UPDATE A DISCOUNT CODE")
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Updated Discount"),
@ApiResponse(code = 404, message = "Discount Not Found")
})
@RequestMapping(value = "/code/{id}", method = RequestMethod.PUT)
public ResponseEntity<DiscountCode> update(@PathVariable(value = "id") Long id, @RequestBody @Valid DiscountCode discountCode) {
Optional<DiscountCode> optionalDiscountCode = this.discountCodeRepository.findById(id);
Expand All @@ -77,6 +86,10 @@ public ResponseEntity<DiscountCode> update(@PathVariable(value = "id") Long id,
}

@ApiOperation(value = "DELETE A DISCOUNT CODE")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Deleted Discount Code"),
@ApiResponse(code = 404, message = "Discount Not Found")
})
@RequestMapping(value = "/code/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(@PathVariable(value = "id") Long id) {
if (Optional.ofNullable(this.discountCodeRepository.findById(id)).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.rysia.conferencedemo.models.PricingCategory;
import com.rysia.conferencedemo.repositories.PricingCategoryRepository;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -23,6 +25,7 @@ public class PricingCategoriesController {
private PricingCategoryRepository pricingCategoryRepository;

@ApiOperation(value = "LIST ALL PRICING CATEGORIES")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Categories Not Found")})
@GetMapping("/categories")
public ResponseEntity<List<PricingCategory>> list() {
List<PricingCategory> pricingCategories = this.pricingCategoryRepository.findAll();
Expand All @@ -39,6 +42,7 @@ public ResponseEntity<List<PricingCategory>> list() {
}

@ApiOperation(value = "GET A UNIQUE PRICING CATEGORY")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Category Not Found")})
@GetMapping("/category/{id}")
public ResponseEntity<PricingCategory> get(@PathVariable(value = "id") Long id) {
Optional<PricingCategory> optionalPricingCategory = this.pricingCategoryRepository.findById(id);
Expand All @@ -54,13 +58,18 @@ public ResponseEntity<PricingCategory> get(@PathVariable(value = "id") Long id)
}

@ApiOperation(value = "CREATE PRICING CATEGORY")
@ApiResponses(value = {@ApiResponse(code = 201, message = "Pricing Category Created")})
@PostMapping("/category")
public ResponseEntity<PricingCategory> create(@RequestBody @Valid final PricingCategory pricingCategory) {
return new ResponseEntity<PricingCategory>(this.pricingCategoryRepository.saveAndFlush(pricingCategory),
HttpStatus.CREATED);
}

@ApiOperation(value = "UPDATE PRICING CATEGORY")
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Updated Category"),
@ApiResponse(code = 404, message = "Category Not Found")
})
@RequestMapping(value = "/category/{id}", method = RequestMethod.PUT)
public ResponseEntity<PricingCategory> update(@PathVariable(value = "id") Long id, @RequestBody @Valid PricingCategory pricingCategory) {
Optional<PricingCategory> optionalPricingCategory = pricingCategoryRepository.findById(id);
Expand All @@ -77,6 +86,10 @@ public ResponseEntity<PricingCategory> update(@PathVariable(value = "id") Long i
}

@ApiOperation(value = "DELETE PRICING CATEGORY")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Deleted Pricing Category"),
@ApiResponse(code = 404, message = "Pricing Category Not Found")
})
@RequestMapping(value = "/category/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(@PathVariable(value = "id") Long id) {
if (Optional.ofNullable(this.pricingCategoryRepository.findById(id)).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.rysia.conferencedemo.models.SessionSchedule;
import com.rysia.conferencedemo.repositories.SessionScheduleRepository;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.modelmapper.ModelMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -29,6 +31,7 @@ public class SessionSchedulesController {
ModelMapper modelMapper;

@ApiOperation(value = "LIST ALL SESSIONS SCHEDULES")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Sessions Schedules Not Found")})
@GetMapping("/sessions/schedules")
public ResponseEntity<List<SessionSchedule>> list() {
List<SessionSchedule> sessionSchedules = this.sessionScheduleRepository.findAll();
Expand All @@ -44,6 +47,7 @@ public ResponseEntity<List<SessionSchedule>> list() {
}

@ApiOperation(value = "GET A UNIQUE SESSION SCHEDULE")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Session Schedule Not Found")})
@GetMapping("/session/schedule/{id}")
public ResponseEntity<SessionSchedule> get(@PathVariable(value = "id") Long id) {
Optional<SessionSchedule> optionalSessionSchedule = this.sessionScheduleRepository.findById(id);
Expand All @@ -59,13 +63,18 @@ public ResponseEntity<SessionSchedule> get(@PathVariable(value = "id") Long id)
}

@ApiOperation(value = "CREATE A SESSION SCHEDULE")
@ApiResponses(value = {@ApiResponse(code = 201, message = "Session Schedule Created")})
@PostMapping("/session/schedule")
public ResponseEntity<SessionScheduleDTO> create(@RequestBody @Valid final SessionScheduleDTO sessionScheduleDTO) {
return new ResponseEntity<SessionScheduleDTO>(convertEntityToDTO(this.sessionScheduleRepository
.saveAndFlush(convertToEntity(sessionScheduleDTO))), HttpStatus.CREATED);
}

@ApiOperation(value = "UPDATE A SESSION SCHEDULE")
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Updated Session Schedule"),
@ApiResponse(code = 404, message = "Session Schedule Not Found")
})
@RequestMapping(value = "/session/schedule/{id}", method = RequestMethod.PUT)
public ResponseEntity<SessionSchedule> update(@PathVariable(value = "id") Long id, @RequestBody @Valid SessionScheduleDTO sessionScheduleDTO) {
Optional<SessionSchedule> optionalSessionSchedule = this.sessionScheduleRepository.findById(id);
Expand All @@ -82,6 +91,10 @@ public ResponseEntity<SessionSchedule> update(@PathVariable(value = "id") Long i
}

@ApiOperation(value = "DELETE A SESSION SCHEDULE")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Deleted Session Schedule"),
@ApiResponse(code = 404, message = "Session Schedule Not Found")
})
@RequestMapping(value = "/session/schedule/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(@PathVariable(value = "id") Long id) {
if (Optional.ofNullable(this.sessionScheduleRepository.findById(id).isPresent()).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.rysia.conferencedemo.models.Session;
import com.rysia.conferencedemo.repositories.SessionRepository;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.modelmapper.ModelMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,6 +30,7 @@ public class SessionsController {
private ModelMapper modelMapper;

@ApiOperation(value = "LIST ALL SESSIONS")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Sessions Not Found")})
@GetMapping("/sessions")
@ResponseBody
public ResponseEntity<List<Session>> list() {
Expand All @@ -43,6 +46,7 @@ public ResponseEntity<List<Session>> list() {
}

@ApiOperation(value = "GET A UNIQUE SESSION")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Session Not Found")})
@GetMapping("/session/{id}")
@ResponseBody
public ResponseEntity<Session> get(@PathVariable(value = "id") Long id) {
Expand All @@ -59,13 +63,18 @@ public ResponseEntity<Session> get(@PathVariable(value = "id") Long id) {
}

@ApiOperation(value = "CREATE A SESSION")
@ApiResponses(value = {@ApiResponse(code = 201, message = "Session Created")})
@PostMapping("/session")
public ResponseEntity<Session> create(@RequestBody @Valid final SessionDTO sessionDTO) {
return new ResponseEntity<Session>(this.sessionRepository.saveAndFlush(convertToEntity(sessionDTO)),
HttpStatus.CREATED);
}

@ApiOperation(value = "UPDATE A SESSION")
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Updated Session"),
@ApiResponse(code = 404, message = "Session Not Found")
})
@RequestMapping(value = "/session/{id}", method = RequestMethod.PUT, produces = "application/json", consumes = "application/json")
public ResponseEntity<Session> update(@PathVariable(value = "id") Long id, @RequestBody @Valid SessionDTO sessionDTO) {
Optional<Session> optionalSession = this.sessionRepository.findById(id);
Expand All @@ -80,6 +89,10 @@ public ResponseEntity<Session> update(@PathVariable(value = "id") Long id, @Requ
}

@ApiOperation(value = "DELETE A SESSION")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Deleted Session"),
@ApiResponse(code = 404, message = "Session Not Found")
})
@RequestMapping(value = "/session/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(@PathVariable(value = "id") Long id) {
if (Optional.ofNullable(this.sessionRepository.findById(id)).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.rysia.conferencedemo.models.Slot;
import com.rysia.conferencedemo.repositories.SlotRepository;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -23,6 +25,7 @@ public class SlotsController {
private SlotRepository slotRepository;

@ApiOperation(value = "LIST ALL TIME SLOTS")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Slots Not Found")})
@GetMapping("/slots")
public ResponseEntity<List<Slot>> list() {
List<Slot> slots = this.slotRepository.findAll();
Expand All @@ -37,6 +40,7 @@ public ResponseEntity<List<Slot>> list() {
}

@ApiOperation(value = "GET A UNIQUE TIME SLOT")
@ApiResponses(value = {@ApiResponse(code = 404, message = "Slot Not Found")})
@GetMapping("/slot/{id}")
public ResponseEntity<Slot> get(@PathVariable(value = "id") Long id) {
Optional<Slot> optionalSlot = this.slotRepository.findById(id);
Expand All @@ -52,12 +56,17 @@ public ResponseEntity<Slot> get(@PathVariable(value = "id") Long id) {
}

@ApiOperation(value = "CREATE A TIME SLOT")
@ApiResponses(value = {@ApiResponse(code = 201, message = "Slot Created")})
@PostMapping("/slot")
public ResponseEntity<Slot> create(@RequestBody @Valid final Slot slot) {
return new ResponseEntity<Slot>(this.slotRepository.saveAndFlush(slot), HttpStatus.CREATED);
}

@ApiOperation(value = "UPDATE A TIME SLOT")
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Updated Slot"),
@ApiResponse(code = 404, message = "Slot Not Found")
})
@RequestMapping(value = "/slot/{id}", method = RequestMethod.PUT)
public ResponseEntity<Slot> update(@PathVariable(value = "id") Long id, @RequestBody @Valid Slot slot) {
Optional<Slot> optionalSlot = this.slotRepository.findById(id);
Expand All @@ -74,6 +83,10 @@ public ResponseEntity<Slot> update(@PathVariable(value = "id") Long id, @Request
}

@ApiOperation(value = "DELETE A TIME SLOT")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Deleted Time Slot"),
@ApiResponse(code = 404, message = "Time Slot Not Found")
})
@RequestMapping(value = "/slot/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> delete(@PathVariable(value = "id") Long id) {
if (Optional.ofNullable(this.slotRepository.findById(id)).isPresent()) {
Expand Down
Loading

0 comments on commit bf0a0cd

Please sign in to comment.