From 0f5516bca769d8c51a644ff9a105e5c11fd2320e Mon Sep 17 00:00:00 2001 From: Oktawian-L Date: Sat, 9 Nov 2019 09:05:05 +0100 Subject: [PATCH] PhotoController initial PhotoController initial --- .gitignore | 3 + .../SubitonAPI/config/applicationhost.config | 2 +- .../v16/TestStore/0/000-0000.testlog | Bin 20971556 -> 20971556 bytes .../Controllers/PhotosController.cs | 131 ++++++++++++++++++ SubitonAPI/SubitonAPI/Startup.cs | 2 + SubitonAPI/SubitonAPI/Subiton.db | Bin 114688 -> 114688 bytes SubitonAPI/SubitonAPI/SubitonAPI.csproj | 4 + 7 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 SubitonAPI/SubitonAPI/Controllers/PhotosController.cs diff --git a/.gitignore b/.gitignore index de82e0b..b93b0b2 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,6 @@ SubitonBackend/.vs/SubitonBackend/v15/Server/sqlite3/storage.ide SubitonAPI/.vs/SubitonAPI/DesignTimeBuild/.dtbcache SubitonAPI/.vs/SubitonAPI/v16/Server/sqlite3/db.lock SubitonAPI/.vs/SubitonAPI/v16/Server/sqlite3/storage.ide +SubitonAPI/SubitonAPI/appsettings.json +SubitonAPI/SubitonAPI/appsettings.json +SubitonAPI/SubitonAPI/appsettings.json diff --git a/SubitonAPI/.vs/SubitonAPI/config/applicationhost.config b/SubitonAPI/.vs/SubitonAPI/config/applicationhost.config index 032d57e..d401068 100644 --- a/SubitonAPI/.vs/SubitonAPI/config/applicationhost.config +++ b/SubitonAPI/.vs/SubitonAPI/config/applicationhost.config @@ -157,7 +157,7 @@ - + diff --git a/SubitonAPI/.vs/SubitonAPI/v16/TestStore/0/000-0000.testlog b/SubitonAPI/.vs/SubitonAPI/v16/TestStore/0/000-0000.testlog index 0cd5930c03db2d028044306747e400f166f330b1..3fdbd4a8732d0dbd7a1aeac17a48bd63e7f63bd0 100644 GIT binary patch delta 16372 zcmeI(33yc16$kM9vOo-k1O+05u*4*gz?-~%8H1PxwNaEM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ybm8{tN{32ug8!mr@h@Ef=VZiU-m6Wk7);SRVH?t;7F9=I3ogZp6%{1zU7 z2jL;u3Qh1ZJOa(|C_Dz+;Bj~Yo`k31Y4{yH1HXr7;W=o5?XUx$hn?^Oya+ErEBpao zhF$Oqyb6DW*I+li4sXDp;Lq?T`~}{Ew_y*w1Mk9n@IHJ1ZSW!Ng^yq#d<=huzriQ) zDf}J&0sn-5!M|bu6`1>Lfrca+l4(exA(e(fGz_L8jfNv=NT*>44MSy5`9`$KJLmJVTCN!lP z&B>qzEont2t!YDB+R>g%xRlGdoGZAJ4s_%yI&n4E(3xwwj_c_{SGsWnH*ymr5|^55BJia0SsgigBik5hB2J`xSt1jkcW7fM|hOSc$_B~ z!AM4t#b};n3{UYi&oGu}d5-59#|w;S0u!0Ui@e0kOy(6{X90envq(O+L1bux{-R3`jG~ahLJ{*#*rqGrjcfm=8=p@i%82zt4L;~b)-$CZKPdd Pq4!9ncb}J%lQH-r=C}`V diff --git a/SubitonAPI/SubitonAPI/Controllers/PhotosController.cs b/SubitonAPI/SubitonAPI/Controllers/PhotosController.cs new file mode 100644 index 0000000..a42a1a0 --- /dev/null +++ b/SubitonAPI/SubitonAPI/Controllers/PhotosController.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using CloudinaryDotNet; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; +using SubitonAPI.Data; +using SubitonAPI.Helpers; +using SubitonAPI.Models; + +namespace SubitonAPI.Controllers +{ + [Authorize] + [Route("api/[controller]")] + [ApiController] + public class PhotosController : ControllerBase + { + private readonly DataContext _context; + private readonly IUserRepository _userRepository; + private readonly IMapper _mapper; + private readonly IOptions _claudinarySettings; + private readonly Cloudinary _cloudinary; + + public PhotosController(DataContext context, IUserRepository userRepository, IMapper mapper, IOptions claudinarySettings) + { + _context = context; + _userRepository = userRepository; + _mapper = mapper; + _claudinarySettings = claudinarySettings; + + Account account = new Account( + _claudinarySettings.Value.CloudName, + _claudinarySettings.Value.ApiKey, + _claudinarySettings.Value.ApiSecret + ); + + _cloudinary = new Cloudinary(account); + } + + // GET: api/Photos + [HttpGet] + public async Task>> GetPhotos() + { + return await _context.Photos.ToListAsync(); + } + + // GET: api/Photos/5 + [HttpGet("{id}")] + public async Task> GetPhoto(int id) + { + var photo = await _context.Photos.FindAsync(id); + + if (photo == null) + { + return NotFound(); + } + + return photo; + } + + // PUT: api/Photos/5 + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see https://aka.ms/RazorPagesCRUD. + [HttpPut("{id}")] + public async Task PutPhoto(int id, Photo photo) + { + if (id != photo.Id) + { + return BadRequest(); + } + + _context.Entry(photo).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!PhotoExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/Photos + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see https://aka.ms/RazorPagesCRUD. + [HttpPost] + public async Task> PostPhoto(Photo photo) + { + _context.Photos.Add(photo); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetPhoto", new { id = photo.Id }, photo); + } + + // DELETE: api/Photos/5 + [HttpDelete("{id}")] + public async Task> DeletePhoto(int id) + { + var photo = await _context.Photos.FindAsync(id); + if (photo == null) + { + return NotFound(); + } + + _context.Photos.Remove(photo); + await _context.SaveChangesAsync(); + + return photo; + } + + private bool PhotoExists(int id) + { + return _context.Photos.Any(e => e.Id == id); + } + } +} diff --git a/SubitonAPI/SubitonAPI/Startup.cs b/SubitonAPI/SubitonAPI/Startup.cs index bc6e532..c8721c4 100644 --- a/SubitonAPI/SubitonAPI/Startup.cs +++ b/SubitonAPI/SubitonAPI/Startup.cs @@ -39,6 +39,8 @@ public void ConfigureServices(IServiceCollection services) services.AddDbContext(x => x.UseSqlite("Data Source =Subiton.db")); services.AddControllers(); services.AddCors(); + //claudinary config + services.Configure(Configuration.GetSection("ClaudinarySettings")); //automapper init services.AddAutoMapper(typeof(Startup)); // Auto Mapper Configurations diff --git a/SubitonAPI/SubitonAPI/Subiton.db b/SubitonAPI/SubitonAPI/Subiton.db index 5ec2431a1d5e86654f5fd0ecf9f00bf3a9a85410..068fdb62c4b122679d4967729b940c2f36d88586 100644 GIT binary patch delta 39 ocmZo@U~gz(-@q%+Zf0m{YGPovSwvn&0LE!H*WYfg&v + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + all runtime; build; native; contentfiles; analyzers; buildtransitive