This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from UA-CS491-591/Develop
Develop
- Loading branch information
Showing
27 changed files
with
2,695 additions
and
96 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,3 +172,4 @@ UpgradeLog*.htm | |
|
||
# Microsoft Fakes | ||
FakesAssemblies/ | ||
Project2/WebServices/Web.config |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated from a template. | ||
// | ||
// Manual changes to this file may cause unexpected behavior in your application. | ||
// Manual changes to this file will be overwritten if the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
namespace WebServices | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public partial class Category | ||
{ | ||
public Category() | ||
{ | ||
this.Stories = new HashSet<Story>(); | ||
} | ||
|
||
public System.Guid Id { get; set; } | ||
public string Name { get; set; } | ||
public string Description { get; set; } | ||
|
||
public virtual ICollection<Story> Stories { get; set; } | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
Project2/WebServices/Controllers/API/CategoryController.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Web.Http; | ||
using WebServices.Models.Dtos; | ||
|
||
namespace WebServices.Controllers.API | ||
{ | ||
public class CategoryController : ApiController | ||
{ | ||
StoryModelContainer db = new StoryModelContainer(); | ||
|
||
[HttpGet] | ||
public List<DtoCategory> categories(string token) | ||
{ | ||
if (AccountController.isValidReader(token) || AccountController.isValidWriter(token)) | ||
{ | ||
List<Category> categories = db.Categories.ToList(); | ||
|
||
if (categories != null) | ||
{ | ||
List<DtoCategory> dtoCategories = new List<DtoCategory>(); | ||
foreach (Category category in categories) | ||
{ | ||
dtoCategories.Add(DtoCategory.dtoFromCategory(category)); | ||
} | ||
|
||
return dtoCategories; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
204 changes: 204 additions & 0 deletions
204
Project2/WebServices/Controllers/API/StoryController.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Web.Http; | ||
using WebServices.Models.Dtos; | ||
|
||
namespace WebServices.Controllers.API | ||
{ | ||
public class StoryController : ApiController | ||
{ | ||
StoryModelContainer db = new StoryModelContainer(); | ||
|
||
[HttpGet] | ||
public DtoStory byId(Guid token, Guid storyId) | ||
{ | ||
if (AccountController.isValidReader(token.ToString()) || AccountController.isValidWriter(token.ToString())) | ||
{ | ||
//Fetch story | ||
Story story = db.Stories.Where(s => s.Id.Equals(storyId)).SingleOrDefault(); | ||
|
||
if (story != null) | ||
{ | ||
return DtoStory.dtoFromStory(story); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
[HttpGet] | ||
public List<DtoStory> recent(string token) | ||
{ | ||
if (AccountController.isValidReader(token) || AccountController.isValidWriter(token)) | ||
{ | ||
List<Story> stories = db.Stories.OrderByDescending(s => s.DatePublished).Take(20).ToList(); | ||
|
||
if (stories != null) | ||
{ | ||
List<DtoStory> dtoStories = new List<DtoStory>(); | ||
|
||
foreach (Story story in stories) | ||
{ | ||
dtoStories.Add(DtoStory.lightDtoFromStory(story)); | ||
} | ||
|
||
return dtoStories; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
[HttpGet] | ||
public List<DtoStory> byCategory(Guid token, Guid categoryId) | ||
{ | ||
if (AccountController.isValidReader(token.ToString()) || AccountController.isValidWriter(token.ToString())) | ||
{ | ||
Category category = db.Categories.Where(c => c.Id == categoryId).SingleOrDefault(); | ||
|
||
if (category != null) | ||
{ | ||
List<Story> stories = category.Stories.OrderByDescending(s => s.DatePublished).ToList(); | ||
|
||
if (stories != null) | ||
{ | ||
|
||
List<DtoStory> dtoStories = new List<DtoStory>(); | ||
|
||
foreach (Story story in stories) | ||
{ | ||
dtoStories.Add(DtoStory.lightDtoFromStory(story)); | ||
} | ||
|
||
return dtoStories; | ||
} | ||
else | ||
{ | ||
return new List<DtoStory>(); | ||
} | ||
} | ||
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
[HttpGet] | ||
public List<DtoStory> byAuthor(Guid token, string authorId) | ||
{ | ||
if (AccountController.isValidReader(token.ToString()) || AccountController.isValidWriter(token.ToString())) | ||
{ | ||
|
||
List<Story> stories = db.Stories.Where(s => s.authorId.Equals(authorId)).OrderByDescending(s => s.DatePublished).ToList(); | ||
|
||
if (stories != null) | ||
{ | ||
List<DtoStory> dtoStories = new List<DtoStory>(); | ||
|
||
foreach (Story story in stories) | ||
{ | ||
dtoStories.Add(DtoStory.lightDtoFromStory(story)); | ||
} | ||
|
||
return dtoStories; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
[HttpGet] | ||
public List<DtoStory> search(string token, string searchString) | ||
{ | ||
if (AccountController.isValidReader(token) || AccountController.isValidWriter(token)) | ||
{ | ||
List<Story> stories = db.Stories.Where(s => s.Title.Contains(searchString) || s.Subtitle.Contains(searchString) || s.Body.Contains(searchString)).OrderByDescending(s => s.DatePublished).Take(20).ToList(); | ||
|
||
if (stories != null) | ||
{ | ||
List<DtoStory> dtoStories = new List<DtoStory>(); | ||
|
||
foreach (Story story in stories) | ||
{ | ||
dtoStories.Add(DtoStory.lightDtoFromStory(story)); | ||
} | ||
|
||
return dtoStories; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
[HttpPost] | ||
public DtoStory add(DtoAddStory dtoAddStory) | ||
{ | ||
if (AccountController.isValidWriter(dtoAddStory.accessToken)) | ||
{ | ||
Category category = db.Categories.Where(c => c.Id.Equals(dtoAddStory.categoryId)).SingleOrDefault(); | ||
|
||
if (category != null) | ||
{ | ||
Story story = DtoStory.newStoryFromDto(dtoAddStory); | ||
|
||
if (story != null) | ||
{ | ||
category.Stories.Add(story); | ||
db.SaveChanges(); | ||
|
||
return DtoStory.dtoFromStory(story); | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
[HttpPut] | ||
public Boolean edit(DtoEditStory dto){ | ||
|
||
if (AccountController.isValidWriter(dto.accessToken)) | ||
{ | ||
Story story = db.Stories.Where(s => s.Id.Equals(dto.story.storyId)).SingleOrDefault(); | ||
|
||
if (story != null) | ||
{ | ||
story.Title = dto.story.title; | ||
story.Subtitle = dto.story.subtitle; | ||
story.Body = dto.story.body; | ||
story.Lat = dto.story.lat; | ||
story.Lng = dto.story.lng; | ||
story.DateUpdated = DateTime.UtcNow; | ||
|
||
db.SaveChanges(); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
[HttpDelete] | ||
public Boolean delete(string token, Guid storyId) | ||
{ | ||
|
||
if (AccountController.isValidWriter(token)) | ||
{ | ||
Story story = db.Stories.Where(s => s.Id.Equals(storyId)).SingleOrDefault(); | ||
|
||
if (story != null) | ||
{ | ||
db.Stories.Remove(story); | ||
|
||
db.SaveChanges(); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace WebServices.Models.Dtos | ||
{ | ||
public class DtoAccessToken | ||
{ | ||
public string accessToken { get; set; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace WebServices.Models.Dtos | ||
{ | ||
public class DtoAddStory : DtoAccessToken | ||
{ | ||
public String title { get; set; } | ||
public String subtitle { get; set; } | ||
public String body { get; set; } | ||
public Guid authorId { get; set; } | ||
public double? lat { get; set; } | ||
public double? lng { get; set; } | ||
public Guid categoryId { get; set; } | ||
} | ||
} |
Oops, something went wrong.