Created
October 17, 2012 18:08
-
-
Save anirudh83/3907110 to your computer and use it in GitHub Desktop.
using approve in REST URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Jagmeet | |
* @author anirudh | |
*/ | |
@Component | |
@Validated | |
public class MealDayRestService { | |
private static final String MEAL_DAY_ID = "mealDayId"; | |
private static final String USER_ID = "userId"; | |
@Autowired | |
private MealDayService mealDayService; | |
@Autowired | |
private MealDayTransformer transformer; | |
/** | |
* Retrieves count of meal days for a meal plan and status passed. | |
* | |
* @param mealPlanId : unique id for meal plan | |
* @param status : status of meal days | |
* @return : count of meal days for passed meal plan and status. | |
*/ | |
@GET | |
@Path("mealDay/{id}") | |
@Produces(MediaType.APPLICATION_JSON) | |
public MealDayDTO getMealDay(@PathParam("id") Long id) { | |
MealDay mealDay = mealDayService.get(id); | |
return transformer.toDTO(mealDay); | |
} | |
@PUT | |
@Path("mealDay/user/{userId}/saveAsDraft") | |
@Consumes(MediaType.APPLICATION_JSON) | |
@Produces(MediaType.APPLICATION_JSON) | |
public MealDayDTO saveAsDraft(@PathParam(USER_ID) Long userId, MealDayDTO mealDayDTO) { | |
MealDay mealDay = transformer.toDomain(mealDayDTO); | |
mealDay = mealDayService.updateMealDay(mealDay, userId); | |
return getMealDay(mealDay.getId()); | |
} | |
@PUT | |
@Path("mealDay/user/{userId}/submitForApproval") | |
@Consumes(MediaType.APPLICATION_JSON) | |
@Produces(MediaType.APPLICATION_JSON) | |
public MealDayDTO submitForApproval(@PathParam(USER_ID) Long userId, MealDayDTO mealDayDTO) { | |
MealDay mealDay = transformer.toDomain(mealDayDTO); | |
mealDay = mealDayService.updateMealDay(mealDay, userId, WorkflowStatus.SUBMITTED_FOR_APPROVAL); | |
return getMealDay(mealDay.getId()); | |
} | |
@PUT | |
@Path("mealDay/{mealDayId}/user/{userId}/approve") | |
@Produces(MediaType.APPLICATION_JSON) | |
public void approveMealDay(@PathParam(MEAL_DAY_ID) Long mealDayId, @PathParam(USER_ID) Long userId) { | |
mealDayService.approveMealDay(mealDayId, userId); | |
} | |
@PUT | |
@Path("mealDay/{mealDayId}/user/{userId}/reject") | |
@Produces(MediaType.APPLICATION_JSON) | |
public void rejectMealDay(@PathParam(MEAL_DAY_ID) Long mealDayId, @PathParam(USER_ID) Long userId) { | |
mealDayService.rejectMealDay(mealDayId, userId); | |
} | |
} |
UserId is not for the user who approves it
but it is the identifies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This API approves a mealDay for a particular User
MealDay is an entity
And Each User has multiple meal days