Skip to content

Instantly share code, notes, and snippets.

@anirudh83
Created October 17, 2012 18:08
Show Gist options
  • Save anirudh83/3907110 to your computer and use it in GitHub Desktop.
Save anirudh83/3907110 to your computer and use it in GitHub Desktop.
using approve in REST URL
/**
* @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);
}
}
@anirudh83
Copy link
Author

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