Class DealDAO
java.lang.Object
com.JesacaLin.GrubGoblin_v13.daos.DealDAO
Class is a Data Access Object (DAO) for dealing with the 'deal' table in the GrubGoblin v1.3 PostgreSQL database. Will also deal with view model: FullDealDetails
Annotation means this class is a Spring Component, Spring will create the class if there is a need.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateDeal
(Deal deal) Creates a new deal in the 'deals' table in the database.int
deleteDealById
(int dealId) Deletes an existing deal in the 'deals' table in the database.getAllDealByDayOfWeek
(String dayOfWeek) Fetches all deals from the 'deal' table by specific day of the week, according to 'FullDealDetails' view model.getAllDealByKeyword
(String keyword) Fetches all deals from the 'deal' table by specific keyword, according to 'FullDealDetails' view model.getAllDealDetailByDealId
(int deal_id) getAllDealDetailByPlaceId
(int place_id) Fetches all deals from the 'deal' table from a specific place, according to 'FullDealDetails' view model.Fetches all deals from the 'deal' table, according to 'FullDealDetails' view model.Fetches all deals from the 'deal' table in the database.Fetches all deals from the 'deal' table if stars rating is 4 or above, according to 'FullDealDetails' view model.getDealById
(int dealId) Fetches a specific deal from the 'deal' table in the database using its ID.mapRowToDeal
(org.springframework.jdbc.support.rowset.SqlRowSet rowSet) A utility method that maps data from a SqlRowSet, obtained from a SQL query, to aDeal
object.mapRowToDealDetails
(org.springframework.jdbc.support.rowset.SqlRowSet rowSet) A utility method that maps data from a SqlRowSet, obtained from a SQL query, to aFullDealDetails
object.updateDeal
(Deal deal) Updates an existing deal in the 'deals' table in the database.
-
Constructor Details
-
DealDAO
-
-
Method Details
-
getAllDeals
Fetches all deals from the 'deal' table in the database.- Returns:
- a list of all deals in the database
- Throws:
DaoException
- if unable to connect to the server or database
-
getDealById
Fetches a specific deal from the 'deal' table in the database using its ID.- Parameters:
dealId
- the ID of the deal to fetch- Returns:
- the deal with the given ID, or null if id doesn't exist
- Throws:
DaoException
- if unable to connect to the server or database
-
createDeal
Creates a new deal in the 'deals' table in the database.- Parameters:
deal
- the deal to create. More info on the related Deal model:Deal
. Each object now includes the following info: - placeId: the ID of the place where the deal is available - typeOfDeal: The type of deal it is - dealDescription: a description of what the deal is - daysOfWeek: The days of the week the deal is available (e.g., "M, Tu, W, Th, F") - startTime: The start time of the deal (e.g., "10:00:00") - endTime: The end time of the deal (e.g., "17:00:00") - createdBy: the user that created the deal- Returns:
- the newly created deal with all details filled in.
- Throws:
DaoException
- if unable to connect to the server/database or data integrity violation. For example, if placeId doesn't exist
-
updateDeal
Updates an existing deal in the 'deals' table in the database.- Parameters:
deal
- the deal to update. More info on the related Deal model:Deal
. Each object needs the following info: - placeId: the ID of the place where the deal is available (**This field cannot be updated**). - typeOfDeal: The type of deal it is - dealDescription: a description of what the deal is - daysOfWeek: The days of the week the deal is available (e.g., "M, Tu, W, Th, F") - startTime: The start time of the deal (e.g., "10:00:00") - endTime: The end time of the deal (e.g., "17:00:00") - createdBy: the user that created the deal (**This field cannot be updated**)- Returns:
- the newly updated deal with edits added.
- Throws:
DaoException
- if unable to connect to the server/database, data integrity violation (e.g., placeId doesn't exist in the 'places' table).
-
deleteDealById
public int deleteDealById(int dealId) Deletes an existing deal in the 'deals' table in the database.- Parameters:
dealId
- the specific deal to delete, based on id.- Returns:
- the number of rows affected. Should be 1. If returning 0, it means nothing was deleted.
- Throws:
DaoException
- if unable to connect to the server/database or data integrity violation. For ex: if dealId doesn't exist in the 'deal' table.
-
getAllDealDetails
Fetches all deals from the 'deal' table, according to 'FullDealDetails' view model.- Returns:
- a list of all deals in the database that conforms to the view model's required data. Full list here:
FullDealDetails
- Throws:
DaoException
- if unable to connect to the server or database
-
getAllDealByKeyword
Fetches all deals from the 'deal' table by specific keyword, according to 'FullDealDetails' view model.- Parameters:
keyword
- the word to search for in the deal descriptions- Returns:
- a list of all deals in the database that contains the keyword and conforms to the view model's required data. Full list here:
FullDealDetails
- Throws:
DaoException
- if unable to connect to the server or database
-
getAllDealByDayOfWeek
Fetches all deals from the 'deal' table by specific day of the week, according to 'FullDealDetails' view model. Day of the week is an int!- Parameters:
dayOfWeek
- the specific day of the week being searched for (1 for Monday, 2 for Tuesday...etc. 8 for deals that are available all week)- Returns:
- a list of all deals in the database that occurs on a specific day of the week and conforms to the view model's required data. Full list here:
FullDealDetails
- Throws:
DaoException
- if unable to connect to the server or database
-
getAllTopRatedDeals
Fetches all deals from the 'deal' table if stars rating is 4 or above, according to 'FullDealDetails' view model. Note: Star rating is the user's rating of the deal, is NOT google rating- Returns:
- a list of all deals in the database that has a deal rating of 4 or higher and conforms to the view model's required data. Full list here:
FullDealDetails
- Throws:
DaoException
- if unable to connect to the server or database
-
getAllDealDetailByPlaceId
Fetches all deals from the 'deal' table from a specific place, according to 'FullDealDetails' view model.- Parameters:
place_id
- the specific place searched for.- Returns:
- a list of all deals in the database that occurs at a specific place and conforms to the view model's required data. Full list here:
FullDealDetails
- Throws:
DaoException
- if unable to connect to the server or database
-
getAllDealDetailByDealId
-
mapRowToDeal
A utility method that maps data from a SqlRowSet, obtained from a SQL query, to aDeal
object.- Parameters:
rowSet
- a SqlRowSet containing data from a row in the 'deal' table.- Returns:
- new deal object that is populated with data from the rowSet. For more info on the fields in the Deal object, see
Deal
.
-
mapRowToDealDetails
public FullDealDetails mapRowToDealDetails(org.springframework.jdbc.support.rowset.SqlRowSet rowSet) A utility method that maps data from a SqlRowSet, obtained from a SQL query, to aFullDealDetails
object.- Parameters:
rowSet
- a SqlRowSet containing data from a row in the 'deal' table.- Returns:
- new deal object that is populated with data from the rowSet. For more info on the fields in the Deal object, see
FullDealDetails
.
-